Update app.py
Browse files
app.py
CHANGED
@@ -10,18 +10,18 @@ client = InferenceClient("THUDM/GLM-4-32B-0414")
|
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
for
|
21 |
-
if
|
22 |
-
messages.append({"role": "user", "content":
|
23 |
-
if
|
24 |
-
messages.append({"role": "assistant", "content":
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
@@ -34,8 +34,7 @@ def respond(
|
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
@@ -46,12 +45,14 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
additional_inputs=[
|
49 |
-
gr.Textbox(
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
56 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
57 |
gr.Slider(
|
@@ -66,4 +67,4 @@ There is also evil donald ducks and mr long reeds trying to vandlize the cars ca
|
|
66 |
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
-
demo.launch()
|
|
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
13 |
+
system_message: str,
|
14 |
+
max_tokens: int,
|
15 |
+
temperature: float,
|
16 |
+
top_p: float,
|
17 |
+
) -> str:
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
+
for user_msg, assistant_msg in history:
|
21 |
+
if user_msg:
|
22 |
+
messages.append({"role": "user", "content": user_msg})
|
23 |
+
if assistant_msg:
|
24 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
|
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
+
token = message.choices[0].delta.content or "" # Handle potential None values
|
|
|
38 |
response += token
|
39 |
yield response
|
40 |
|
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
+
gr.Textbox(
|
49 |
+
value="""From now on respond as a salesman for a car that is a ripoff of a Tesla called an Edison Model S. Respond in broken English.
|
50 |
+
The company is Edison Motors and you never mention Tesla. The car is made of cardboard and duct tape but you don't mention it.
|
51 |
+
When you understand, say "Ready".
|
52 |
+
Your name is Elon Ma and you're Chinese.
|
53 |
+
There are also evil Donald Ducks and Mr. Long Reeds trying to vandalize the cars, calling them Nazi cars or "sawasticars".""",
|
54 |
+
label="System message"
|
55 |
+
),
|
56 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
57 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
58 |
gr.Slider(
|
|
|
67 |
|
68 |
|
69 |
if __name__ == "__main__":
|
70 |
+
demo.launch()
|