Spaces:
Sleeping
Sleeping
Commit ·
ff62d4f
1
Parent(s): 30f47d5
Update space
Browse files
app.py
CHANGED
|
@@ -15,26 +15,29 @@ def respond(
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
for val in history:
|
| 21 |
if val[0]:
|
| 22 |
-
|
| 23 |
if val[1]:
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
response = ""
|
| 28 |
|
| 29 |
-
# Use
|
| 30 |
-
for message in client.
|
| 31 |
-
|
| 32 |
-
|
| 33 |
stream=True,
|
| 34 |
temperature=temperature,
|
| 35 |
top_p=top_p,
|
| 36 |
):
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
yield response
|
| 39 |
|
| 40 |
|
|
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 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 |
+
# Use chat completion instead of text generation
|
| 31 |
+
for message in client.chat_completion(
|
| 32 |
+
messages,
|
| 33 |
+
max_tokens=max_tokens,
|
| 34 |
stream=True,
|
| 35 |
temperature=temperature,
|
| 36 |
top_p=top_p,
|
| 37 |
):
|
| 38 |
+
token = message.choices[0].delta.content
|
| 39 |
+
if token:
|
| 40 |
+
response += token
|
| 41 |
yield response
|
| 42 |
|
| 43 |
|