From 9192b2254694fd576d97c955f0761eadc005de56 Mon Sep 17 00:00:00 2001 From: Chuan Hu <51039745+GaiZhenbiao@users.noreply.github.com> Date: Mon, 6 Mar 2023 21:33:49 +0800 Subject: [PATCH] Update ChuanhuChatbot.py --- ChuanhuChatbot.py | 8 ++++---- README.md | 13 ++++++++----- requirements.txt | 2 -- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ChuanhuChatbot.py b/ChuanhuChatbot.py index 7d1397e3..2edef970 100644 --- a/ChuanhuChatbot.py +++ b/ChuanhuChatbot.py @@ -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" @@ -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 @@ -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) diff --git a/README.md b/README.md index 19fae68d..d2741c77 100644 --- a/README.md +++ b/README.md @@ -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用量 ## 使用技巧 diff --git a/requirements.txt b/requirements.txt index 0bea62e0..25acedda 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ -openai>=0.27.0 gradio -markdown