Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 340c121

Browse files
committed
feat(use-examples): optimize code
1 parent 22ac390 commit 340c121

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

‎main.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,26 @@ def substruction_function(left, right):
7373

7474

7575
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+
# 将用户输入添加到会话状态中的消息列表中
8777
st.session_state['messages'].append(
8878
{"role": "user", "content": user_input})
8979

80+
# 使用OpenAI的GPT-3.5模型进行聊天补全
9081
completion = openai.ChatCompletion.create(
91-
model="gpt-3.5-turbo-0613", # gpt-4-0613
82+
model="gpt-3.5-turbo-0613",
83+
# 将会话状态中的消息列表传递给聊天补全模型
9284
messages=st.session_state['messages'],
9385
# 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+
# 设置函数调用方式为自动调用
9689
function_call="auto",
9790
)
9891

92+
# 打印补全结果
9993
print(completion)
10094

95+
# 返回补全结果中的第一个选项的消息
10196
return completion.choices[0].message
10297

10398

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /