feat(nyahome): 支持模型的思考模式(DS)与编辑模型
增加了控制模型是否支持思考以及是否在调用时启用思考的开关,目前为 DeepSeek 适配。 WebUI 进行了同步的更新。
This commit is contained in:
@@ -105,11 +105,12 @@ def apply_chat(id_: int, user_id: int, chat: ChatroomChat, session: Session) ->
|
||||
"api_key": model.aii_provider.api_key,
|
||||
"model_name": model.model_name,
|
||||
"messages": messages,
|
||||
"enable_thinking": chat.enable_thinking,
|
||||
}
|
||||
|
||||
|
||||
async def s_start_async_streaming_chat(
|
||||
base_url: str, api_key: str, model_name: str, messages: list
|
||||
base_url: str, api_key: str, model_name: str, messages: list, enable_thinking: bool
|
||||
) -> AsyncGenerator[str, None]:
|
||||
client = AsyncOpenAI(base_url=base_url, api_key=api_key)
|
||||
stream = await client.chat.completions.create(
|
||||
@@ -117,6 +118,7 @@ async def s_start_async_streaming_chat(
|
||||
model=model_name,
|
||||
stream=True,
|
||||
reasoning_effort="high",
|
||||
extra_body={"thinking": {"type": "enabled" if enable_thinking else "disabled"}},
|
||||
)
|
||||
|
||||
# AI 说 SSE 好喵,推荐我用 SSE 喵,我不知道喵
|
||||
@@ -135,6 +137,7 @@ async def s_start_async_streaming_chat(
|
||||
yield f"data: {json.dumps({'text': cd, 'type': 'output'}, ensure_ascii=False)}\n\n"
|
||||
logger.info(f"AI 完成输出 : {aii_message}")
|
||||
try:
|
||||
# noinspection PyUnboundLocalVariable
|
||||
yield f"data: {json.dumps({'type': 'usage', **chuck.usage.model_dump()})}\n\n" # type: ignore[union-attr]
|
||||
finally:
|
||||
yield "data: [DONE]\n\n"
|
||||
|
||||
Reference in New Issue
Block a user