remove:移除内部固定温度参数
This commit is contained in:
@@ -14,7 +14,6 @@ from src.common.database.database import get_db_session
|
||||
from src.common.database.database_model import Images, ImageType
|
||||
from src.common.data_models.image_data_model import MaiImage
|
||||
from src.config.config import global_config
|
||||
from src.common.data_models.llm_service_data_models import LLMImageOptions
|
||||
from src.services.llm_service import LLMServiceClient
|
||||
|
||||
install(extra_lines=3)
|
||||
@@ -382,7 +381,6 @@ class ImageManager:
|
||||
prompt,
|
||||
image_base64,
|
||||
image_format,
|
||||
options=LLMImageOptions(temperature=0.4),
|
||||
)
|
||||
description = generation_result.response
|
||||
if not description:
|
||||
|
||||
@@ -14,7 +14,7 @@ from sqlmodel import select
|
||||
import Levenshtein
|
||||
|
||||
from src.common.data_models.image_data_model import MaiEmoji
|
||||
from src.common.data_models.llm_service_data_models import LLMGenerationOptions, LLMImageOptions
|
||||
from src.common.data_models.llm_service_data_models import LLMGenerationOptions
|
||||
from src.common.database.database import get_db_session, get_db_session_manual
|
||||
from src.common.database.database_model import Images, ImageType
|
||||
from src.common.logger import get_logger
|
||||
@@ -778,7 +778,7 @@ class EmojiManager:
|
||||
|
||||
decision_result = await emoji_manager_emotion_judge_llm.generate_response(
|
||||
emoji_replace_prompt,
|
||||
options=LLMGenerationOptions(temperature=0.8, max_tokens=600),
|
||||
options=LLMGenerationOptions(max_tokens=600),
|
||||
)
|
||||
decision = decision_result.response
|
||||
logger.info(f"[决策] 结果: {decision}")
|
||||
@@ -853,7 +853,6 @@ class EmojiManager:
|
||||
prompt,
|
||||
image_base64,
|
||||
"jpg",
|
||||
options=LLMImageOptions(temperature=0.5),
|
||||
)
|
||||
description = description_result.response
|
||||
else:
|
||||
@@ -865,7 +864,6 @@ class EmojiManager:
|
||||
prompt,
|
||||
image_base64,
|
||||
image_format,
|
||||
options=LLMImageOptions(temperature=0.5),
|
||||
)
|
||||
description = description_result.response
|
||||
except Exception as e:
|
||||
@@ -886,7 +884,6 @@ class EmojiManager:
|
||||
filtration_prompt,
|
||||
image_base64,
|
||||
image_format,
|
||||
options=LLMImageOptions(temperature=0.3),
|
||||
)
|
||||
llm_response = filtration_result.response
|
||||
except Exception as e:
|
||||
|
||||
@@ -9,7 +9,6 @@ import random
|
||||
from src.chat.message_receive.chat_manager import chat_manager
|
||||
from src.cli.maisaka_cli_sender import CLI_PLATFORM_NAME, render_cli_message
|
||||
from src.common.data_models.image_data_model import MaiEmoji
|
||||
from src.common.data_models.llm_service_data_models import LLMGenerationOptions
|
||||
from src.common.logger import get_logger
|
||||
from src.common.utils.utils_image import ImageUtils
|
||||
from src.services import send_service
|
||||
@@ -18,7 +17,6 @@ from .emoji_manager import (
|
||||
_normalize_emoji_tag_text,
|
||||
_serialize_emoji_for_hook,
|
||||
emoji_manager,
|
||||
emoji_manager_emotion_judge_llm,
|
||||
)
|
||||
|
||||
logger = get_logger("emoji_maisaka_tool")
|
||||
@@ -123,56 +121,6 @@ def _normalize_emotions(emoji: MaiEmoji) -> list[str]:
|
||||
return []
|
||||
|
||||
|
||||
def _build_recent_context_text(context_texts: Sequence[str], max_items: int = 5) -> str:
|
||||
"""构建供情绪判断使用的最近上下文文本。"""
|
||||
|
||||
normalized_items = [str(item).strip() for item in context_texts if str(item).strip()]
|
||||
if not normalized_items:
|
||||
return ""
|
||||
return "\n".join(normalized_items[-max_items:])
|
||||
|
||||
|
||||
async def _select_emoji_with_llm(
|
||||
*,
|
||||
sampled_emojis: Sequence[MaiEmoji],
|
||||
reasoning: str,
|
||||
context_text: str,
|
||||
) -> tuple[MaiEmoji, str]:
|
||||
"""让模型在采样表情中选择更合适的情绪标签。"""
|
||||
|
||||
emotion_map: dict[str, list[MaiEmoji]] = {}
|
||||
for emoji in sampled_emojis:
|
||||
for emotion in _normalize_emotions(emoji):
|
||||
emotion_map.setdefault(emotion, []).append(emoji)
|
||||
|
||||
available_emotions = list(emotion_map.keys())
|
||||
if not available_emotions:
|
||||
return random.choice(list(sampled_emojis)), ""
|
||||
|
||||
prompt = (
|
||||
"你正在为聊天场景选择一个最合适的表情包情绪标签。\n"
|
||||
f"发送原因:{reasoning or '辅助表达当前语气和情绪'}\n"
|
||||
f"最近聊天记录:\n{context_text or '(暂无额外上下文)'}\n\n"
|
||||
"可选情绪标签如下:\n"
|
||||
f"{chr(10).join(available_emotions)}\n\n"
|
||||
"请只返回一个最匹配的情绪标签,不要解释。"
|
||||
)
|
||||
|
||||
try:
|
||||
llm_result = await emoji_manager_emotion_judge_llm.generate_response(
|
||||
prompt,
|
||||
options=LLMGenerationOptions(temperature=0.3, max_tokens=60),
|
||||
)
|
||||
chosen_emotion = (llm_result.response or "").strip().strip("\"'")
|
||||
except Exception as exc:
|
||||
logger.warning(f"使用 LLM 选择表情情绪失败,将回退为随机选择: {exc}")
|
||||
chosen_emotion = ""
|
||||
|
||||
if chosen_emotion and chosen_emotion in emotion_map:
|
||||
return random.choice(emotion_map[chosen_emotion]), chosen_emotion
|
||||
return random.choice(list(sampled_emojis)), ""
|
||||
|
||||
|
||||
async def select_emoji_for_maisaka(
|
||||
*,
|
||||
requested_emotion: str = "",
|
||||
@@ -182,6 +130,8 @@ async def select_emoji_for_maisaka(
|
||||
) -> tuple[MaiEmoji | None, str]:
|
||||
"""为 Maisaka 选择一个合适的表情。"""
|
||||
|
||||
del reasoning, context_texts
|
||||
|
||||
available_emojis = list(emoji_manager.emojis)
|
||||
if not available_emojis:
|
||||
return None, ""
|
||||
@@ -200,12 +150,7 @@ async def select_emoji_for_maisaka(
|
||||
available_emojis,
|
||||
min(max(sample_size, 1), len(available_emojis)),
|
||||
)
|
||||
context_text = _build_recent_context_text(context_texts or [])
|
||||
return await _select_emoji_with_llm(
|
||||
sampled_emojis=sampled_emojis,
|
||||
reasoning=reasoning,
|
||||
context_text=context_text,
|
||||
)
|
||||
return random.choice(sampled_emojis), ""
|
||||
|
||||
|
||||
async def send_emoji_for_maisaka(
|
||||
|
||||
@@ -24,7 +24,6 @@ async def _run_expression_selector(tool_ctx: BuiltinToolRuntimeContext, system_p
|
||||
system_prompt=system_prompt,
|
||||
request_kind="expression_selector",
|
||||
max_tokens=256,
|
||||
temperature=0.1,
|
||||
)
|
||||
return (response.content or "").strip()
|
||||
|
||||
|
||||
@@ -187,7 +187,6 @@ class MaisakaChatLoopService:
|
||||
chat_system_prompt: Optional[str] = None,
|
||||
session_id: Optional[str] = None,
|
||||
is_group_chat: Optional[bool] = None,
|
||||
temperature: float = 0.5,
|
||||
max_tokens: int = 2048,
|
||||
) -> None:
|
||||
"""初始化 Maisaka 对话循环服务。
|
||||
@@ -196,11 +195,9 @@ class MaisakaChatLoopService:
|
||||
chat_system_prompt: 可选的系统提示词。
|
||||
session_id: 当前会话 ID,用于匹配会话级额外提示。
|
||||
is_group_chat: 当前会话是否为群聊。
|
||||
temperature: 规划器温度参数。
|
||||
max_tokens: 规划器最大输出长度。
|
||||
"""
|
||||
|
||||
self._temperature = temperature
|
||||
self._max_tokens = max_tokens
|
||||
self._is_group_chat = is_group_chat
|
||||
self._session_id = session_id or ""
|
||||
@@ -546,7 +543,6 @@ class MaisakaChatLoopService:
|
||||
message_factory=message_factory,
|
||||
options=LLMGenerationOptions(
|
||||
tool_options=all_tools if all_tools else None,
|
||||
temperature=self._temperature,
|
||||
max_tokens=self._max_tokens,
|
||||
response_format=response_format,
|
||||
interrupt_flag=self._interrupt_flag,
|
||||
|
||||
@@ -138,7 +138,6 @@ class MaisakaReasoningEngine:
|
||||
request_kind="timing_gate",
|
||||
interrupt_flag=None,
|
||||
max_tokens=TIMING_GATE_MAX_TOKENS,
|
||||
temperature=0.1,
|
||||
tool_definitions=tool_definitions,
|
||||
)
|
||||
|
||||
|
||||
@@ -566,7 +566,6 @@ class MaisakaHeartFlowChatting:
|
||||
interrupt_flag: asyncio.Event | None = None,
|
||||
max_tokens: int = 512,
|
||||
response_format: RespFormat | None = None,
|
||||
temperature: float = 0.2,
|
||||
tool_definitions: Optional[Sequence[ToolDefinitionInput]] = None,
|
||||
) -> ChatResponse:
|
||||
"""运行一个复制上下文的临时子代理,并在完成后立即销毁。"""
|
||||
@@ -584,7 +583,6 @@ class MaisakaHeartFlowChatting:
|
||||
chat_system_prompt=system_prompt,
|
||||
session_id=self.session_id,
|
||||
is_group_chat=self.chat_stream.is_group_session,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens,
|
||||
)
|
||||
sub_agent.set_interrupt_flag(interrupt_flag)
|
||||
@@ -611,7 +609,6 @@ class MaisakaHeartFlowChatting:
|
||||
request_kind="reply_effect_judge",
|
||||
extra_messages=[judge_message],
|
||||
max_tokens=900,
|
||||
temperature=0.1,
|
||||
tool_definitions=[],
|
||||
)
|
||||
return (response.content or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user