commonlemon commited on
Commit
45c6520
·
verified ·
1 Parent(s): 86c4fa1

comments adjusted for teaching

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -3,7 +3,7 @@ from huggingface_hub import InferenceClient #InferenceClient class
3
 
4
  client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B") #Create an instance of InferenceClient connected to the Qwen/Qwen2.5-7B-Instruct text-generation model
5
  #this client will handle making requests to the model to generate responses
6
-
7
 
8
  def respond(message, history): #function for Gradio to call
9
  #Gradio passes arguments as parameters: the user's most recent input which is a string ("message"), and "history" which is the list of past messages
@@ -12,25 +12,28 @@ def respond(message, history): #function for Gradio to call
12
  messages = [
13
  {"role": "system",
14
  "content": "You are a friendly chatbot."}
15
- ] #dict in list to store messages
16
 
17
  #Add convo history to the messages if there's convo history
 
18
  if history:
19
  messages.extend(history) # adds history to the end of messages list via .extend() method
20
 
 
21
  messages.append({"role": "user", "content": message}) #add the current user’s message to the messages list
22
 
23
- # chat completion API call forwarding the messages & other params to model
 
24
  response = client.chat_completion(messages, max_tokens=100, temperature = 2, top_p=0.95) #deepseek R1 recomended temp range: 0.5-0.7
25
- return response.choices[0].message.content.strip()
26
  # max_tokens, to limit the number of tokens that can be generated
27
  # temperature, which controls randomness (higher = more random)
28
  # top_p, an alternative to sampling with temperature
29
-
30
 
31
  # defining chatbot
32
  chatbot = gr.ChatInterface(respond, title = "", description = "") #using gradio to quickly build a chatbot UI (w/ convo history & user input)
33
  # passing fxn into a fxn, passing echo for gradio to call each time the user sends a message
34
  # Adding parentheses would call the function and pass its return value instead, I didn't include () because I want Gradio to call it later, not right now
35
 
36
- chatbot.launch() #launch chatbot
 
 
3
 
4
  client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B") #Create an instance of InferenceClient connected to the Qwen/Qwen2.5-7B-Instruct text-generation model
5
  #this client will handle making requests to the model to generate responses
6
+ #allows us to access the LLM we chose (og: "Qwen/Qwen2.5-7B-Instruct")
7
 
8
  def respond(message, history): #function for Gradio to call
9
  #Gradio passes arguments as parameters: the user's most recent input which is a string ("message"), and "history" which is the list of past messages
 
12
  messages = [
13
  {"role": "system",
14
  "content": "You are a friendly chatbot."}
15
+ ] #dictionary in list to store messages
16
 
17
  #Add convo history to the messages if there's convo history
18
+ #adds everytime there's a new message
19
  if history:
20
  messages.extend(history) # adds history to the end of messages list via .extend() method
21
 
22
+ #user's side:
23
  messages.append({"role": "user", "content": message}) #add the current user’s message to the messages list
24
 
25
+ # chat completion API call forwarding the messages (& other params) to model
26
+ # connect the client to chatbot
27
  response = client.chat_completion(messages, max_tokens=100, temperature = 2, top_p=0.95) #deepseek R1 recomended temp range: 0.5-0.7
 
28
  # max_tokens, to limit the number of tokens that can be generated
29
  # temperature, which controls randomness (higher = more random)
30
  # top_p, an alternative to sampling with temperature
31
+ return response.choices[0].message.content.strip()
32
 
33
  # defining chatbot
34
  chatbot = gr.ChatInterface(respond, title = "", description = "") #using gradio to quickly build a chatbot UI (w/ convo history & user input)
35
  # passing fxn into a fxn, passing echo for gradio to call each time the user sends a message
36
  # Adding parentheses would call the function and pass its return value instead, I didn't include () because I want Gradio to call it later, not right now
37
 
38
+ chatbot.launch(debug=True) #launch chatbot
39
+ #(? not 100% sure how)--debug=True will give us detailed messages if something is wrong so we can debug