@@ -73,31 +73,26 @@ def substruction_function(left, right):
73
73
74
74
75
75
def call_gpt (user_input ):
76
- """
77
- Make a ChatCompletion API call to OpenAI GPT-3.5-turbo-0613 model.
78
-
79
- Args:
80
- user_input (str): The user's prompt or input text.
81
-
82
- Returns:
83
- str: The generated response from the API call.
84
- """
85
- # messages = [{"role": "user", "content": user_input}]
86
-
76
+ # 将用户输入添加到会话状态中的消息列表中
87
77
st .session_state ['messages' ].append (
88
78
{"role" : "user" , "content" : user_input })
89
79
80
+ # 使用OpenAI的GPT-3.5模型进行聊天补全
90
81
completion = openai .ChatCompletion .create (
91
- model = "gpt-3.5-turbo-0613" , # gpt-4-0613
82
+ model = "gpt-3.5-turbo-0613" ,
83
+ # 将会话状态中的消息列表传递给聊天补全模型
92
84
messages = st .session_state ['messages' ],
93
85
# messages=messages,
94
- functions = f .function_list , # Receive a list of functions
95
- # Indicates whether the OpenAI model should use the functions in the function list, set to auto, which means that the AI model should guess by itself.
86
+ # 定义可调用的函数列表
87
+ functions = f .function_list ,
88
+ # 设置函数调用方式为自动调用
96
89
function_call = "auto" ,
97
90
)
98
91
92
+ # 打印补全结果
99
93
print (completion )
100
94
95
+ # 返回补全结果中的第一个选项的消息
101
96
return completion .choices [0 ].message
102
97
103
98
0 commit comments