yimo-peng commited on
Commit
9efcd61
·
verified ·
1 Parent(s): 4726aa5

fixRAG with deepseek

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -1,23 +1,32 @@
1
  import gradio as gr
2
- import random
3
- import os
4
  from huggingface_hub import InferenceClient
5
 
6
-
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
  def respond(message, history):
10
- messages = [{"role": "system","content": "You are a freindly chatbot!"}]
11
- if history:
12
- message.extend(history) # will keep conversation going
13
- message.append({"role": "user", "content": message})
 
 
 
 
 
 
 
14
  response = client.chat_completion(
15
- messages
16
- max_tokens=100 #limit characters in response to 100
17
  )
 
 
18
 
19
- return response["choices"][0]["message"]["content"].strip()
20
-
21
- chatbot = gr.ChatInterface(respond, type = "messages")
 
 
22
 
 
23
  chatbot.launch()
 
1
  import gradio as gr
 
 
2
  from huggingface_hub import InferenceClient
3
 
 
4
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
6
  def respond(message, history):
7
+ messages = [{"role": "system", "content": "You are a friendly chatbot!"}]
8
+
9
+ # 添加历史消息
10
+ for user_msg, bot_msg in history:
11
+ messages.append({"role": "user", "content": user_msg})
12
+ messages.append({"role": "assistant", "content": bot_msg})
13
+
14
+ # 添加当前消息
15
+ messages.append({"role": "user", "content": message})
16
+
17
+ # 调用API
18
  response = client.chat_completion(
19
+ messages,
20
+ max_tokens=100 # 限制响应为100个token
21
  )
22
+
23
+ return response.choices[0].message.content.strip()
24
 
25
+ chatbot = gr.ChatInterface(
26
+ respond,
27
+ title="Zephyr-7b Chatbot",
28
+ description="A chatbot powered by Zephyr-7b-beta"
29
+ )
30
 
31
+ if __name__ == "__main__":
32
  chatbot.launch()