mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
Merge branch 'xinnan-tech:main' into main
This commit is contained in:
@@ -69,6 +69,7 @@ class ListenTextMessageHandler(TextMessageHandler):
|
|||||||
enqueue_asr_report(conn, "嘿,你好呀", [])
|
enqueue_asr_report(conn, "嘿,你好呀", [])
|
||||||
await startToChat(conn, "嘿,你好呀")
|
await startToChat(conn, "嘿,你好呀")
|
||||||
else:
|
else:
|
||||||
|
conn.just_woken_up = True
|
||||||
# 上报纯文字数据(复用ASR上报功能,但不提供音频数据)
|
# 上报纯文字数据(复用ASR上报功能,但不提供音频数据)
|
||||||
enqueue_asr_report(conn, original_text, [])
|
enqueue_asr_report(conn, original_text, [])
|
||||||
# 否则需要LLM对文字内容进行答复
|
# 否则需要LLM对文字内容进行答复
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ def get_news_from_chinanews(
|
|||||||
|
|
||||||
# 否则,获取新闻列表并随机选择一条
|
# 否则,获取新闻列表并随机选择一条
|
||||||
# 从配置中获取RSS URL
|
# 从配置中获取RSS URL
|
||||||
rss_config = conn.config["plugins"]["get_news_from_chinanews"]
|
rss_config = conn.config.get("plugins", {}).get("get_news_from_chinanews", {})
|
||||||
default_rss_url = rss_config.get(
|
default_rss_url = rss_config.get(
|
||||||
"default_rss_url", "https://www.chinanews.com.cn/rss/society.xml"
|
"default_rss_url", "https://www.chinanews.com.cn/rss/society.xml"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -120,10 +120,10 @@ def fetch_news_from_api(conn, source="thepaper"):
|
|||||||
"""从API获取新闻列表"""
|
"""从API获取新闻列表"""
|
||||||
try:
|
try:
|
||||||
api_url = f"https://newsnow.busiyi.world/api/s?id={source}"
|
api_url = f"https://newsnow.busiyi.world/api/s?id={source}"
|
||||||
if conn.config["plugins"].get("get_news_from_newsnow") and conn.config[
|
|
||||||
"plugins"
|
news_config = conn.config.get("plugins", {}).get("get_news_from_newsnow", {})
|
||||||
]["get_news_from_newsnow"].get("url"):
|
if news_config.get("url"):
|
||||||
api_url = conn.config["plugins"]["get_news_from_newsnow"]["url"] + source
|
api_url = news_config["url"] + source
|
||||||
|
|
||||||
headers = {"User-Agent": "Mozilla/5.0"}
|
headers = {"User-Agent": "Mozilla/5.0"}
|
||||||
response = requests.get(api_url, headers=headers, timeout=10)
|
response = requests.get(api_url, headers=headers, timeout=10)
|
||||||
|
|||||||
@@ -158,13 +158,10 @@ def parse_weather_info(soup):
|
|||||||
def get_weather(conn, location: str = None, lang: str = "zh_CN"):
|
def get_weather(conn, location: str = None, lang: str = "zh_CN"):
|
||||||
from core.utils.cache.manager import cache_manager, CacheType
|
from core.utils.cache.manager import cache_manager, CacheType
|
||||||
|
|
||||||
api_host = conn.config["plugins"]["get_weather"].get(
|
weather_config = conn.config.get("plugins", {}).get("get_weather", {})
|
||||||
"api_host", "mj7p3y7naa.re.qweatherapi.com"
|
api_host = weather_config.get("api_host", "mj7p3y7naa.re.qweatherapi.com")
|
||||||
)
|
api_key = weather_config.get("api_key", "a861d0d5e7bf4ee1a83d9a9e4f96d4da")
|
||||||
api_key = conn.config["plugins"]["get_weather"].get(
|
default_location = weather_config.get("default_location", "广州")
|
||||||
"api_key", "a861d0d5e7bf4ee1a83d9a9e4f96d4da"
|
|
||||||
)
|
|
||||||
default_location = conn.config["plugins"]["get_weather"]["default_location"]
|
|
||||||
client_ip = conn.client_ip
|
client_ip = conn.client_ip
|
||||||
|
|
||||||
# 优先使用用户提供的location参数
|
# 优先使用用户提供的location参数
|
||||||
|
|||||||
@@ -11,15 +11,17 @@ def append_devices_to_prompt(conn):
|
|||||||
"functions", []
|
"functions", []
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 安全地获取插件配置
|
||||||
|
plugins_config = conn.config.get("plugins", {})
|
||||||
config_source = (
|
config_source = (
|
||||||
"home_assistant"
|
"home_assistant"
|
||||||
if conn.config["plugins"].get("home_assistant")
|
if plugins_config.get("home_assistant")
|
||||||
else "hass_get_state"
|
else "hass_get_state"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
||||||
prompt = "\n下面是我家智能设备列表(位置,设备名,entity_id),可以通过homeassistant控制\n"
|
prompt = "\n下面是我家智能设备列表(位置,设备名,entity_id),可以通过homeassistant控制\n"
|
||||||
deviceStr = conn.config["plugins"].get(config_source, {}).get("devices", "")
|
deviceStr = plugins_config.get(config_source, {}).get("devices", "")
|
||||||
conn.prompt += prompt + deviceStr + "\n"
|
conn.prompt += prompt + deviceStr + "\n"
|
||||||
# 更新提示词
|
# 更新提示词
|
||||||
conn.dialogue.update_system_message(conn.prompt)
|
conn.dialogue.update_system_message(conn.prompt)
|
||||||
@@ -30,17 +32,17 @@ def initialize_hass_handler(conn):
|
|||||||
if not conn.load_function_plugin:
|
if not conn.load_function_plugin:
|
||||||
return ha_config
|
return ha_config
|
||||||
|
|
||||||
|
# 安全地获取插件配置
|
||||||
|
plugins_config = conn.config.get("plugins", {})
|
||||||
# 确定配置来源
|
# 确定配置来源
|
||||||
config_source = (
|
config_source = (
|
||||||
"home_assistant"
|
"home_assistant" if plugins_config.get("home_assistant") else "hass_get_state"
|
||||||
if conn.config["plugins"].get("home_assistant")
|
|
||||||
else "hass_get_state"
|
|
||||||
)
|
)
|
||||||
if not conn.config["plugins"].get(config_source):
|
if not plugins_config.get(config_source):
|
||||||
return ha_config
|
return ha_config
|
||||||
|
|
||||||
# 统一获取配置
|
# 统一获取配置
|
||||||
plugin_config = conn.config["plugins"][config_source]
|
plugin_config = plugins_config[config_source]
|
||||||
ha_config["base_url"] = plugin_config.get("base_url")
|
ha_config["base_url"] = plugin_config.get("base_url")
|
||||||
ha_config["api_key"] = plugin_config.get("api_key")
|
ha_config["api_key"] = plugin_config.get("api_key")
|
||||||
|
|
||||||
|
|||||||
@@ -118,8 +118,9 @@ def get_music_files(music_dir, music_ext):
|
|||||||
def initialize_music_handler(conn):
|
def initialize_music_handler(conn):
|
||||||
global MUSIC_CACHE
|
global MUSIC_CACHE
|
||||||
if MUSIC_CACHE == {}:
|
if MUSIC_CACHE == {}:
|
||||||
if "play_music" in conn.config["plugins"]:
|
plugins_config = conn.config.get("plugins", {})
|
||||||
MUSIC_CACHE["music_config"] = conn.config["plugins"]["play_music"]
|
if "play_music" in plugins_config:
|
||||||
|
MUSIC_CACHE["music_config"] = plugins_config["play_music"]
|
||||||
MUSIC_CACHE["music_dir"] = os.path.abspath(
|
MUSIC_CACHE["music_dir"] = os.path.abspath(
|
||||||
MUSIC_CACHE["music_config"].get("music_dir", "./music") # 默认路径修改
|
MUSIC_CACHE["music_config"].get("music_dir", "./music") # 默认路径修改
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -32,9 +32,10 @@ def search_from_ragflow(conn, question=None):
|
|||||||
else:
|
else:
|
||||||
question = str(question) if question is not None else ""
|
question = str(question) if question is not None else ""
|
||||||
|
|
||||||
base_url = conn.config["plugins"]["search_from_ragflow"].get("base_url", "")
|
ragflow_config = conn.config.get("plugins", {}).get("search_from_ragflow", {})
|
||||||
api_key = conn.config["plugins"]["search_from_ragflow"].get("api_key", "")
|
base_url = ragflow_config.get("base_url", "")
|
||||||
dataset_ids = conn.config["plugins"]["search_from_ragflow"].get("dataset_ids", [])
|
api_key = ragflow_config.get("api_key", "")
|
||||||
|
dataset_ids = ragflow_config.get("dataset_ids", [])
|
||||||
|
|
||||||
url = base_url + "/api/v1/retrieval"
|
url = base_url + "/api/v1/retrieval"
|
||||||
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
||||||
|
|||||||
Reference in New Issue
Block a user