hushell commited on
Commit
d131f3e
·
1 Parent(s): b8c2939

Add model options

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -96,6 +96,7 @@ def write_data(new_chat_name=current_chat):
96
  # 防止高频创建时组件尚未渲染完成,不影响正常写入
97
  if "frequency_penalty" + current_chat in st.session_state:
98
  st.session_state["paras"] = {
 
99
  "temperature": st.session_state["temperature" + current_chat],
100
  "top_p": st.session_state["top_p" + current_chat],
101
  "presence_penalty": st.session_state["presence_penalty" + current_chat],
@@ -152,6 +153,9 @@ with tap_set:
152
  key='context_level' + current_chat, help="表示每次会话中包含的历史对话次数,预设内容不计算在内。")
153
 
154
  st.markdown("模型参数:")
 
 
 
155
  st.slider("Temperature", 0.0, 2.0, st.session_state["temperature" + current_chat + "default"], 0.1,
156
  help="""在0和2之间,应该使用什么样的采样温度?较高的值(如0.8)会使输出更随机,而较低的值(如0.2)则会使其更加集中和确定性。
157
  我们一般建议只更改这个参数或top_p参数中的一个,而不要同时更改两个。""",
@@ -211,6 +215,7 @@ with tap_input:
211
  "content": st.session_state['context_input' + current_chat]}]
212
  + history_tem)
213
  paras_need_input = {
 
214
  "temperature": st.session_state["temperature" + current_chat],
215
  "top_p": st.session_state["top_p" + current_chat],
216
  "presence_penalty": st.session_state["presence_penalty" + current_chat],
@@ -222,7 +227,7 @@ with tap_input:
222
  openai.api_key = apikey
223
  else:
224
  openai.api_key = st.secrets["apikey"]
225
- r = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=history_need_input, stream=True,
226
  **paras_need_input)
227
  except (FileNotFoundError, KeyError):
228
  area_error.error("缺失 OpenAI API Key,请在复制项目后配置Secrets,或者在设置中进行临时配置。"
 
96
  # 防止高频创建时组件尚未渲染完成,不影响正常写入
97
  if "frequency_penalty" + current_chat in st.session_state:
98
  st.session_state["paras"] = {
99
+ "model": st.session_state["model" + current_chat],
100
  "temperature": st.session_state["temperature" + current_chat],
101
  "top_p": st.session_state["top_p" + current_chat],
102
  "presence_penalty": st.session_state["presence_penalty" + current_chat],
 
153
  key='context_level' + current_chat, help="表示每次会话中包含的历史对话次数,预设内容不计算在内。")
154
 
155
  st.markdown("模型参数:")
156
+ st.selectbox("Model", ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4", "gpt-4-32k"], index=0,
157
+ help="[模型选择参考](https://platform.openai.com/docs/models)",
158
+ on_change=write_data, key='model' + current_chat)
159
  st.slider("Temperature", 0.0, 2.0, st.session_state["temperature" + current_chat + "default"], 0.1,
160
  help="""在0和2之间,应该使用什么样的采样温度?较高的值(如0.8)会使输出更随机,而较低的值(如0.2)则会使其更加集中和确定性。
161
  我们一般建议只更改这个参数或top_p参数中的一个,而不要同时更改两个。""",
 
215
  "content": st.session_state['context_input' + current_chat]}]
216
  + history_tem)
217
  paras_need_input = {
218
+ "model": st.session_state["model" + current_chat],
219
  "temperature": st.session_state["temperature" + current_chat],
220
  "top_p": st.session_state["top_p" + current_chat],
221
  "presence_penalty": st.session_state["presence_penalty" + current_chat],
 
227
  openai.api_key = apikey
228
  else:
229
  openai.api_key = st.secrets["apikey"]
230
+ r = openai.ChatCompletion.create(messages=history_need_input, stream=True,
231
  **paras_need_input)
232
  except (FileNotFoundError, KeyError):
233
  area_error.error("缺失 OpenAI API Key,请在复制项目后配置Secrets,或者在设置中进行临时配置。"