Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions astrbot/builtin_stars/astrbot/long_term_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def get_image_caption(
image_caption_prompt: str,
) -> str:
if not image_caption_provider_id:
provider = self.context.get_using_provider()
provider = await self.context.get_using_provider()
else:
provider = self.context.get_provider_by_id(image_caption_provider_id)
if not provider:
Expand Down Expand Up @@ -164,7 +164,9 @@ async def on_req_llm(self, event: AstrMessageEvent, req: ProviderRequest):
"Please react to it. Only output your response and do not output any other information. "
"You MUST use the SAME language as the chatroom is using."
)
req.contexts = [] # 清空上下文,当使用了主动回复,所有聊天记录都在一个prompt中。
req.contexts = (
[]
) # 清空上下文,当使用了主动回复,所有聊天记录都在一个prompt中。
else:
req.system_prompt += (
"You are now in a chatroom. The chat history is as follows: \n"
Expand Down
4 changes: 3 additions & 1 deletion astrbot/builtin_stars/astrbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ async def on_message(self, event: AstrMessageEvent):

if need_active:
"""主动回复"""
provider = self.context.get_using_provider(event.unified_msg_origin)
provider = await self.context.get_using_provider(
event.unified_msg_origin
)
if not provider:
logger.error("未找到任何 LLM 提供商。请先配置。无法主动回复")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def reset(self, message: AstrMessageEvent):
message.set_result(MessageEventResult().message("重置对话成功。"))
return

if not self.context.get_using_provider(umo):
if not await self.context.get_using_provider(umo):
message.set_result(
MessageEventResult().message("未找到任何 LLM 提供商。请先配置。"),
)
Expand Down Expand Up @@ -100,7 +100,7 @@ async def reset(self, message: AstrMessageEvent):

async def his(self, message: AstrMessageEvent, page: int = 1):
"""查看对话记录"""
if not self.context.get_using_provider(message.unified_msg_origin):
if not await self.context.get_using_provider(message.unified_msg_origin):
message.set_result(
MessageEventResult().message("未找到任何 LLM 提供商。请先配置。"),
)
Expand Down
10 changes: 5 additions & 5 deletions astrbot/builtin_stars/builtin_commands/commands/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def provider(
llm_data = [d for d in display_data if d["type"] == "llm"]
for i, d in enumerate(llm_data):
line = f"{i + 1}. {d['info']}{d['mark']}"
provider_using = self.context.get_using_provider(umo=umo)
provider_using = await self.context.get_using_provider(umo=umo)
if (
provider_using
and provider_using.meta().id == d["provider"].meta().id
Expand All @@ -152,7 +152,7 @@ async def provider(
parts.append("\n## 载入的 TTS 提供商\n")
for i, d in enumerate(tts_data):
line = f"{i + 1}. {d['info']}{d['mark']}"
tts_using = self.context.get_using_tts_provider(umo=umo)
tts_using = await self.context.get_using_tts_provider(umo=umo)
if tts_using and tts_using.meta().id == d["provider"].meta().id:
line += " (当前使用)"
parts.append(line + "\n")
Expand All @@ -163,7 +163,7 @@ async def provider(
parts.append("\n## 载入的 STT 提供商\n")
for i, d in enumerate(stt_data):
line = f"{i + 1}. {d['info']}{d['mark']}"
stt_using = self.context.get_using_stt_provider(umo=umo)
stt_using = await self.context.get_using_stt_provider(umo=umo)
if stt_using and stt_using.meta().id == d["provider"].meta().id:
line += " (当前使用)"
parts.append(line + "\n")
Expand Down Expand Up @@ -230,7 +230,7 @@ async def model_ls(
idx_or_name: int | str | None = None,
):
"""查看或者切换模型"""
prov = self.context.get_using_provider(message.unified_msg_origin)
prov = await self.context.get_using_provider(message.unified_msg_origin)
if not prov:
message.set_result(
MessageEventResult().message("未找到任何 LLM 提供商。请先配置。"),
Expand Down Expand Up @@ -294,7 +294,7 @@ async def model_ls(
)

async def key(self, message: AstrMessageEvent, index: int | None = None):
prov = self.context.get_using_provider(message.unified_msg_origin)
prov = await self.context.get_using_provider(message.unified_msg_origin)
if not prov:
message.set_result(
MessageEventResult().message("未找到任何 LLM 提供商。请先配置。"),
Expand Down
2 changes: 1 addition & 1 deletion astrbot/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.14.7"
__version__ = "4.14.8"
8 changes: 4 additions & 4 deletions astrbot/core/astr_main_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class MainAgentBuildResult:
reset_coro: Coroutine | None = None


def _select_provider(
async def _select_provider(
event: AstrMessageEvent, plugin_context: Context
) -> Provider | None:
"""Select chat provider for the event."""
Expand All @@ -134,7 +134,7 @@ def _select_provider(
return None
return provider
try:
return plugin_context.get_using_provider(umo=event.unified_msg_origin)
return await plugin_context.get_using_provider(umo=event.unified_msg_origin)
except ValueError as exc:
logger.error("Error occurred while selecting provider: %s", exc)
return None
Expand Down Expand Up @@ -505,7 +505,7 @@ async def _process_quote_message(
if img_cap_prov_id:
prov = plugin_context.get_provider_by_id(img_cap_prov_id)
if prov is None:
prov = plugin_context.get_using_provider(event.unified_msg_origin)
prov = await plugin_context.get_using_provider(event.unified_msg_origin)

if prov and isinstance(prov, Provider):
llm_resp = await prov.text_chat(
Expand Down Expand Up @@ -845,7 +845,7 @@ async def build_main_agent(

If apply_reset is False, will not call reset on the agent runner.
"""
provider = provider or _select_provider(event, plugin_context)
provider = provider or await _select_provider(event, plugin_context)
if provider is None:
logger.info("未找到任何对话模型(提供商),跳过 LLM 请求处理。")
return None
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from astrbot.core.utils.astrbot_path import get_astrbot_data_path

VERSION = "4.14.7"
VERSION = "4.14.8"
DB_PATH = os.path.join(get_astrbot_data_path(), "data_v4.db")

WEBHOOK_SUPPORTED_PLATFORMS = [
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/pipeline/preprocess_stage/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def process(
if self.stt_settings.get("enable", False):
# TODO: 独立
ctx = self.plugin_manager.context
stt_provider = ctx.get_using_stt_provider(event.unified_msg_origin)
stt_provider = await ctx.get_using_stt_provider(event.unified_msg_origin)
if not stt_provider:
logger.warning(
f"会话 {event.unified_msg_origin} 未配置语音转文本模型。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async def process(

# 获取 TTS Provider
tts_provider = (
self.ctx.plugin_manager.context.get_using_tts_provider(
await self.ctx.plugin_manager.context.get_using_tts_provider(
event.unified_msg_origin
)
)
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/pipeline/result_decorate/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ async def process(
result.chain = new_chain

# TTS
tts_provider = self.ctx.plugin_manager.context.get_using_tts_provider(
tts_provider = await self.ctx.plugin_manager.context.get_using_tts_provider(
event.unified_msg_origin,
)

Expand Down
12 changes: 6 additions & 6 deletions astrbot/core/provider/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async def get_provider_by_id(self, provider_id: str) -> Providers | None:
"""根据提供商 ID 获取提供商实例"""
return self.inst_map.get(provider_id)

def get_using_provider(
async def get_using_provider(
self, provider_type: ProviderType, umo=None
) -> Providers | None:
"""获取正在使用的提供商实例。
Expand All @@ -169,11 +169,11 @@ def get_using_provider(
provider = None
provider_id = None
if umo:
provider_id = sp.get(
f"provider_perf_{provider_type.value}",
None,
scope="umo",
scope_id=umo,
provider_id = await sp.get_async(
scope="umo",
scope_id=umo,
key=f"provider_perf_{provider_type.value}",
default=None,
)
if provider_id:
provider = self.inst_map.get(provider_id)
Expand Down
14 changes: 7 additions & 7 deletions astrbot/core/star/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async def get_current_chat_provider_id(self, umo: str) -> str:
Raises:
ProviderNotFoundError: 未找到。
"""
prov = self.get_using_provider(umo)
prov = await self.get_using_provider(umo)
if not prov:
raise ProviderNotFoundError("Provider not found")
return prov.meta().id
Expand Down Expand Up @@ -335,7 +335,7 @@ def get_all_embedding_providers(self) -> list[EmbeddingProvider]:
"""获取所有用于 Embedding 任务的 Provider。"""
return self.provider_manager.embedding_provider_insts

def get_using_provider(self, umo: str | None = None) -> Provider | None:
async def get_using_provider(self, umo: str | None = None) -> Provider | None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

保持同步方法的原因是为了向后兼容。直接将这个改为异步方法会导致插件不兼容。

建议新建 get_using_provider_async 方法去处理。

"""获取当前使用的用于文本生成任务的 LLM Provider(Chat_Completion 类型)。

Args:
Expand All @@ -348,7 +348,7 @@ def get_using_provider(self, umo: str | None = None) -> Provider | None:
Raises:
ValueError: 该会话来源配置的的对话模型(提供商)的类型不正确。
"""
prov = self.provider_manager.get_using_provider(
prov = await self.provider_manager.get_using_provider(
provider_type=ProviderType.CHAT_COMPLETION,
umo=umo,
)
Expand All @@ -360,7 +360,7 @@ def get_using_provider(self, umo: str | None = None) -> Provider | None:
)
return prov

def get_using_tts_provider(self, umo: str | None = None) -> TTSProvider | None:
async def get_using_tts_provider(self, umo: str | None = None) -> TTSProvider | None:
"""获取当前使用的用于 TTS 任务的 Provider。

Args:
Expand All @@ -372,15 +372,15 @@ def get_using_tts_provider(self, umo: str | None = None) -> TTSProvider | None:
Raises:
ValueError: 返回的提供者不是 TTSProvider 类型。
"""
prov = self.provider_manager.get_using_provider(
prov = await self.provider_manager.get_using_provider(
provider_type=ProviderType.TEXT_TO_SPEECH,
umo=umo,
)
if prov and not isinstance(prov, TTSProvider):
raise ValueError("返回的 Provider 不是 TTSProvider 类型")
return prov

def get_using_stt_provider(self, umo: str | None = None) -> STTProvider | None:
async def get_using_stt_provider(self, umo: str | None = None) -> STTProvider | None:
"""获取当前使用的用于 STT 任务的 Provider。

Args:
Expand All @@ -392,7 +392,7 @@ def get_using_stt_provider(self, umo: str | None = None) -> STTProvider | None:
Raises:
ValueError: 返回的提供者不是 STTProvider 类型。
"""
prov = self.provider_manager.get_using_provider(
prov = await self.provider_manager.get_using_provider(
provider_type=ProviderType.SPEECH_TO_TEXT,
umo=umo,
)
Expand Down
35 changes: 35 additions & 0 deletions changelogs/v4.14.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## What's Changed

hotfix of 4.14.7

- 为 AstrBot Electron App 增加特殊的更新处理。

### 修复
- 人格预设对话可能会重复添加到上下文 ([#4961](https://github.com/AstrBotDevs/AstrBot/issues/4961))

### 新增
- 增加提供商级别的代理支持 ([#4949](https://github.com/AstrBotDevs/AstrBot/issues/4949))
- WebUI 管理行为增加插件指令权限管理功能 ([#4887](https://github.com/AstrBotDevs/AstrBot/issues/4887))
- 允许 LLM 预览工具返回的图片并自主决定是否发送 ([#4895](https://github.com/AstrBotDevs/AstrBot/issues/4895))
- Telegram 平台添加媒体组(相册)支持 ([#4893](https://github.com/AstrBotDevs/AstrBot/issues/4893))
- 增加欢迎功能,支持本地化内容和新手引导步骤
- 支持 Electron 桌面应用部署 ([#4952](https://github.com/AstrBotDevs/AstrBot/issues/4952))

### 注意
- 更新 AstrBot Python 版本要求至 3.12 ([#4963](https://github.com/AstrBotDevs/AstrBot/issues/4963))

## What's Changed

### Fixes
- Fixed issue where persona preset conversations could be duplicated in context ([#4961](https://github.com/AstrBotDevs/AstrBot/issues/4961))

### Features
- Added provider-level proxy support ([#4949](https://github.com/AstrBotDevs/AstrBot/issues/4949))
- Added plugin command permission management to WebUI management behavior ([#4887](https://github.com/AstrBotDevs/AstrBot/issues/4887))
- Allowed LLMs to preview images returned by tools and autonomously decide whether to send them ([#4895](https://github.com/AstrBotDevs/AstrBot/issues/4895))
- Added media group (album) support for Telegram platform ([#4893](https://github.com/AstrBotDevs/AstrBot/issues/4893))
- Added welcome feature with support for localized content and onboarding steps
- Supported Electron desktop application deployment ([#4952](https://github.com/AstrBotDevs/AstrBot/issues/4952))

### Notice
- Updated AstrBot Python version requirement to 3.12 ([#4963](https://github.com/AstrBotDevs/AstrBot/issues/4963))
2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astrbot-desktop",
"version": "4.14.6",
"version": "4.14.7",
"description": "AstrBot desktop wrapper",
"private": true,
"main": "main.js",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "AstrBot"
version = "4.14.7"
version = "4.14.8"
description = "Easy-to-use multi-platform LLM chatbot and development framework"
readme = "README.md"
requires-python = ">=3.12"
Expand Down