AstrBot 4.5.3__py3-none-any.whl → 4.5.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- astrbot/api/all.py +2 -1
- astrbot/api/provider/__init__.py +2 -1
- astrbot/core/agent/run_context.py +7 -2
- astrbot/core/agent/runners/base.py +7 -0
- astrbot/core/agent/runners/tool_loop_agent_runner.py +51 -3
- astrbot/core/agent/tool.py +5 -6
- astrbot/core/astr_agent_context.py +13 -8
- astrbot/core/astr_agent_hooks.py +36 -0
- astrbot/core/astr_agent_run_util.py +80 -0
- astrbot/core/astr_agent_tool_exec.py +246 -0
- astrbot/core/config/default.py +53 -7
- astrbot/core/exceptions.py +9 -0
- astrbot/core/pipeline/context.py +1 -2
- astrbot/core/pipeline/context_utils.py +0 -65
- astrbot/core/pipeline/process_stage/method/llm_request.py +239 -491
- astrbot/core/pipeline/respond/stage.py +21 -20
- astrbot/core/platform/platform_metadata.py +3 -0
- astrbot/core/platform/register.py +2 -0
- astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +2 -0
- astrbot/core/platform/sources/dingtalk/dingtalk_adapter.py +16 -5
- astrbot/core/platform/sources/discord/discord_platform_adapter.py +4 -1
- astrbot/core/platform/sources/discord/discord_platform_event.py +16 -7
- astrbot/core/platform/sources/lark/lark_adapter.py +4 -1
- astrbot/core/platform/sources/misskey/misskey_adapter.py +4 -1
- astrbot/core/platform/sources/satori/satori_adapter.py +2 -2
- astrbot/core/platform/sources/slack/slack_adapter.py +2 -0
- astrbot/core/platform/sources/webchat/webchat_adapter.py +3 -0
- astrbot/core/platform/sources/webchat/webchat_event.py +8 -1
- astrbot/core/platform/sources/wechatpadpro/wechatpadpro_adapter.py +4 -1
- astrbot/core/platform/sources/wechatpadpro/wechatpadpro_message_event.py +16 -0
- astrbot/core/platform/sources/wecom/wecom_adapter.py +2 -1
- astrbot/core/platform/sources/weixin_official_account/weixin_offacc_adapter.py +4 -1
- astrbot/core/provider/__init__.py +2 -2
- astrbot/core/provider/entities.py +40 -18
- astrbot/core/provider/func_tool_manager.py +15 -6
- astrbot/core/provider/manager.py +4 -1
- astrbot/core/provider/provider.py +7 -22
- astrbot/core/provider/register.py +2 -0
- astrbot/core/provider/sources/anthropic_source.py +0 -2
- astrbot/core/provider/sources/coze_source.py +0 -2
- astrbot/core/provider/sources/dashscope_source.py +1 -3
- astrbot/core/provider/sources/dify_source.py +0 -2
- astrbot/core/provider/sources/gemini_source.py +31 -3
- astrbot/core/provider/sources/groq_source.py +15 -0
- astrbot/core/provider/sources/openai_source.py +67 -21
- astrbot/core/provider/sources/zhipu_source.py +1 -6
- astrbot/core/star/context.py +197 -45
- astrbot/core/star/register/star_handler.py +30 -10
- astrbot/dashboard/routes/chat.py +5 -0
- {astrbot-4.5.3.dist-info → astrbot-4.5.7.dist-info}/METADATA +55 -65
- {astrbot-4.5.3.dist-info → astrbot-4.5.7.dist-info}/RECORD +54 -49
- {astrbot-4.5.3.dist-info → astrbot-4.5.7.dist-info}/WHEEL +0 -0
- {astrbot-4.5.3.dist-info → astrbot-4.5.7.dist-info}/entry_points.txt +0 -0
- {astrbot-4.5.3.dist-info → astrbot-4.5.7.dist-info}/licenses/LICENSE +0 -0
astrbot/core/config/default.py
CHANGED
|
@@ -4,7 +4,7 @@ import os
|
|
|
4
4
|
|
|
5
5
|
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
|
|
6
6
|
|
|
7
|
-
VERSION = "4.5.
|
|
7
|
+
VERSION = "4.5.7"
|
|
8
8
|
DB_PATH = os.path.join(get_astrbot_data_path(), "data_v4.db")
|
|
9
9
|
|
|
10
10
|
# 默认配置
|
|
@@ -68,7 +68,7 @@ DEFAULT_CONFIG = {
|
|
|
68
68
|
"dequeue_context_length": 1,
|
|
69
69
|
"streaming_response": False,
|
|
70
70
|
"show_tool_use_status": False,
|
|
71
|
-
"
|
|
71
|
+
"unsupported_streaming_strategy": "realtime_segmenting",
|
|
72
72
|
"max_agent_step": 30,
|
|
73
73
|
"tool_call_timeout": 60,
|
|
74
74
|
},
|
|
@@ -740,6 +740,7 @@ CONFIG_METADATA_2 = {
|
|
|
740
740
|
"api_base": "https://api.openai.com/v1",
|
|
741
741
|
"timeout": 120,
|
|
742
742
|
"model_config": {"model": "gpt-4o-mini", "temperature": 0.4},
|
|
743
|
+
"custom_headers": {},
|
|
743
744
|
"custom_extra_body": {},
|
|
744
745
|
"modalities": ["text", "image", "tool_use"],
|
|
745
746
|
"hint": "也兼容所有与 OpenAI API 兼容的服务。",
|
|
@@ -755,6 +756,7 @@ CONFIG_METADATA_2 = {
|
|
|
755
756
|
"api_base": "",
|
|
756
757
|
"timeout": 120,
|
|
757
758
|
"model_config": {"model": "gpt-4o-mini", "temperature": 0.4},
|
|
759
|
+
"custom_headers": {},
|
|
758
760
|
"custom_extra_body": {},
|
|
759
761
|
"modalities": ["text", "image", "tool_use"],
|
|
760
762
|
},
|
|
@@ -768,6 +770,7 @@ CONFIG_METADATA_2 = {
|
|
|
768
770
|
"api_base": "https://api.x.ai/v1",
|
|
769
771
|
"timeout": 120,
|
|
770
772
|
"model_config": {"model": "grok-2-latest", "temperature": 0.4},
|
|
773
|
+
"custom_headers": {},
|
|
771
774
|
"custom_extra_body": {},
|
|
772
775
|
"xai_native_search": False,
|
|
773
776
|
"modalities": ["text", "image", "tool_use"],
|
|
@@ -799,6 +802,7 @@ CONFIG_METADATA_2 = {
|
|
|
799
802
|
"key": ["ollama"], # ollama 的 key 默认是 ollama
|
|
800
803
|
"api_base": "http://localhost:11434/v1",
|
|
801
804
|
"model_config": {"model": "llama3.1-8b", "temperature": 0.4},
|
|
805
|
+
"custom_headers": {},
|
|
802
806
|
"custom_extra_body": {},
|
|
803
807
|
"modalities": ["text", "image", "tool_use"],
|
|
804
808
|
},
|
|
@@ -813,6 +817,7 @@ CONFIG_METADATA_2 = {
|
|
|
813
817
|
"model_config": {
|
|
814
818
|
"model": "llama-3.1-8b",
|
|
815
819
|
},
|
|
820
|
+
"custom_headers": {},
|
|
816
821
|
"custom_extra_body": {},
|
|
817
822
|
"modalities": ["text", "image", "tool_use"],
|
|
818
823
|
},
|
|
@@ -829,6 +834,7 @@ CONFIG_METADATA_2 = {
|
|
|
829
834
|
"model": "gemini-1.5-flash",
|
|
830
835
|
"temperature": 0.4,
|
|
831
836
|
},
|
|
837
|
+
"custom_headers": {},
|
|
832
838
|
"custom_extra_body": {},
|
|
833
839
|
"modalities": ["text", "image", "tool_use"],
|
|
834
840
|
},
|
|
@@ -870,6 +876,24 @@ CONFIG_METADATA_2 = {
|
|
|
870
876
|
"api_base": "https://api.deepseek.com/v1",
|
|
871
877
|
"timeout": 120,
|
|
872
878
|
"model_config": {"model": "deepseek-chat", "temperature": 0.4},
|
|
879
|
+
"custom_headers": {},
|
|
880
|
+
"custom_extra_body": {},
|
|
881
|
+
"modalities": ["text", "tool_use"],
|
|
882
|
+
},
|
|
883
|
+
"Groq": {
|
|
884
|
+
"id": "groq_default",
|
|
885
|
+
"provider": "groq",
|
|
886
|
+
"type": "groq_chat_completion",
|
|
887
|
+
"provider_type": "chat_completion",
|
|
888
|
+
"enable": True,
|
|
889
|
+
"key": [],
|
|
890
|
+
"api_base": "https://api.groq.com/openai/v1",
|
|
891
|
+
"timeout": 120,
|
|
892
|
+
"model_config": {
|
|
893
|
+
"model": "openai/gpt-oss-20b",
|
|
894
|
+
"temperature": 0.4,
|
|
895
|
+
},
|
|
896
|
+
"custom_headers": {},
|
|
873
897
|
"custom_extra_body": {},
|
|
874
898
|
"modalities": ["text", "tool_use"],
|
|
875
899
|
},
|
|
@@ -883,6 +907,7 @@ CONFIG_METADATA_2 = {
|
|
|
883
907
|
"api_base": "https://api.302.ai/v1",
|
|
884
908
|
"timeout": 120,
|
|
885
909
|
"model_config": {"model": "gpt-4.1-mini", "temperature": 0.4},
|
|
910
|
+
"custom_headers": {},
|
|
886
911
|
"custom_extra_body": {},
|
|
887
912
|
"modalities": ["text", "image", "tool_use"],
|
|
888
913
|
},
|
|
@@ -899,6 +924,7 @@ CONFIG_METADATA_2 = {
|
|
|
899
924
|
"model": "deepseek-ai/DeepSeek-V3",
|
|
900
925
|
"temperature": 0.4,
|
|
901
926
|
},
|
|
927
|
+
"custom_headers": {},
|
|
902
928
|
"custom_extra_body": {},
|
|
903
929
|
"modalities": ["text", "image", "tool_use"],
|
|
904
930
|
},
|
|
@@ -915,6 +941,7 @@ CONFIG_METADATA_2 = {
|
|
|
915
941
|
"model": "deepseek/deepseek-r1",
|
|
916
942
|
"temperature": 0.4,
|
|
917
943
|
},
|
|
944
|
+
"custom_headers": {},
|
|
918
945
|
"custom_extra_body": {},
|
|
919
946
|
},
|
|
920
947
|
"小马算力": {
|
|
@@ -930,6 +957,7 @@ CONFIG_METADATA_2 = {
|
|
|
930
957
|
"model": "kimi-k2-instruct-0905",
|
|
931
958
|
"temperature": 0.7,
|
|
932
959
|
},
|
|
960
|
+
"custom_headers": {},
|
|
933
961
|
"custom_extra_body": {},
|
|
934
962
|
},
|
|
935
963
|
"优云智算": {
|
|
@@ -944,6 +972,7 @@ CONFIG_METADATA_2 = {
|
|
|
944
972
|
"model_config": {
|
|
945
973
|
"model": "moonshotai/Kimi-K2-Instruct",
|
|
946
974
|
},
|
|
975
|
+
"custom_headers": {},
|
|
947
976
|
"custom_extra_body": {},
|
|
948
977
|
"modalities": ["text", "image", "tool_use"],
|
|
949
978
|
},
|
|
@@ -957,6 +986,7 @@ CONFIG_METADATA_2 = {
|
|
|
957
986
|
"timeout": 120,
|
|
958
987
|
"api_base": "https://api.moonshot.cn/v1",
|
|
959
988
|
"model_config": {"model": "moonshot-v1-8k", "temperature": 0.4},
|
|
989
|
+
"custom_headers": {},
|
|
960
990
|
"custom_extra_body": {},
|
|
961
991
|
"modalities": ["text", "image", "tool_use"],
|
|
962
992
|
},
|
|
@@ -972,6 +1002,8 @@ CONFIG_METADATA_2 = {
|
|
|
972
1002
|
"model_config": {
|
|
973
1003
|
"model": "glm-4-flash",
|
|
974
1004
|
},
|
|
1005
|
+
"custom_headers": {},
|
|
1006
|
+
"custom_extra_body": {},
|
|
975
1007
|
"modalities": ["text", "image", "tool_use"],
|
|
976
1008
|
},
|
|
977
1009
|
"Dify": {
|
|
@@ -1028,6 +1060,7 @@ CONFIG_METADATA_2 = {
|
|
|
1028
1060
|
"timeout": 120,
|
|
1029
1061
|
"api_base": "https://api-inference.modelscope.cn/v1",
|
|
1030
1062
|
"model_config": {"model": "Qwen/Qwen3-32B", "temperature": 0.4},
|
|
1063
|
+
"custom_headers": {},
|
|
1031
1064
|
"custom_extra_body": {},
|
|
1032
1065
|
"modalities": ["text", "image", "tool_use"],
|
|
1033
1066
|
},
|
|
@@ -1040,6 +1073,7 @@ CONFIG_METADATA_2 = {
|
|
|
1040
1073
|
"key": [],
|
|
1041
1074
|
"api_base": "https://api.fastgpt.in/api/v1",
|
|
1042
1075
|
"timeout": 60,
|
|
1076
|
+
"custom_headers": {},
|
|
1043
1077
|
"custom_extra_body": {},
|
|
1044
1078
|
},
|
|
1045
1079
|
"Whisper(API)": {
|
|
@@ -1321,6 +1355,12 @@ CONFIG_METADATA_2 = {
|
|
|
1321
1355
|
"render_type": "checkbox",
|
|
1322
1356
|
"hint": "模型支持的模态。如所填写的模型不支持图像,请取消勾选图像。",
|
|
1323
1357
|
},
|
|
1358
|
+
"custom_headers": {
|
|
1359
|
+
"description": "自定义添加请求头",
|
|
1360
|
+
"type": "dict",
|
|
1361
|
+
"items": {},
|
|
1362
|
+
"hint": "此处添加的键值对将被合并到 OpenAI SDK 的 default_headers 中,用于自定义 HTTP 请求头。值必须为字符串。",
|
|
1363
|
+
},
|
|
1324
1364
|
"custom_extra_body": {
|
|
1325
1365
|
"description": "自定义请求体参数",
|
|
1326
1366
|
"type": "dict",
|
|
@@ -1970,8 +2010,8 @@ CONFIG_METADATA_2 = {
|
|
|
1970
2010
|
"show_tool_use_status": {
|
|
1971
2011
|
"type": "bool",
|
|
1972
2012
|
},
|
|
1973
|
-
"
|
|
1974
|
-
"type": "
|
|
2013
|
+
"unsupported_streaming_strategy": {
|
|
2014
|
+
"type": "string",
|
|
1975
2015
|
},
|
|
1976
2016
|
"max_agent_step": {
|
|
1977
2017
|
"description": "工具调用轮数上限",
|
|
@@ -2276,9 +2316,15 @@ CONFIG_METADATA_3 = {
|
|
|
2276
2316
|
"description": "流式回复",
|
|
2277
2317
|
"type": "bool",
|
|
2278
2318
|
},
|
|
2279
|
-
"provider_settings.
|
|
2280
|
-
"description": "
|
|
2281
|
-
"type": "
|
|
2319
|
+
"provider_settings.unsupported_streaming_strategy": {
|
|
2320
|
+
"description": "不支持流式回复的平台",
|
|
2321
|
+
"type": "string",
|
|
2322
|
+
"options": ["realtime_segmenting", "turn_off"],
|
|
2323
|
+
"hint": "选择在不支持流式回复的平台上的处理方式。实时分段回复会在系统接收流式响应检测到诸如标点符号等分段点时,立即发送当前已接收的内容",
|
|
2324
|
+
"labels": ["实时分段回复", "关闭流式回复"],
|
|
2325
|
+
"condition": {
|
|
2326
|
+
"provider_settings.streaming_response": True,
|
|
2327
|
+
},
|
|
2282
2328
|
},
|
|
2283
2329
|
"provider_settings.max_context_length": {
|
|
2284
2330
|
"description": "最多携带对话轮数",
|
astrbot/core/pipeline/context.py
CHANGED
|
@@ -3,7 +3,7 @@ from dataclasses import dataclass
|
|
|
3
3
|
from astrbot.core.config import AstrBotConfig
|
|
4
4
|
from astrbot.core.star import PluginManager
|
|
5
5
|
|
|
6
|
-
from .context_utils import call_event_hook, call_handler
|
|
6
|
+
from .context_utils import call_event_hook, call_handler
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
@dataclass
|
|
@@ -15,4 +15,3 @@ class PipelineContext:
|
|
|
15
15
|
astrbot_config_id: str
|
|
16
16
|
call_handler = call_handler
|
|
17
17
|
call_event_hook = call_event_hook
|
|
18
|
-
call_local_llm_tool = call_local_llm_tool
|
|
@@ -3,8 +3,6 @@ import traceback
|
|
|
3
3
|
import typing as T
|
|
4
4
|
|
|
5
5
|
from astrbot import logger
|
|
6
|
-
from astrbot.core.agent.run_context import ContextWrapper
|
|
7
|
-
from astrbot.core.astr_agent_context import AstrAgentContext
|
|
8
6
|
from astrbot.core.message.message_event_result import CommandResult, MessageEventResult
|
|
9
7
|
from astrbot.core.platform.astr_message_event import AstrMessageEvent
|
|
10
8
|
from astrbot.core.star.star import star_map
|
|
@@ -107,66 +105,3 @@ async def call_event_hook(
|
|
|
107
105
|
return True
|
|
108
106
|
|
|
109
107
|
return event.is_stopped()
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
async def call_local_llm_tool(
|
|
113
|
-
context: ContextWrapper[AstrAgentContext],
|
|
114
|
-
handler: T.Callable[..., T.Awaitable[T.Any]],
|
|
115
|
-
method_name: str,
|
|
116
|
-
*args,
|
|
117
|
-
**kwargs,
|
|
118
|
-
) -> T.AsyncGenerator[T.Any, None]:
|
|
119
|
-
"""执行本地 LLM 工具的处理函数并处理其返回结果"""
|
|
120
|
-
ready_to_call = None # 一个协程或者异步生成器
|
|
121
|
-
|
|
122
|
-
trace_ = None
|
|
123
|
-
|
|
124
|
-
event = context.context.event
|
|
125
|
-
|
|
126
|
-
try:
|
|
127
|
-
if method_name == "run" or method_name == "decorator_handler":
|
|
128
|
-
ready_to_call = handler(event, *args, **kwargs)
|
|
129
|
-
elif method_name == "call":
|
|
130
|
-
ready_to_call = handler(context, *args, **kwargs)
|
|
131
|
-
else:
|
|
132
|
-
raise ValueError(f"未知的方法名: {method_name}")
|
|
133
|
-
except ValueError as e:
|
|
134
|
-
logger.error(f"调用本地 LLM 工具时出错: {e}", exc_info=True)
|
|
135
|
-
except TypeError:
|
|
136
|
-
logger.error("处理函数参数不匹配,请检查 handler 的定义。", exc_info=True)
|
|
137
|
-
except Exception as e:
|
|
138
|
-
trace_ = traceback.format_exc()
|
|
139
|
-
logger.error(f"调用本地 LLM 工具时出错: {e}\n{trace_}")
|
|
140
|
-
|
|
141
|
-
if not ready_to_call:
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
if inspect.isasyncgen(ready_to_call):
|
|
145
|
-
_has_yielded = False
|
|
146
|
-
try:
|
|
147
|
-
async for ret in ready_to_call:
|
|
148
|
-
# 这里逐步执行异步生成器, 对于每个 yield 返回的 ret, 执行下面的代码
|
|
149
|
-
# 返回值只能是 MessageEventResult 或者 None(无返回值)
|
|
150
|
-
_has_yielded = True
|
|
151
|
-
if isinstance(ret, (MessageEventResult, CommandResult)):
|
|
152
|
-
# 如果返回值是 MessageEventResult, 设置结果并继续
|
|
153
|
-
event.set_result(ret)
|
|
154
|
-
yield
|
|
155
|
-
else:
|
|
156
|
-
# 如果返回值是 None, 则不设置结果并继续
|
|
157
|
-
# 继续执行后续阶段
|
|
158
|
-
yield ret
|
|
159
|
-
if not _has_yielded:
|
|
160
|
-
# 如果这个异步生成器没有执行到 yield 分支
|
|
161
|
-
yield
|
|
162
|
-
except Exception as e:
|
|
163
|
-
logger.error(f"Previous Error: {trace_}")
|
|
164
|
-
raise e
|
|
165
|
-
elif inspect.iscoroutine(ready_to_call):
|
|
166
|
-
# 如果只是一个协程, 直接执行
|
|
167
|
-
ret = await ready_to_call
|
|
168
|
-
if isinstance(ret, (MessageEventResult, CommandResult)):
|
|
169
|
-
event.set_result(ret)
|
|
170
|
-
yield
|
|
171
|
-
else:
|
|
172
|
-
yield ret
|