Chuan Hu commited on
Commit
9192b22
1 Parent(s): 41d7759

Update ChuanhuChatbot.py

Browse files
Files changed (3) hide show
  1. ChuanhuChatbot.py +4 -4
  2. README.md +8 -5
  3. requirements.txt +0 -2
ChuanhuChatbot.py CHANGED
@@ -1,11 +1,13 @@
1
  import json
2
  import gradio as gr
 
3
  import os
4
  import sys
5
  import traceback
6
  import requests
 
7
 
8
- my_api_key = "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" # 在这里输入你的 API 密钥
9
  initial_prompt = "You are a helpful assistant."
10
 
11
  API_URL = "https://api.openai.com/v1/chat/completions"
@@ -120,7 +122,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[],
120
  if token_counter == 0:
121
  history.append(" " + partial_words)
122
  else:
123
- history[-1] = partial_words
124
  chatbot[-1] = (history[-2], history[-1])
125
  # chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
126
  token_counter += 1
@@ -240,8 +242,6 @@ with gr.Blocks() as demo:
240
  saveFileName, systemPromptTxt, history, chatbot], None, show_progress=True)
241
  saveBtn.click(get_history_names, None, [uploadDropdown])
242
  refreshBtn.click(get_history_names, None, [uploadDropdown])
243
- # uploadBtn.upload(load_chat_history, uploadBtn, [
244
- # saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
245
  uploadBtn.click(load_chat_history, [uploadDropdown], [saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
246
 
247
 
 
1
  import json
2
  import gradio as gr
3
+ # import openai
4
  import os
5
  import sys
6
  import traceback
7
  import requests
8
+ # import markdown
9
 
10
+ my_api_key = "" # 在这里输入你的 API 密钥
11
  initial_prompt = "You are a helpful assistant."
12
 
13
  API_URL = "https://api.openai.com/v1/chat/completions"
 
122
  if token_counter == 0:
123
  history.append(" " + partial_words)
124
  else:
125
+ history[-1] = parse_text(partial_words)
126
  chatbot[-1] = (history[-2], history[-1])
127
  # chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
128
  token_counter += 1
 
242
  saveFileName, systemPromptTxt, history, chatbot], None, show_progress=True)
243
  saveBtn.click(get_history_names, None, [uploadDropdown])
244
  refreshBtn.click(get_history_names, None, [uploadDropdown])
 
 
245
  uploadBtn.click(load_chat_history, [uploadDropdown], [saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
246
 
247
 
README.md CHANGED
@@ -14,11 +14,14 @@
14
 
15
 
16
  ## 功能
17
- - 重试对话,让ChatGPT再回答一次。
18
- - 优化Tokens,减少Tokens占用,以支持更长的对话。
19
- - 设置System Prompt,有效地设定前置条件
20
- - 保存/加载对话历史记录
21
- - 在图形界面中添加API key
 
 
 
22
 
23
  ## 使用技巧
24
 
 
14
 
15
 
16
  ## 功能
17
+ - [x] 像官方客户端那样支持实时显示回答!
18
+ - [x] 重试对话,让ChatGPT再回答一次。
19
+ - [x] 优化Tokens,减少Tokens占用,以支持更长的对话。
20
+ - [x] 设置System Prompt,有效地设定前置条件
21
+ - [x] 保存/加载对话历史记录
22
+ - [x] 在图形界面中添加API key
23
+ - [ ] System Prompt模板功能,从预置的Prompt库中选择
24
+ - [ ] 实时显示Tokens用量
25
 
26
  ## 使用技巧
27
 
requirements.txt CHANGED
@@ -1,3 +1 @@
1
- openai>=0.27.0
2
  gradio
3
- markdown
 
 
1
  gradio