暗语初步支持 (#27)

This commit is contained in:
Akarin~
2025-06-10 13:30:54 +08:00
committed by GitHub
parent 6bfa2c39a1
commit dc6786deab
7 changed files with 96 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
import json
from datetime import timedelta
from typing import Optional, Tuple, Union
from azure.ai.inference.models import (
@@ -17,7 +18,13 @@ from nonebot.matcher import (
current_event,
current_matcher,
)
from nonebot_plugin_alconna.uniseg import UniMessage, UniMsg, get_message_id, get_target
from nonebot_plugin_alconna.uniseg import (
Text,
UniMessage,
UniMsg,
get_target,
)
from nonebot_plugin_argot import Argot # type: ignore
from openai import AsyncOpenAI, AsyncStream
from openai.types.chat import ChatCompletion, ChatCompletionChunk, ChatCompletionMessage
@@ -35,7 +42,7 @@ from .util import (
make_chat_openai,
parse_richtext,
)
from .utils.processor import process_chat_stream
from .utils.processor import process_chat_stream, process_completion_to_details
class MarshoHandler:
@@ -230,12 +237,28 @@ class MarshoHandler:
target_list.append([self.target.id, self.target.private])
# 对话成功发送消息
send_message = UniMessage()
if config.marshoai_enable_richtext_parse:
await (await parse_richtext(str(choice_msg_content))).send(
reply_to=True
)
send_message = await parse_richtext(str(choice_msg_content))
else:
await UniMessage(str(choice_msg_content)).send(reply_to=True)
send_message = UniMessage(str(choice_msg_content))
send_message.append(
Argot(
"detail",
Text(await process_completion_to_details(response)),
command="detail",
expired_at=timedelta(minutes=5),
)
)
# send_message.append(
# Argot(
# "debug",
# Text(str(response)),
# command=f"debug",
# expired_at=timedelta(minutes=5),
# )
# )
await send_message.send(reply_to=True)
return UserMessage(content=user_message), choice_msg_after
elif choice.finish_reason == CompletionsFinishReason.CONTENT_FILTERED: