mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-09-25 04:16:23 +00:00
戳一戳支持流式请求
This commit is contained in:
@ -264,7 +264,7 @@ class MarshoHandler:
|
||||
"""
|
||||
处理流式请求
|
||||
"""
|
||||
response: AsyncStream[ChatCompletionChunk] = await self.handle_single_chat(
|
||||
response = await self.handle_single_chat(
|
||||
user_message=user_message,
|
||||
model_name=model_name,
|
||||
tools_list=None, # TODO:让流式调用支持工具调用
|
||||
@ -272,4 +272,8 @@ class MarshoHandler:
|
||||
stream=True,
|
||||
)
|
||||
|
||||
return await process_chat_stream(response)
|
||||
if isinstance(response, AsyncStream):
|
||||
return await process_chat_stream(response)
|
||||
else:
|
||||
logger.error("Unexpected response type for stream request")
|
||||
return None
|
||||
|
@ -33,6 +33,7 @@ from .metadata import metadata
|
||||
from .models import MarshoContext
|
||||
from .plugin.func_call.caller import get_function_calls
|
||||
from .util import *
|
||||
from .utils.request import process_chat_stream
|
||||
|
||||
|
||||
async def at_enable():
|
||||
@ -298,15 +299,15 @@ with contextlib.suppress(ImportError): # 优化先不做()
|
||||
try:
|
||||
if config.marshoai_poke_suffix != "":
|
||||
logger.info(f"收到戳一戳,用户昵称:{user_nickname}")
|
||||
if config.marshoai_stream:
|
||||
handler = MarshoHandler(client, MarshoContext())
|
||||
response = await handler.handle_stream_request(usermsg, model_name)
|
||||
else:
|
||||
response = await make_chat_openai(
|
||||
client=client,
|
||||
model_name=model_name,
|
||||
msg=usermsg,
|
||||
)
|
||||
|
||||
response = await make_chat_openai(
|
||||
client=client,
|
||||
model_name=model_name,
|
||||
msg=usermsg,
|
||||
stream=config.marshoai_stream,
|
||||
)
|
||||
if isinstance(response, AsyncStream):
|
||||
response = await process_chat_stream(response)
|
||||
choice = response.choices[0] # type: ignore
|
||||
if choice.finish_reason == CompletionsFinishReason.STOPPED:
|
||||
content = extract_content_and_think(choice.message)[0]
|
||||
|
Reference in New Issue
Block a user