Funpee commited on
Commit
00a3ced
·
1 Parent(s): 5289a03

修改标题,删除敏感信息

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. local_demo.py +0 -73
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: 米你AI 提示词助手
3
  emoji: 🤖
4
  colorFrom: blue
5
  colorTo: pink
 
1
  ---
2
+ title: 米你AI 助手
3
  emoji: 🤖
4
  colorFrom: blue
5
  colorTo: pink
local_demo.py DELETED
@@ -1,73 +0,0 @@
1
- import gradio as gr
2
- import requests
3
- import json
4
- import sseclient
5
- import sys
6
-
7
- COZE_API_URL = "https://api.coze.cn/v3/chat"
8
- API_KEY = "pat_egQpN6qGjxzhy9RFwMsNOgQKJ2bNiQrdFJZBmVch5rhFkYUDPkIGBMxGXUIhlxgB" # 请替换为您的实际API密钥
9
- BOT_ID = "7430829668795760640" # 请替换为您的实际Bot ID
10
-
11
- def chat_stream(message, history):
12
- headers = {
13
- "Authorization": f"Bearer {API_KEY}",
14
- "Content-Type": "application/json"
15
- }
16
-
17
- # 构建包含历史记录的消息列表
18
- messages = []
19
- for human, assistant in history:
20
- messages.append({"role": "user", "content": human, "content_type": "text"})
21
- messages.append({"role": "assistant", "content": assistant, "content_type": "text"})
22
- messages.append({"role": "user", "content": message, "content_type": "text"})
23
-
24
- data = {
25
- "bot_id": BOT_ID,
26
- "user_id": "123123***", # 可以根据需要修改用户ID
27
- "stream": True,
28
- "auto_save_history": True,
29
- "additional_messages": messages
30
- }
31
-
32
- print(f"发送到API的数据: {json.dumps(data, ensure_ascii=False)}", file=sys.stderr)
33
-
34
- response = requests.post(COZE_API_URL, headers=headers, data=json.dumps(data), stream=True)
35
- client = sseclient.SSEClient(response)
36
-
37
- full_response = ""
38
- for event in client.events():
39
- if event.data == "[DONE]":
40
- break
41
- try:
42
- chunk = json.loads(event.data)
43
- if isinstance(chunk, dict) and "content" in chunk and chunk.get("type") == "answer":
44
- full_response = chunk["content"]
45
- except json.JSONDecodeError:
46
- pass
47
-
48
- print(f"完整的响应: {full_response}", file=sys.stderr)
49
- return full_response
50
-
51
- iface = gr.ChatInterface(
52
- chat_stream,
53
- chatbot=gr.Chatbot(height=400, label="提示词助手"),
54
- textbox=gr.Textbox(placeholder="在这里输入您的消息...", container=False, scale=7),
55
- title="米你AI 提示词助手",
56
- description="帮助你生成提示词,输入一个主题,我会帮你联想合适的提示词",
57
- theme="soft",
58
- examples=[
59
- "一个站在树上的小猴子",
60
- "今天天气怎么样?",
61
- "给我讲个笑话"
62
- ],
63
- cache_examples=False,
64
- retry_btn="重试",
65
- undo_btn="撤销",
66
- clear_btn="清除",
67
- submit_btn="发送",
68
- stop_btn="停止",
69
- autofocus=True
70
- )
71
-
72
- if __name__ == "__main__":
73
- iface.launch()