Skip to content

Commit

Permalink
Update ChuanhuChatbot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GaiZhenbiao committed Mar 6, 2023
1 parent 41d7759 commit 9192b22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ChuanhuChatbot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import json
import gradio as gr
# import openai
import os
import sys
import traceback
import requests
# import markdown

my_api_key = "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" # 在这里输入你的 API 密钥
my_api_key = "" # 在这里输入你的 API 密钥
initial_prompt = "You are a helpful assistant."

API_URL = "https://api.openai.com/v1/chat/completions"
Expand Down Expand Up @@ -120,7 +122,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[],
if token_counter == 0:
history.append(" " + partial_words)
else:
history[-1] = partial_words
history[-1] = parse_text(partial_words)
chatbot[-1] = (history[-2], history[-1])
# chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
token_counter += 1
Expand Down Expand Up @@ -240,8 +242,6 @@ def reset_textbox():
saveFileName, systemPromptTxt, history, chatbot], None, show_progress=True)
saveBtn.click(get_history_names, None, [uploadDropdown])
refreshBtn.click(get_history_names, None, [uploadDropdown])
# uploadBtn.upload(load_chat_history, uploadBtn, [
# saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
uploadBtn.click(load_chat_history, [uploadDropdown], [saveFileName, systemPromptTxt, history, chatbot], show_progress=True)


Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@


## 功能
- 重试对话,让ChatGPT再回答一次。
- 优化Tokens,减少Tokens占用,以支持更长的对话。
- 设置System Prompt,有效地设定前置条件
- 保存/加载对话历史记录
- 在图形界面中添加API key
- [x] 像官方客户端那样支持实时显示回答!
- [x] 重试对话,让ChatGPT再回答一次。
- [x] 优化Tokens,减少Tokens占用,以支持更长的对话。
- [x] 设置System Prompt,有效地设定前置条件
- [x] 保存/加载对话历史记录
- [x] 在图形界面中添加API key
- [ ] System Prompt模板功能,从预置的Prompt库中选择
- [ ] 实时显示Tokens用量

## 使用技巧

Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
openai>=0.27.0
gradio
markdown

0 comments on commit 9192b22

Please sign in to comment.