Compare commits

..

4 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
c6b6eef8c4 Complete Docker compatibility fix with enhanced documentation
Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
2025-08-16 16:03:54 +00:00
copilot-swe-agent[bot]
50cf263076 Implement CLI Docker compatibility fix and login-info command
Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
2025-08-16 16:01:36 +00:00
copilot-swe-agent[bot]
2554548088 Initial commit: fix formatting and explore codebase
Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
2025-08-16 15:53:37 +00:00
copilot-swe-agent[bot]
aa4a2d10e2 Initial plan 2025-08-16 15:48:10 +00:00
6 changed files with 56 additions and 75 deletions

0
astrbot.lock Normal file
View File

View File

@@ -139,6 +139,14 @@ def conf():
- dashboard.password: Dashboard 密码
- callback_api_base: 回调接口基址
可用子命令:
- set: 设置配置项值
- get: 获取配置项值
- login-info: 显示 Web 管理面板登录信息
"""
pass
@@ -204,3 +212,44 @@ def get_config(key: str = None):
click.echo(f" {key}: {value}")
except (KeyError, TypeError):
pass
@conf.command(name="login-info")
def get_login_info():
"""显示 Web 管理面板的登录信息
在 Docker 环境中使用示例:
docker exec -e ASTRBOT_ROOT=/AstrBot astrbot-container astrbot conf login-info
"""
config = _load_config()
try:
username = _get_nested_item(config, "dashboard.username")
# 注意我们不显示实际的MD5哈希密码而是提示用户如何重置
click.echo("🔐 Web 管理面板登录信息:")
click.echo(f" 用户名: {username}")
click.echo(" 密码: [已加密存储]")
click.echo()
click.echo("💡 如需重置密码,请使用以下命令:")
click.echo(" astrbot conf set dashboard.password <新密码>")
click.echo()
click.echo("🌐 访问地址:")
# 尝试获取端口信息
try:
port = _get_nested_item(config, "dashboard.port")
click.echo(f" http://localhost:{port}")
click.echo(f" http://your-server-ip:{port}")
except (KeyError, TypeError):
click.echo(" http://localhost:6185 (默认端口)")
click.echo(" http://your-server-ip:6185 (默认端口)")
click.echo()
click.echo("📋 Docker 环境使用说明:")
click.echo(" 如果在 Docker 中运行,请使用以下命令格式:")
click.echo(" docker exec -e ASTRBOT_ROOT=/AstrBot <容器名> astrbot conf login-info")
except KeyError:
click.echo("❌ 无法找到登录配置,请先运行 'astrbot init' 初始化")
except Exception as e:
raise click.UsageError(f"获取登录信息失败: {str(e)}")

View File

@@ -16,7 +16,13 @@ def check_astrbot_root(path: str | Path) -> bool:
def get_astrbot_root() -> Path:
"""获取Astrbot根目录路径"""
return Path.cwd()
import os
# 使用与core应用相同的路径解析逻辑优先使用ASTRBOT_ROOT环境变量
if path := os.environ.get("ASTRBOT_ROOT"):
return Path(path)
else:
return Path.cwd()
async def check_dashboard(astrbot_root: Path) -> None:

View File

@@ -676,7 +676,6 @@ CONFIG_METADATA_2 = {
"model": "gemini-1.5-flash",
"temperature": 0.4,
},
"enable_google_search": False,
},
"Gemini": {
"id": "gemini_default",
@@ -1577,11 +1576,6 @@ CONFIG_METADATA_2 = {
"type": "string",
"hint": "API Base URL 请在模型提供商处获得。如出现 404 报错,尝试在地址末尾加上 /v1",
},
"enable_google_search": {
"description": "启用 Google 搜索",
"type": "bool",
"hint": "启用后Gemini(OpenAI兼容) 提供商将支持 googleSearch 函数工具调用,用于网页搜索功能。",
},
"model_config": {
"description": "模型配置",
"type": "object",

View File

@@ -81,17 +81,6 @@ class ProviderOpenAIOfficial(Provider):
async def _query(self, payloads: dict, tools: FuncCall) -> LLMResponse:
if tools:
# Check if we need to add googleSearch function for Gemini(OpenAI Compatible)
if (
self.provider_config.get("enable_google_search", False)
and self.provider_config.get("api_base", "").find(
"generativelanguage.googleapis.com"
)
!= -1
):
# Add googleSearch function as alias to web_search
await self._add_google_search_tool(tools)
model = payloads.get("model", "").lower()
omit_empty_param_field = "gemini" in model
tool_list = tools.get_func_desc_openai_style(
@@ -135,17 +124,6 @@ class ProviderOpenAIOfficial(Provider):
) -> AsyncGenerator[LLMResponse, None]:
"""流式查询API逐步返回结果"""
if tools:
# Check if we need to add googleSearch function for Gemini(OpenAI Compatible)
if (
self.provider_config.get("enable_google_search", False)
and self.provider_config.get("api_base", "").find(
"generativelanguage.googleapis.com"
)
!= -1
):
# Add googleSearch function as alias to web_search
await self._add_google_search_tool(tools)
model = payloads.get("model", "").lower()
omit_empty_param_field = "gemini" in model
tool_list = tools.get_func_desc_openai_style(
@@ -575,35 +553,3 @@ class ProviderOpenAIOfficial(Provider):
image_bs64 = base64.b64encode(f.read()).decode("utf-8")
return "data:image/jpeg;base64," + image_bs64
return ""
async def _add_google_search_tool(self, tools: FuncCall) -> None:
"""Add googleSearch function as an alias to web_search for Gemini(OpenAI Compatible)"""
# Check if googleSearch is already added
for func in tools.func_list:
if func.name == "googleSearch":
return
# Check if web_search exists
web_search_func = None
for func in tools.func_list:
if func.name == "web_search":
web_search_func = func
break
if web_search_func is None:
# If web_search is not available, don't add googleSearch
return
# Add googleSearch as an alias to web_search with English description
tools.add_func(
name="googleSearch",
func_args=[
{
"type": "string",
"name": "query",
"description": "The most relevant search keywords for the user's question, used to search on Google.",
}
],
desc="Search the internet to answer user questions using Google search. Call this tool when users need to search the web for real-time information.",
handler=web_search_func.handler,
)

View File

@@ -30,11 +30,9 @@ class Main(star.Star):
websearch = self.context.get_config()["provider_settings"]["web_search"]
if websearch:
self.context.activate_llm_tool("web_search")
self.context.activate_llm_tool("googleSearch")
self.context.activate_llm_tool("fetch_url")
else:
self.context.deactivate_llm_tool("web_search")
self.context.deactivate_llm_tool("googleSearch")
self.context.deactivate_llm_tool("fetch_url")
async def _tidy_text(self, text: str) -> str:
@@ -72,14 +70,12 @@ class Main(star.Star):
self.context.get_config()["provider_settings"]["web_search"] = True
self.context.get_config().save_config()
self.context.activate_llm_tool("web_search")
self.context.activate_llm_tool("googleSearch")
self.context.activate_llm_tool("fetch_url")
event.set_result(MessageEventResult().message("已开启网页搜索功能"))
elif oper == "off":
self.context.get_config()["provider_settings"]["web_search"] = False
self.context.get_config().save_config()
self.context.deactivate_llm_tool("web_search")
self.context.deactivate_llm_tool("googleSearch")
self.context.deactivate_llm_tool("fetch_url")
event.set_result(MessageEventResult().message("已关闭网页搜索功能"))
else:
@@ -143,16 +139,6 @@ class Main(star.Star):
return ret
@llm_tool("googleSearch")
async def google_search_alias(self, event: AstrMessageEvent, query: str) -> str:
"""Search the internet to answer user questions using Google search. Call this tool when users need to search the web for real-time information.
Args:
query(string): The most relevant search keywords for the user's question, used to search on Google.
"""
# This is an alias for web_search to provide better OpenAI API compatibility
return await self.search_from_search_engine(event, query)
@llm_tool("fetch_url")
async def fetch_website_content(self, event: AstrMessageEvent, url: str) -> str:
"""fetch the content of a website with the given web url