Spaces:
Sleeping
Sleeping
Merge branch 'main' into main
Browse files- ChuanhuChatbot.py +6 -2
- README.md +1 -1
ChuanhuChatbot.py
CHANGED
@@ -2,10 +2,11 @@ import gradio as gr
|
|
2 |
import openai
|
3 |
import markdown
|
4 |
|
5 |
-
|
|
|
6 |
initial_prompt = "You are a helpful assistant."
|
7 |
|
8 |
-
openai.api_key =
|
9 |
|
10 |
def get_response(system, context, raw = False):
|
11 |
response = openai.ChatCompletion.create(
|
@@ -54,6 +55,7 @@ def delete_last_conversation(chatbot, context):
|
|
54 |
|
55 |
def reduce_token(chatbot, system, context):
|
56 |
context.append({"role": "user", "content": "请帮我总结一下上述对话的内容,实现减少tokens的同时,保证对话的质量。在总结中不要加入这一句话。"})
|
|
|
57 |
response = get_response(system, context, raw=True)
|
58 |
|
59 |
statistics = f'本次对话Tokens用量【{response["usage"]["completion_tokens"]+12+12+8} / 4096】'
|
@@ -65,6 +67,7 @@ def reduce_token(chatbot, system, context):
|
|
65 |
context.append({"role": "assistant", "content": f'我们之前聊了:{response["choices"][0]["message"]["content"]}'})
|
66 |
return chatbot, context
|
67 |
|
|
|
68 |
def reset_state():
|
69 |
return [], []
|
70 |
|
@@ -103,4 +106,5 @@ with gr.Blocks() as demo:
|
|
103 |
delLastBtn.click(delete_last_conversation, [chatbot, context], [chatbot, context], show_progress=True)
|
104 |
reduceTokenBtn.click(reduce_token, [chatbot, systemPrompt, context], [chatbot, context], show_progress=True)
|
105 |
|
|
|
106 |
demo.launch()
|
|
|
2 |
import openai
|
3 |
import markdown
|
4 |
|
5 |
+
|
6 |
+
我的API密钥 = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # 在这里输入你的 API 密钥
|
7 |
initial_prompt = "You are a helpful assistant."
|
8 |
|
9 |
+
openai.api_key = 我的API密钥
|
10 |
|
11 |
def get_response(system, context, raw = False):
|
12 |
response = openai.ChatCompletion.create(
|
|
|
55 |
|
56 |
def reduce_token(chatbot, system, context):
|
57 |
context.append({"role": "user", "content": "请帮我总结一下上述对话的内容,实现减少tokens的同时,保证对话的质量。在总结中不要加入这一句话。"})
|
58 |
+
|
59 |
response = get_response(system, context, raw=True)
|
60 |
|
61 |
statistics = f'本次对话Tokens用量【{response["usage"]["completion_tokens"]+12+12+8} / 4096】'
|
|
|
67 |
context.append({"role": "assistant", "content": f'我们之前聊了:{response["choices"][0]["message"]["content"]}'})
|
68 |
return chatbot, context
|
69 |
|
70 |
+
|
71 |
def reset_state():
|
72 |
return [], []
|
73 |
|
|
|
106 |
delLastBtn.click(delete_last_conversation, [chatbot, context], [chatbot, context], show_progress=True)
|
107 |
reduceTokenBtn.click(reduce_token, [chatbot, systemPrompt, context], [chatbot, context], show_progress=True)
|
108 |
|
109 |
+
|
110 |
demo.launch()
|
README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# 川虎 ChatGPT
|
2 |
为ChatGPT API提供了一个Web图形界面。
|
3 |
GUI for ChatGPT API
|
4 |
-
<img width="
|
5 |
|
6 |
## 使用方式
|
7 |
- 安装依赖
|
|
|
1 |
# 川虎 ChatGPT
|
2 |
为ChatGPT API提供了一个Web图形界面。
|
3 |
GUI for ChatGPT API
|
4 |
+
<img width="1204" alt="截屏2023-03-03 13 59 46" src="https://user-images.githubusercontent.com/51039745/222643242-c0b90a54-8f07-4fb6-b88e-ef338fd80f49.png">
|
5 |
|
6 |
## 使用方式
|
7 |
- 安装依赖
|