summaryrefslogtreecommitdiff
path: root/caller.py
blob: 7b8c68faf04a31690d0db4fa42cd592b888c69ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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}