Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,32 +15,16 @@ def respond(
|
|
15 |
max_tokens,
|
16 |
temperature,
|
17 |
top_p,
|
18 |
-
max_context_length=4096, # Set the maximum context length
|
19 |
):
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
tokens_so_far += len(client.tokenizer.encode(user_input))
|
28 |
-
if bot_response:
|
29 |
-
tokens_so_far += len(client.tokenizer.encode(bot_response))
|
30 |
|
31 |
-
|
32 |
-
truncated_history.insert(0, (user_input, bot_response))
|
33 |
-
else:
|
34 |
-
break
|
35 |
-
|
36 |
-
for user_input, bot_response in truncated_history:
|
37 |
-
if user_input:
|
38 |
-
messages.append({"role": "user", "content": user_input})
|
39 |
-
if bot_response:
|
40 |
-
messages.append({"role": "assistant", "content": bot_response})
|
41 |
-
|
42 |
-
if message:
|
43 |
-
messages.append({"role": "user", "content": message})
|
44 |
|
45 |
response = ""
|
46 |
|
@@ -54,10 +38,7 @@ def respond(
|
|
54 |
token = message.choices[0].delta.content
|
55 |
|
56 |
response += token
|
57 |
-
yield response
|
58 |
-
|
59 |
-
if response:
|
60 |
-
truncated_history.append((message, response))
|
61 |
|
62 |
"""
|
63 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
@@ -66,12 +47,12 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
66 |
system_message = "You are a helpful car configuration assistant, specifically you are the assistant for Apex Customs (https://www.apexcustoms.com/). Given the user's input, provide suggestions for car models, colors, and customization options. Be conversational in your responses. You should remember the user's car model and tailor your answers accordingly, referring to the specific car model mentioned by the user. You limit yourself to answering the given question and maybe propose a suggestion but not write the next question of the user."
|
67 |
|
68 |
demo = gr.ChatInterface(
|
69 |
-
respond,
|
70 |
chatbot=gr.Chatbot(value=[[None, initial_message]]),
|
71 |
additional_inputs=[
|
72 |
gr.Textbox(value=system_message, label="System message"),
|
73 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
74 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.
|
75 |
gr.Slider(
|
76 |
minimum=0.1,
|
77 |
maximum=1.0,
|
|
|
15 |
max_tokens,
|
16 |
temperature,
|
17 |
top_p,
|
|
|
18 |
):
|
19 |
messages = [{"role": "system", "content": system_message}]
|
20 |
|
21 |
+
for val in history:
|
22 |
+
if val[0]:
|
23 |
+
messages.append({"role": "user", "content": val[0]})
|
24 |
+
if val[1]:
|
25 |
+
messages.append({"role": "assistant", "content": val[1]})
|
|
|
|
|
|
|
26 |
|
27 |
+
messages.append({"role": "user", "content": message})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
response = ""
|
30 |
|
|
|
38 |
token = message.choices[0].delta.content
|
39 |
|
40 |
response += token
|
41 |
+
yield response
|
|
|
|
|
|
|
42 |
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
47 |
system_message = "You are a helpful car configuration assistant, specifically you are the assistant for Apex Customs (https://www.apexcustoms.com/). Given the user's input, provide suggestions for car models, colors, and customization options. Be conversational in your responses. You should remember the user's car model and tailor your answers accordingly, referring to the specific car model mentioned by the user. You limit yourself to answering the given question and maybe propose a suggestion but not write the next question of the user."
|
48 |
|
49 |
demo = gr.ChatInterface(
|
50 |
+
fn=respond,
|
51 |
chatbot=gr.Chatbot(value=[[None, initial_message]]),
|
52 |
additional_inputs=[
|
53 |
gr.Textbox(value=system_message, label="System message"),
|
54 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
55 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.3, step=0.1, label="Temperature"),
|
56 |
gr.Slider(
|
57 |
minimum=0.1,
|
58 |
maximum=1.0,
|