为Ollama API返回结果添加图像字段和性能统计信息

- 在OllamaMessage中添加images字段
- 响应消息中增加images字段
- 完成标记中添加性能统计信息
- 更新测试用例以处理性能统计
- 移除测试用例中的/naive前缀
This commit is contained in:
yangdx
2025-01-15 20:46:45 +08:00
parent 23f838ec94
commit f81b1cdf0a
2 changed files with 26 additions and 16 deletions

View File

@@ -35,7 +35,7 @@ def test_stream_chat():
"messages": [
{
"role": "user",
"content": "/naive 孙悟空有什么法力,性格特征是什么"
"content": "孙悟空有什么法力,性格特征是什么"
}
],
"stream": True
@@ -51,12 +51,16 @@ def test_stream_chat():
for event in client.events():
try:
data = json.loads(event.data)
message = data.get("message", {})
content = message.get("content", "")
if content: # 只收集非空内容
output_buffer.append(content)
if data.get("done", False): # 如果收到完成标记,退出循环
break
if data.get("done", False): # 如果是完成标记
if "total_duration" in data: # 最终的性能统计消息
print("\n=== 性能统计 ===")
print(json.dumps(data, ensure_ascii=False, indent=2))
break
else: # 正常的内容消息
message = data.get("message", {})
content = message.get("content", "")
if content: # 只收集非空内容
output_buffer.append(content)
except json.JSONDecodeError:
print("Error decoding JSON from SSE event")
finally: