drixo commited on
Commit
90a6520
·
verified ·
1 Parent(s): 30bcb65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -17,16 +17,30 @@ def respond(
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  for val in history:
21
  if val[0]:
22
  messages.append({"role": "user", "content": val[0]})
23
  if val[1]:
24
  messages.append({"role": "assistant", "content": val[1]})
25
 
 
26
  messages.append({"role": "user", "content": message})
27
 
 
28
  response = ""
29
-
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,27 +49,17 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
- gr.Textbox(value="RC ChatBot.", label="System message"),
50
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
  ],
60
  )
61
 
 
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
+ # Add a few-shot context to guide the chatbot
21
+ rc_qa_examples = [
22
+ ("What is Resilient Coders?", "Resilient Coders is a nonprofit that trains young people of color for careers in tech."),
23
+ ("Is the bootcamp free?", "Yes, the bootcamp is completely free and includes a stipend."),
24
+ ("How long is the program?", "It usually runs for about 14 to 20 weeks."),
25
+ ("Do I need to know how to code?", "No prior experience is required. We train participants from the ground up."),
26
+ ("Is it remote or in-person?", "The program may be remote, in-person, or hybrid depending on the cohort."),
27
+ ]
28
+ for q, a in rc_qa_examples:
29
+ messages.append({"role": "user", "content": q})
30
+ messages.append({"role": "assistant", "content": a})
31
+
32
+ # Add conversation history
33
  for val in history:
34
  if val[0]:
35
  messages.append({"role": "user", "content": val[0]})
36
  if val[1]:
37
  messages.append({"role": "assistant", "content": val[1]})
38
 
39
+ # Append current user message
40
  messages.append({"role": "user", "content": message})
41
 
42
+ # Stream response
43
  response = ""
 
44
  for message in client.chat_completion(
45
  messages,
46
  max_tokens=max_tokens,
 
49
  top_p=top_p,
50
  ):
51
  token = message.choices[0].delta.content
 
52
  response += token
53
  yield response
54
 
55
 
 
 
 
56
  demo = gr.ChatInterface(
57
  respond,
58
  additional_inputs=[
59
+ gr.Textbox(value="You are a helpful assistant that only answers questions about the Resilient Coders bootcamp. If the question is unrelated, politely decline.", label="System message"),
60
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
61
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
62
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
63
  ],
64
  )
65