update pay function
This commit is contained in:
@@ -12,6 +12,7 @@ from typing import List, Dict, Any, Optional, Literal, AsyncGenerator
|
||||
from datetime import datetime, date
|
||||
import logging
|
||||
import httpx
|
||||
import time
|
||||
from enum import Enum
|
||||
import mcp_database as db
|
||||
from openai import OpenAI
|
||||
@@ -2474,7 +2475,7 @@ MEETING_ROLES = {
|
||||
"nickname": "决策者",
|
||||
"role_type": "manager",
|
||||
"avatar": "/avatars/fund_manager.png",
|
||||
"model": "kimi-k2-thinking",
|
||||
"model": "deepseek",
|
||||
"color": "#8B5CF6",
|
||||
"description": "综合分析做出最终决策",
|
||||
"tools": ROLE_TOOLS["fund_manager"],
|
||||
@@ -2600,6 +2601,7 @@ async def stream_role_response(
|
||||
|
||||
for tool_call in assistant_message.tool_calls:
|
||||
tool_name = tool_call.function.name
|
||||
tool_call_id = tool_call.id
|
||||
try:
|
||||
arguments = json.loads(tool_call.function.arguments)
|
||||
except:
|
||||
@@ -2608,19 +2610,31 @@ async def stream_role_response(
|
||||
# 发送工具调用开始事件
|
||||
yield {
|
||||
"type": "tool_call_start",
|
||||
"tool": tool_name,
|
||||
"tool_call_id": tool_call_id,
|
||||
"tool_name": tool_name,
|
||||
"arguments": arguments
|
||||
}
|
||||
|
||||
# 执行工具调用
|
||||
start_time = time.time()
|
||||
result = await call_role_tool(role_id, tool_name, arguments)
|
||||
tool_calls_made.append(result)
|
||||
execution_time = time.time() - start_time
|
||||
tool_calls_made.append({
|
||||
"tool_call_id": tool_call_id,
|
||||
"tool_name": tool_name,
|
||||
"arguments": arguments,
|
||||
"result": result,
|
||||
"execution_time": execution_time
|
||||
})
|
||||
|
||||
# 发送工具调用结果事件
|
||||
yield {
|
||||
"type": "tool_call_result",
|
||||
"tool": tool_name,
|
||||
"result": result
|
||||
"tool_call_id": tool_call_id,
|
||||
"tool_name": tool_name,
|
||||
"result": result,
|
||||
"status": "success" if result.get("success") else "error",
|
||||
"execution_time": execution_time
|
||||
}
|
||||
|
||||
# 添加工具结果到消息
|
||||
@@ -2715,11 +2729,11 @@ async def stream_investment_meeting(request: MeetingRequest):
|
||||
|
||||
async for event in stream_role_response(role_id, request.topic, accumulated_context, role_tools):
|
||||
if event["type"] == "tool_call_start":
|
||||
yield f"data: {json.dumps({'type': 'tool_call_start', 'role_id': role_id, 'tool': event['tool'], 'arguments': event['arguments']}, ensure_ascii=False)}\n\n"
|
||||
yield f"data: {json.dumps({'type': 'tool_call_start', 'role_id': role_id, 'tool_call_id': event['tool_call_id'], 'tool_name': event['tool_name'], 'arguments': event['arguments']}, ensure_ascii=False)}\n\n"
|
||||
|
||||
elif event["type"] == "tool_call_result":
|
||||
yield f"data: {json.dumps({'type': 'tool_call_result', 'role_id': role_id, 'tool': event['tool'], 'result': event['result']}, ensure_ascii=False)}\n\n"
|
||||
tool_calls.append(event["result"])
|
||||
yield f"data: {json.dumps({'type': 'tool_call_result', 'role_id': role_id, 'tool_call_id': event['tool_call_id'], 'tool_name': event['tool_name'], 'result': event['result'], 'status': event['status'], 'execution_time': event['execution_time']}, ensure_ascii=False)}\n\n"
|
||||
tool_calls.append(event)
|
||||
|
||||
elif event["type"] == "content_delta":
|
||||
yield f"data: {json.dumps({'type': 'content_delta', 'role_id': role_id, 'content': event['content']}, ensure_ascii=False)}\n\n"
|
||||
@@ -2765,10 +2779,10 @@ async def stream_investment_meeting(request: MeetingRequest):
|
||||
|
||||
async for event in stream_role_response("fund_manager", request.topic, accumulated_context, fm_tools):
|
||||
if event["type"] == "tool_call_start":
|
||||
yield f"data: {json.dumps({'type': 'tool_call_start', 'role_id': 'fund_manager', 'tool': event['tool'], 'arguments': event['arguments']}, ensure_ascii=False)}\n\n"
|
||||
yield f"data: {json.dumps({'type': 'tool_call_start', 'role_id': 'fund_manager', 'tool_call_id': event['tool_call_id'], 'tool_name': event['tool_name'], 'arguments': event['arguments']}, ensure_ascii=False)}\n\n"
|
||||
elif event["type"] == "tool_call_result":
|
||||
yield f"data: {json.dumps({'type': 'tool_call_result', 'role_id': 'fund_manager', 'tool': event['tool'], 'result': event['result']}, ensure_ascii=False)}\n\n"
|
||||
fm_tool_calls.append(event["result"])
|
||||
yield f"data: {json.dumps({'type': 'tool_call_result', 'role_id': 'fund_manager', 'tool_call_id': event['tool_call_id'], 'tool_name': event['tool_name'], 'result': event['result'], 'status': event['status'], 'execution_time': event['execution_time']}, ensure_ascii=False)}\n\n"
|
||||
fm_tool_calls.append(event)
|
||||
elif event["type"] == "content_delta":
|
||||
yield f"data: {json.dumps({'type': 'content_delta', 'role_id': 'fund_manager', 'content': event['content']}, ensure_ascii=False)}\n\n"
|
||||
fm_full_content += event["content"]
|
||||
|
||||
Reference in New Issue
Block a user