-
Notifications
You must be signed in to change notification settings - Fork 1
/
function_call.py
58 lines (43 loc) · 1.13 KB
/
function_call.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Simple function to extract specific information in your input
import os
from openai import OpenAI
import json
client = OpenAI()
content = "I want some projects for my 3d graphics python software"
messages = [
{
"role": "system",
"content": "Repository of the best opensource software and projects"
},
{
"role": "user",
"content": content,
}
]
tools=[
{
"type": "function",
"function": {
"name": "get_top_opensource_projects",
"description": "Get a list of top 5 open-source projects in a specified topic",
"parameters": {
"type": "object",
"properties": {
"topics": {
"type": "string",
"description": "List of the top 5 projects "
}
},
"required": ["topics"]
},
}
}
]
completion = client.chat.completions.create(
messages=messages,
model="gpt-4",
tools= tools,
tool_choice="auto",
)
reply_content = completion.choices[0].message
print(reply_content)