13ilguun commited on
Commit
bcfd1f0
·
1 Parent(s): 6ec6301
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -33,24 +33,41 @@ def respond(
33
  response += token_piece
34
  yield response
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  demo = gr.ChatInterface(
37
  respond,
38
  additional_inputs=[
39
- gr.Textbox(
40
- value=(
41
- "I am Bilguun, a third year software engineering student at McGill University and the founder of VentureCircle. "
42
- "VentureCircle is based in Montreal. "
43
- "I created this chatbot, LaunchPad, to help aspiring entrepreneurs achieve their goals. "
44
- "Your name is LaunchPad. "
45
- "LaunchPad is a friendly AI assistant designed to provide useful and supportive guidance for starting and growing a startup."
46
- ),
47
- label="System message"
48
- ),
49
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
52
  ],
53
  )
54
 
55
- if __name__ == "__main__":
56
- demo.launch(share=True, show_error=True)
 
33
  response += token_piece
34
  yield response
35
 
36
+ # Make a version of `respond` that's API-callable
37
+ def chat_api(message, max_tokens, temperature, top_p):
38
+ # Create a minimal prompt with default system message and no chat history
39
+ messages = [{"role": "system", "content": DEFAULT_SYSTEM_MESSAGE}]
40
+ messages.append({"role": "user", "content": message})
41
+
42
+ output = ""
43
+ for chunk in client.chat_completion(
44
+ messages,
45
+ max_tokens=max_tokens,
46
+ stream=True,
47
+ temperature=temperature,
48
+ top_p=top_p,
49
+ ):
50
+ output += chunk.choices[0].delta.content
51
+ return output
52
+
53
+ DEFAULT_SYSTEM_MESSAGE = (
54
+ "I am Bilguun, a third year software engineering student at McGill University and the founder of VentureCircle. "
55
+ "VentureCircle is based in Montreal. "
56
+ "I created this chatbot, LaunchPad, to help aspiring entrepreneurs achieve their goals. "
57
+ "Your name is LaunchPad. "
58
+ "LaunchPad is a friendly AI assistant designed to provide useful and supportive guidance for starting and growing a startup."
59
+ )
60
+
61
+ # Main demo UI
62
  demo = gr.ChatInterface(
63
  respond,
64
  additional_inputs=[
65
+ gr.Textbox(value=DEFAULT_SYSTEM_MESSAGE, label="System message"),
 
 
 
 
 
 
 
 
 
66
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
67
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
68
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
69
  ],
70
  )
71
 
72
+ # Launch with /chat endpoint
73
+ demo.launch(share=True, show_error=True).api(fn=chat_api, inputs=["text", "slider", "slider", "slider"], api_name="/chat")