Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -142,7 +142,7 @@ def merlin_chat(message, history):
|
|
| 142 |
prompt_data = history
|
| 143 |
prompt_data.append(user_msg)
|
| 144 |
prompt_data.insert(0,system_msg)
|
| 145 |
-
prompt = json.dumps(
|
| 146 |
for attempt in range(3):
|
| 147 |
# result = model(prompt, max_new_tokens=250, return_full_text=False, handle_long_generation="hole")
|
| 148 |
result = generate_text(prompt, model_path, parameters, headers)
|
|
@@ -151,14 +151,15 @@ def merlin_chat(message, history):
|
|
| 151 |
start = 0
|
| 152 |
end = 0
|
| 153 |
cleanStr = response.lstrip()
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
| 155 |
end = cleanStr.find('}') + 1
|
| 156 |
if end<=0:
|
| 157 |
continue
|
| 158 |
-
cleanStr = cleanStr[:end]
|
| 159 |
-
|
| 160 |
-
messages = json.loads(messageStr)
|
| 161 |
-
message = messages[-1]
|
| 162 |
if message['role'] != 'assistant':
|
| 163 |
continue
|
| 164 |
return message['content']
|
|
|
|
| 142 |
prompt_data = history
|
| 143 |
prompt_data.append(user_msg)
|
| 144 |
prompt_data.insert(0,system_msg)
|
| 145 |
+
prompt = json.dumps(prompt_data)[:-1] #+ ",{\"role\": \"assistant\", \"content\": \""
|
| 146 |
for attempt in range(3):
|
| 147 |
# result = model(prompt, max_new_tokens=250, return_full_text=False, handle_long_generation="hole")
|
| 148 |
result = generate_text(prompt, model_path, parameters, headers)
|
|
|
|
| 151 |
start = 0
|
| 152 |
end = 0
|
| 153 |
cleanStr = response.lstrip()
|
| 154 |
+
cleanStr = cleanStr.replace(prompt,"")
|
| 155 |
+
start = cleanStr.find('{')
|
| 156 |
+
if start<=0:
|
| 157 |
+
continue
|
| 158 |
end = cleanStr.find('}') + 1
|
| 159 |
if end<=0:
|
| 160 |
continue
|
| 161 |
+
cleanStr = cleanStr[start:end]
|
| 162 |
+
message = json.loads(cleanStr)
|
|
|
|
|
|
|
| 163 |
if message['role'] != 'assistant':
|
| 164 |
continue
|
| 165 |
return message['content']
|