-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathtest_allowed_tools.py
More file actions
83 lines (76 loc) · 2.27 KB
/
test_allowed_tools.py
File metadata and controls
83 lines (76 loc) · 2.27 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from openai import OpenAI
client = OpenAI()
tools = [
{
"type": "function",
"function":{
"name": "get_horoscope",
"description": "Get today's horoscope for an astrological sign.",
"parameters": {
"type": "object",
"properties": {
"sign": {
"type": "string",
"description": "An astrological sign like Taurus or Aquarius",
},
},
"required": ["sign"],
},
}
},
{
"type": "function",
"function": {
"name": "say",
"description": "say something to the user when no other tools are available",
"parameters": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "say something to the user",
}
},
"required": ["text"],
},
}
},
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country name e.g. Bogotá, Colombia",
}
},
"required": ["location"],
},
}
},
]
tool_choice = {
"type": "allowed_tools",
"mode": "auto",
"allowed_tools": {
"mode": "auto",
"tools": [
{"type": "function", "function": {"name": 'get_weather'}},
{"type": "function", "function": {"name": 'say'}},
]
}
}
messages = [ {"role": "user", "content": "What is my horoscope? I am an Aquarius."} ]
response = client.chat.completions.create(
messages = messages,
model = "gpt-4o-2024-11-20",
stream = False,
tools = tools,
tool_choice = tool_choice
)
print("Response:", response.choices[0].message.content)
print("Hit Tools:", [ i.function for i in response.choices[0].message.tool_calls] )