fix: 修复流式输出问题,以及各种神秘问题

This commit is contained in:
tcmofashi
2025-03-31 09:09:30 +08:00
parent 1e4cdc8ce3
commit 42b1b772ef
4 changed files with 13 additions and 7 deletions

View File

@@ -50,7 +50,9 @@ class Heartflow:
# 检查所有子心流
for subheartflow_id, subheartflow in self._subheartflows.items():
if current_time - subheartflow.last_active_time > global_config.sub_heart_flow_stop_time: # 10分钟 = 600秒
if (
current_time - subheartflow.last_active_time > global_config.sub_heart_flow_stop_time
): # 10分钟 = 600秒
inactive_subheartflows.append(subheartflow_id)
logger.info(f"发现不活跃的子心流: {subheartflow_id}")

View File

@@ -162,7 +162,7 @@ class ChatBot:
logger.debug(f"8处理表情包时间: {timer2 - timer1}")
timer1 = time.time()
await self._update_using_response(message, chat, response_set)
await self._update_using_response(message, response_set)
timer2 = time.time()
logger.info(f"6更新htfl时间: {timer2 - timer1}")
@@ -213,7 +213,7 @@ class ChatBot:
stream_id, limit=global_config.MAX_CONTEXT_SIZE, combine=True
)
heartflow.get_subheartflow(stream_id).do_after_reply(response_set, chat_talking_prompt)
await heartflow.get_subheartflow(stream_id).do_after_reply(response_set, chat_talking_prompt)
async def _send_response_messages(self, message, chat, response_set, thinking_id):
container = message_manager.get_container(chat.stream_id)

View File

@@ -26,8 +26,7 @@ class ResponseGenerator:
self.model_reasoning = LLM_request(
model=global_config.llm_reasoning,
temperature=0.7,
max_tokens=1000,
stream=True,
max_tokens=3000,
request_type="response",
)
self.model_normal = LLM_request(

View File

@@ -1,9 +1,13 @@
from fastapi import FastAPI, HTTPException
from typing import Dict, Any, Callable, List
from src.common.logger import get_module_logger
import aiohttp
import asyncio
import uvicorn
import os
import traceback
logger = get_module_logger("api")
class BaseMessageAPI:
@@ -50,8 +54,9 @@ class BaseMessageAPI:
for handler in self.message_handlers:
try:
await handler(self.cache[0])
except Exception:
pass
except Exception as e:
logger.error(str(e))
logger.error(traceback.format_exc())
self.cache.pop(0)
if len(self.cache) > 0:
await asyncio.sleep(0.1 / len(self.cache))