mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 23:23:55 +08:00
* fix: 退出指令无法识别 (#302) 修复指令text包含标点的情况下,无法正确识别退出指令的问题 * 优化提示词 (#303) * 添加 使用 coze 会话。 (#282) 历史消息在coze 上可配置历史消息的轮次。 同个会话id,coze 上自动带历史上下文。 会话和当前session关联。一次连接一个会话,断开后,重连是新会话无历史消息。 * update:去除无用代码 --------- Co-authored-by: Jad <journey.adc@gmail.com> Co-authored-by: Jiao Haoyang <108573524+XuSenfeng@users.noreply.github.com> Co-authored-by: xu <494462498@qq.com> Co-authored-by: hrz <1710360675@qq.com>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import List, Dict
|
|
from config.logger import setup_logging
|
|
|
|
TAG = __name__
|
|
logger = setup_logging()
|
|
|
|
|
|
class IntentProviderBase(ABC):
|
|
def __init__(self, config):
|
|
self.config = config
|
|
self.intent_options = config.get("intent_options", {
|
|
"continue_chat": "继续聊天",
|
|
"end_chat": "结束聊天",
|
|
"play_music": "播放音乐"
|
|
})
|
|
|
|
def set_llm(self, llm):
|
|
self.llm = llm
|
|
logger.bind(tag=TAG).debug("Set LLM for intent provider")
|
|
|
|
@abstractmethod
|
|
async def detect_intent(self, conn, dialogue_history: List[Dict], text: str) -> str:
|
|
"""
|
|
检测用户最后一句话的意图
|
|
Args:
|
|
dialogue_history: 对话历史记录列表,每条记录包含role和content
|
|
Returns:
|
|
返回识别出的意图,格式为:
|
|
- "继续聊天"
|
|
- "结束聊天"
|
|
- "播放音乐 歌名" 或 "随机播放音乐"
|
|
"""
|
|
pass
|