consy commited on
Commit
021e6cc
·
verified ·
1 Parent(s): 9f5f8f8

Connected Chatbot to LLM

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -2,8 +2,27 @@ import gradio as gr
2
  import random
3
  #import lines go at the top!
4
 
5
- def yes_or_no(message,history):
6
- return random.choice(['Yes','No'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  #def echo(message, history):
9
  #always need two inputs
@@ -11,7 +30,7 @@ def yes_or_no(message,history):
11
 
12
  print("Hello, World")
13
 
14
- chatbot = gr.ChatInterface(yes_or_no, type='messages')
15
  #defining my chatbot so user can interact, see their conversation and send new messages
16
 
17
  chatbot.launch()
 
2
  import random
3
  #import lines go at the top!
4
 
5
+ from huggingface_hub import InferenceClient
6
+
7
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
+ # name of llm chatbot accessed ^^
9
+
10
+ def respond(message,history):
11
+
12
+ messages = [{'role': 'system','content':'You are a friendly chatbot.'}]
13
+ #creating dictionary containing key value pairs; first key value pair is system message, second is user message
14
+
15
+ if history:
16
+ messages.extend(history)
17
+
18
+ messages.append({'role': 'user','content': message})
19
+
20
+ response = client.chat_completion(messages, max_tokens = 100)
21
+
22
+ return response['choices'][0]['message']['content'].strip()
23
+
24
+ #def yes_or_no(message,history):
25
+ #return random.choice(['Yes','No'])
26
 
27
  #def echo(message, history):
28
  #always need two inputs
 
30
 
31
  print("Hello, World")
32
 
33
+ chatbot = gr.ChatInterface(respond, type='messages')
34
  #defining my chatbot so user can interact, see their conversation and send new messages
35
 
36
  chatbot.launch()