Last active
April 20, 2024 13:26
-
-
Save KolegaLiterat/28a8ae9b80303bd5b8f24b87f8d3806b to your computer and use it in GitHub Desktop.
Code examples for meeting summaries and transcription. A part of article on my blog -> kolegaliterat.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ["OPENAI_API_KEY"] = OPEN_AI_API_KEY | |
from crewai import Agent, Task, Crew, Process | |
from crewai_tools import FileReadTool, TXTSearchTool, DirectoryReadTool | |
from langchain_openai import OpenAI, ChatOpenAI | |
#Tools | |
transcription_directory = DirectoryReadTool(FOLDER_PATH) | |
summaries_directory = DirectoryReadTool(FOLDER_PATH) | |
file_read_tool = FileReadTool() | |
txt_search_tool = TXTSearchTool() | |
#Agents personas | |
project_manager = Agent( | |
role = 'Gamedev Project Manager', | |
goal = 'To establish project priorities and identify potential risks within game development, devise strategies to mitigate those risks, and develop actionable work plans.', | |
backstory = """The agent functions as a project manager at an independent gaming company, aiding teams in concentrating on critical tasks. Known for a communication style that is both direct and centered on problem-solving.""", | |
LLM = OpenAI(model_name = "gpt-4-turbo"), | |
tools = [transcription_directory, file_read_tool, txt_search_tool], | |
verbose = True, | |
memory = True, | |
cache = True, | |
allow_delegation = True, | |
max_iter = 10, | |
) | |
scrum_master = Agent( | |
role = 'Scrum Master in Gamedev Team', | |
goal = 'To outline objectives for the upcoming sprint.', | |
backstory = """The agent holds the position of scrum master within an independent gaming company and is currently engaged in determining the tasks for the next sprint, utilizing insights from the project manager's strategy and planning.""", | |
LLM = OpenAI(model_name = "gpt-4-turbo"), | |
tools = [summaries_directory, file_read_tool, txt_search_tool], | |
verbose = True, | |
memory = True, | |
cache = True, | |
max_iter = 10, | |
) | |
#Tasks | |
meeting_summary = Task( | |
description = ("Concentrate on capturing the essential details discussed during the meeting"), | |
expected_output = "Produce a concise bullet-point list that encapsulates the core information for each topic addressed.", | |
agent = project_manager, | |
output_file = OUTPUT_FOLDER, | |
) | |
decision_summary = Task( | |
description = ("Summarize the decisions made in a meeting." | |
"Assign a numerical value between 0 and 5 next to each decision to indicate its level of impact, with higher numbers signifying greater impact. " | |
"Include any mentioned solutions related to these decisions." | |
), | |
expected_output = "A bullet list of decision. With impact score in ()", | |
agent = project_manager, | |
output_file = OUTPUT_FOLDER, | |
) | |
actions = Task( | |
description = ("Formatting Instructions: Utilize Markdown syntax to format the list. Begin each action item with - [ ] to denote an unchecked task." | |
"Accompany each action with a priority label, ranging from P0 to P5, where P0 indicates the highest level of urgency." | |
"Phrase each item as a task that must be completed." | |
), | |
expected_output = "Generate a list of actionable items for the forthcoming sprint.", | |
agent = scrum_master, | |
output_file = OUTPUT_FOLDER | |
) | |
#Crew gathering | |
crew = Crew( | |
agents = [project_manager, scrum_master], | |
tasks = [meeting_summary, decision_summary, actions], | |
memory=True, | |
cache=True, | |
process=Process.hierarchical, | |
max_rpm = 100, | |
manager_llm=ChatOpenAI(model="gpt-4-turbo") | |
) | |
result = crew.kickoff() | |
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openai import OpenAI | |
from langchain_openai import ChatOpenAI | |
from langchain_core.prompts import ChatPromptTemplate | |
from langchain_core.output_parsers import StrOutputParser | |
from progress.bar import ChargingBar | |
##App files | |
from src.helper import DataFiles | |
class Transcriber(): | |
def __init__(self, api_key: str, file_paths: str): | |
self.open_ai_client = OpenAI(api_key=api_key) | |
self.file_paths = file_paths | |
self.transcription_folder = DataFiles("transcription") | |
def transcribe_meeting_call(self): | |
progress = ChargingBar("Cleaning transcriptions!", max=len(self.file_paths)) | |
for part, file in enumerate(self.file_paths, start=0): | |
transcription = self.__create_transcription(file) | |
self.transcription_folder.save_data(f"part_{part}.txt", transcription) | |
progress.next() | |
progress.finish() | |
def __create_transcription(self, file_path: str): | |
with open(file_path, "rb") as audio_file: | |
transcription = self.open_ai_client.audio.transcriptions.create( | |
model="whisper-1", | |
file=audio_file, | |
response_format="text" | |
) | |
return transcription | |
class PurityClerk(): | |
def __init__(self, api_key, file_paths): | |
self.llm_cleaner = ChatOpenAI(api_key=api_key, model="gpt-4-turbo") | |
self.output_parser = StrOutputParser() | |
self.summaries_folder = DataFiles("crew/meetings") | |
self.file_paths = file_paths | |
def prepare_summary(self): | |
progress = ChargingBar("Cleaning transcriptions!", max=len(self.file_paths)) | |
for path in self.file_paths: | |
with open(path, 'r') as file: | |
data = file.read() | |
summary_filename = path[-10:] | |
summary = self.__clean_up_transcription(data) | |
self.summaries_folder.save_data(summary_filename, summary) | |
progress.next() | |
progress.finish() | |
def __clean_up_transcription(self, content): | |
###Langchain can be easilly removed and replaced by a request to the OpenAI API. | |
prompt = ChatPromptTemplate.from_messages([ | |
("system", "##ROLE \ | |
You're well known person who specilizes in creating great summaries based on meeting transcprition. \ | |
You're always focused on looking for crucial information from meeting. \ | |
###TASK \ | |
Clean up transcription of a meeting. Focus on important information, remove repetitions and small-talk. \ | |
Summary needs to have max 300 words and be in english"), | |
("user", "{transcription}") | |
]) | |
chain = prompt | self.llm_cleaner | self.output_parser | |
summary = chain.invoke({"transcription": content}) | |
return summary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment