From c284a6b1679cb2e3f115850143bcd985fe23dfb2 Mon Sep 17 00:00:00 2001 From: haoyuren <13851610112@163.com> Date: Fri, 6 Dec 2024 22:58:19 -0600 Subject: Initial commit: Meeting details extractor --- caller.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 caller.py (limited to 'caller.py') diff --git a/caller.py b/caller.py new file mode 100644 index 0000000..7b8c68f --- /dev/null +++ b/caller.py @@ -0,0 +1,44 @@ +import openai +import re +import yaml + +# Load API key from yaml file +with open('api-key.yaml', 'r') as file: + config = yaml.safe_load(file) + api_key = config['openai']['api_key'] + +# Initialize the OpenAI client +client = openai.OpenAI(api_key=api_key) + +def extract_meeting_details(long_text): + response = client.chat.completions.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "system", "content": "You are an assistant that extracts meeting details from text. You must respond in a specific format that can be parsed as YAML."}, + {"role": "user", "content": f"""Please extract all mentioned meetings from the following text and format the response as YAML: + +{long_text} + +Format the response as: +meetings: + - time: "YYYY-MM-DD HH:MM - HH:MM" + location: "location name" + description: "event description" + title: "meeting title" + - time: "YYYY-MM-DD HH:MM - HH:MM" + location: "location name" + description: "event description" + title: "meeting title" + +If no meetings are found, respond with: +meetings: null"""} + ], + max_tokens=1500, + temperature=0.2 + ) + + try: + result = yaml.safe_load(response.choices[0].message.content) + return result + except yaml.YAMLError: + return {"meetings": None} \ No newline at end of file -- cgit v1.2.3