forked from yeyu2/Youtube_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_function.py
67 lines (61 loc) · 1.9 KB
/
parallel_function.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
59
60
61
62
63
64
65
66
67
import openai
import json
def get_stock_price(symbol):
if symbol == "TSLA":
return "$222.18"
else:
return "Unknown"
def tweet_send(symbol):
data = get_stock_price(symbol)
answer = f"New Tweet Msg: Tesla's Q2 revenue in 2023 was {data}. #Tesla #2023"
return answer
def facebook_send(symbol):
data = get_stock_price(symbol)
answer = f"New Facebook Msg: Tesla's Q2 revenue in 2023 was {data}. #Tesla #2023"
return answer
messages = [{"role": "user", "content": "Send a tweet message and facebook message about Tesla's current stock price."}]
tools = [
{
"type": "function",
"function": {
"name": "facebook_send",
"description": "generate a tweet message based on input stock symbol and send it to facebook",
"parameters": {
"type": "object",
"properties": {
"symbol": {
"type": "string",
"description": "The Stock Symbol, like AAPL",
},
},
"required": ["symbol"],
},
},
},
{
"type": "function",
"function": {
"name": "tweet_send",
"description": "generate a tweet message based on input stock symbol and send it to twitter",
"parameters": {
"type": "object",
"properties": {
"symbol": {
"type": "string",
"description": "The Stock Symbol, like AAPL",
},
},
"required": ["symbol"],
},
},
}
]
response = openai.chat.completions.create(
model="gpt-4-0613",
messages=messages,
tools=tools,
tool_choice="auto",
)
response_message = response.choices[0].message
tool_calls = response_message.tool_calls
print(tool_calls)