diff options
| author | haoyuren <13851610112@163.com> | 2024-12-06 22:58:19 -0600 |
|---|---|---|
| committer | haoyuren <13851610112@163.com> | 2024-12-06 22:58:19 -0600 |
| commit | c284a6b1679cb2e3f115850143bcd985fe23dfb2 (patch) | |
| tree | 1e4a558a56591c57c930ed16a0445911267c7ea7 /caller.py | |
Initial commit: Meeting details extractor
Diffstat (limited to 'caller.py')
| -rw-r--r-- | caller.py | 44 |
1 files changed, 44 insertions, 0 deletions
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 |
