Spaces:
Runtime error
Runtime error
mikemin027
commited on
Commit
•
abff1a0
1
Parent(s):
39dd6d4
Update app.py
Browse files
app.py
CHANGED
@@ -15,32 +15,36 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
#
|
19 |
-
|
20 |
|
|
|
|
|
|
|
|
|
21 |
for val in history:
|
22 |
if val[0]:
|
23 |
-
|
24 |
if val[1]:
|
25 |
-
|
26 |
|
27 |
-
|
|
|
28 |
|
29 |
response = ""
|
30 |
|
31 |
-
# Use llm.create_completion
|
32 |
-
for
|
33 |
-
|
34 |
max_tokens=max_tokens,
|
35 |
stream=True,
|
36 |
temperature=temperature,
|
37 |
top_p=top_p,
|
38 |
):
|
39 |
-
|
40 |
-
response +=
|
41 |
yield response
|
42 |
|
43 |
-
|
44 |
# Gradio demo setup
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
+
# Initialize an empty list to hold tokenized messages
|
19 |
+
tokenized_messages = []
|
20 |
|
21 |
+
# Tokenize the system message
|
22 |
+
tokenized_messages.append(llm.tokenizer.encode(system_message))
|
23 |
+
|
24 |
+
# Tokenize the history messages
|
25 |
for val in history:
|
26 |
if val[0]:
|
27 |
+
tokenized_messages.append(llm.tokenizer.encode(val[0])) # User message
|
28 |
if val[1]:
|
29 |
+
tokenized_messages.append(llm.tokenizer.encode(val[1])) # Assistant message
|
30 |
|
31 |
+
# Tokenize the current user message
|
32 |
+
tokenized_messages.append(llm.tokenizer.encode(message))
|
33 |
|
34 |
response = ""
|
35 |
|
36 |
+
# Use llm.create_completion with tokenized messages
|
37 |
+
for token in llm.create_completion(
|
38 |
+
tokenized_messages,
|
39 |
max_tokens=max_tokens,
|
40 |
stream=True,
|
41 |
temperature=temperature,
|
42 |
top_p=top_p,
|
43 |
):
|
44 |
+
token_content = token['choices'][0]['delta']['content']
|
45 |
+
response += token_content
|
46 |
yield response
|
47 |
|
|
|
48 |
# Gradio demo setup
|
49 |
demo = gr.ChatInterface(
|
50 |
respond,
|