yimo-peng commited on
Commit
86c6031
·
verified ·
1 Parent(s): c4800ec

create a new chatbot RAG

Browse files
Files changed (1) hide show
  1. app.py +31 -12
app.py CHANGED
@@ -1,16 +1,35 @@
1
  import gradio as gr
2
  import random
 
3
 
4
- def simple(message, history):
5
- responses = ["Hello", "How are you?", "What's your name?"]
6
- return random.choice(responses)
7
-
8
- chatbot = gr.ChatInterface(
9
- fn=simple, # 添加了fn参数指向你的聊天函数
10
- title="Simple Pattern Bot",
11
- description="I respond to basic patterns (try saying hi or asking a question)",
12
- examples=["Hello", "How are you?", "What's your name?"],
13
- )
14
-
15
- if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  chatbot.launch()
 
1
  import gradio as gr
2
  import random
3
+ import os
4
 
5
+ #os.environ["HF_TOKEN"] = "#insert token here"
6
+
7
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
+
9
+ def repond(message, history):
10
+ messages = [{"role": "system","content": "You are a freindly chatbot!"}]
11
+ #responses = ["Hello", "How are you?", "What's your name?"]
12
+ if history:
13
+ message.extend(history)
14
+
15
+ messages.append({"role": "user", "content": message})
16
+
17
+ #return random.choice(responses)
18
+ response = client.chat_completion(
19
+ messages
20
+ max_tokens=100
21
+ )
22
+
23
+ return response['choices'][0]['message']['content'].strip()
24
+
25
+ chatbot = gr.ChatInterface(respond, type="messages")
26
+
27
+ #chatbot = gr.ChatInterface(
28
+ # fn=simple,
29
+ # title="Simple Pattern Bot",
30
+ # description="I respond to basic patterns (try saying hi or asking a question)",
31
+ # examples=["Hello", "How are you?", "What's your name?"],
32
+ #)
33
+
34
+ #if __name__ == "__main__":
35
  chatbot.launch()