Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,19 +19,28 @@ def respond(message, history, character_id, max_tokens, temperature, top_p):
|
|
| 19 |
char = character_dict[character_id]
|
| 20 |
system_message = char["persona_prompt"]
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
messages,
|
| 27 |
max_tokens=max_tokens,
|
| 28 |
temperature=temperature,
|
| 29 |
top_p=top_p,
|
| 30 |
-
stream=False
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Tạo danh sách lựa chọn nhân vật
|
| 37 |
def format_label(c):
|
|
|
|
| 19 |
char = character_dict[character_id]
|
| 20 |
system_message = char["persona_prompt"]
|
| 21 |
|
| 22 |
+
# Format lại history đúng kiểu "messages"
|
| 23 |
+
messages = [{"role": "system", "content": system_message}]
|
| 24 |
+
for turn in history:
|
| 25 |
+
if turn["role"] in ["user", "assistant"]:
|
| 26 |
+
messages.append(turn)
|
| 27 |
|
| 28 |
+
messages.append({"role": "user", "content": message})
|
| 29 |
+
|
| 30 |
+
# Không dùng stream
|
| 31 |
+
result = client.chat_completion(
|
| 32 |
messages,
|
| 33 |
max_tokens=max_tokens,
|
| 34 |
temperature=temperature,
|
| 35 |
top_p=top_p,
|
| 36 |
+
stream=False
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
reply = result.choices[0].message.content
|
| 40 |
+
history.append({"role": "user", "content": message})
|
| 41 |
+
history.append({"role": "assistant", "content": reply})
|
| 42 |
+
return history
|
| 43 |
+
|
| 44 |
|
| 45 |
# Tạo danh sách lựa chọn nhân vật
|
| 46 |
def format_label(c):
|