Spaces:
Sleeping
Sleeping
Fix syntax error in stream_anthropic function - use variables instead of multi-line f-strings
Browse files
app.py
CHANGED
|
@@ -237,7 +237,7 @@ async def stream_anthropic(ollama_stream, original_model: str):
|
|
| 237 |
message_id = f"msg_{uuid.uuid4().hex[:10]}"
|
| 238 |
|
| 239 |
# Send message_start
|
| 240 |
-
|
| 241 |
'type': 'message_start',
|
| 242 |
'message': {
|
| 243 |
'id': message_id,
|
|
@@ -249,14 +249,16 @@ async def stream_anthropic(ollama_stream, original_model: str):
|
|
| 249 |
'stop_sequence': None,
|
| 250 |
'usage': {'input_tokens': 0, 'output_tokens': 0}
|
| 251 |
}
|
| 252 |
-
}
|
|
|
|
| 253 |
|
| 254 |
# Send content_block_start
|
| 255 |
-
|
| 256 |
'type': 'content_block_start',
|
| 257 |
'index': 0,
|
| 258 |
'content_block': {'type': 'text'}
|
| 259 |
-
}
|
|
|
|
| 260 |
|
| 261 |
input_tokens = 0
|
| 262 |
output_tokens = 0
|
|
@@ -292,10 +294,11 @@ async def stream_anthropic(ollama_stream, original_model: str):
|
|
| 292 |
continue
|
| 293 |
|
| 294 |
# Send content_block_stop
|
| 295 |
-
|
| 296 |
'type': 'content_block_stop',
|
| 297 |
'index': 0
|
| 298 |
-
}
|
|
|
|
| 299 |
|
| 300 |
# Map stop reason
|
| 301 |
stop_reason_map = {
|
|
@@ -305,19 +308,19 @@ async def stream_anthropic(ollama_stream, original_model: str):
|
|
| 305 |
}
|
| 306 |
|
| 307 |
# Send message_delta
|
| 308 |
-
|
| 309 |
'type': 'message_delta',
|
| 310 |
'delta': {
|
| 311 |
'stop_reason': stop_reason_map.get(stop_reason, "end_turn"),
|
| 312 |
'stop_sequence': None
|
| 313 |
},
|
| 314 |
'usage': {'output_tokens': output_tokens}
|
| 315 |
-
}
|
|
|
|
| 316 |
|
| 317 |
# Send message_stop
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
})}\n\n"
|
| 321 |
|
| 322 |
# ==========================================
|
| 323 |
# ENDPOINTS
|
|
|
|
| 237 |
message_id = f"msg_{uuid.uuid4().hex[:10]}"
|
| 238 |
|
| 239 |
# Send message_start
|
| 240 |
+
message_start_data = {
|
| 241 |
'type': 'message_start',
|
| 242 |
'message': {
|
| 243 |
'id': message_id,
|
|
|
|
| 249 |
'stop_sequence': None,
|
| 250 |
'usage': {'input_tokens': 0, 'output_tokens': 0}
|
| 251 |
}
|
| 252 |
+
}
|
| 253 |
+
yield f"data: {json.dumps(message_start_data)}\n\n"
|
| 254 |
|
| 255 |
# Send content_block_start
|
| 256 |
+
content_block_start_data = {
|
| 257 |
'type': 'content_block_start',
|
| 258 |
'index': 0,
|
| 259 |
'content_block': {'type': 'text'}
|
| 260 |
+
}
|
| 261 |
+
yield f"data: {json.dumps(content_block_start_data)}\n\n"
|
| 262 |
|
| 263 |
input_tokens = 0
|
| 264 |
output_tokens = 0
|
|
|
|
| 294 |
continue
|
| 295 |
|
| 296 |
# Send content_block_stop
|
| 297 |
+
content_block_stop_data = {
|
| 298 |
'type': 'content_block_stop',
|
| 299 |
'index': 0
|
| 300 |
+
}
|
| 301 |
+
yield f"data: {json.dumps(content_block_stop_data)}\n\n"
|
| 302 |
|
| 303 |
# Map stop reason
|
| 304 |
stop_reason_map = {
|
|
|
|
| 308 |
}
|
| 309 |
|
| 310 |
# Send message_delta
|
| 311 |
+
message_delta_data = {
|
| 312 |
'type': 'message_delta',
|
| 313 |
'delta': {
|
| 314 |
'stop_reason': stop_reason_map.get(stop_reason, "end_turn"),
|
| 315 |
'stop_sequence': None
|
| 316 |
},
|
| 317 |
'usage': {'output_tokens': output_tokens}
|
| 318 |
+
}
|
| 319 |
+
yield f"data: {json.dumps(message_delta_data)}\n\n"
|
| 320 |
|
| 321 |
# Send message_stop
|
| 322 |
+
message_stop_data = {'type': 'message_stop'}
|
| 323 |
+
yield f"data: {json.dumps(message_stop_data)}\n\n"
|
|
|
|
| 324 |
|
| 325 |
# ==========================================
|
| 326 |
# ENDPOINTS
|