Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
additional_dependencies: ["types-PyYAML", "types-pytz", "azure-ai-inference", "dashscope", "google-genai", "ollama"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black
args: ["--config=./pyproject.toml"]
Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def load_specified_adapter(driver: Driver, adapter: str):
try:
module = importlib.import_module(adapter)
adapter = module.Adapter
driver.register_adapter(adapter) # type:ignore
driver.register_adapter(adapter) # type: ignore
except ImportError:
print(f"\33[35m{adapter}不存在,请检查拼写错误或是否已安装该适配器?")
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion muicebot/llm/embeddings/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def embed(self, texts: list[str]) -> EmbeddingsBatchResult:
"""
查询文本嵌入
"""
result = await self.client.aio.models.embed_content(model=self.model, contents=texts) # type:ignore
result = await self.client.aio.models.embed_content(model=self.model, contents=texts) # type: ignore

if not result.embeddings:
raise RuntimeError("Gemini 嵌入查询无返回!")
Expand Down
6 changes: 3 additions & 3 deletions muicebot/llm/providers/dashscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ async def _tool_calls_handle_sync(
messages.append(response.output.choices[0].message)
messages.append({"role": "tool", "content": function_return, "tool_call_id": tool_call_id})

return await self._ask(messages, tools, response_format, total_tokens) # type:ignore
return await self._ask(messages, tools, response_format, total_tokens) # type: ignore

async def _tool_calls_handle_stream(
self,
Expand All @@ -296,7 +296,7 @@ async def _tool_calls_handle_stream(
"""
function_args = json.loads(func_stream.function_args)

function_return = await function_call_handler(func_stream.function_name, function_args) # type:ignore
function_return = await function_call_handler(func_stream.function_name, function_args) # type: ignore

messages.append(
{
Expand All @@ -317,7 +317,7 @@ async def _tool_calls_handle_stream(
)
messages.append({"role": "tool", "content": function_return, "tool_call_id": func_stream.id})

return await self._ask(messages, tools, response_format, total_tokens) # type:ignore
return await self._ask(messages, tools, response_format, total_tokens) # type: ignore

async def _ask(
self,
Expand Down
16 changes: 8 additions & 8 deletions muicebot/llm/providers/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _build_gemini_config(
tool["parameters"]["required"] = required_parameters
format_tools.append(tool)

function_tools = Tool(function_declarations=format_tools) # type:ignore
function_tools = Tool(function_declarations=format_tools) # type: ignore

if self.enable_search:
function_tools.google_search = GoogleSearch()
Expand All @@ -123,7 +123,7 @@ def _build_user_parts(self, request: ModelRequest) -> list[Part]:
if resource.type == "image" and resource.path is not None:
user_parts.append(
Part.from_bytes(
data=get_file_base64(resource.path), mime_type=resource.mimetype or "image/jpeg" # type:ignore
data=get_file_base64(resource.path), mime_type=resource.mimetype or "image/jpeg" # type: ignore
)
)

Expand Down Expand Up @@ -157,8 +157,8 @@ async def _ask_sync(

try:
chat = self.client.aio.chats.create(model=self.model_name, config=gemini_config, history=messages[:-1])
message = messages[-1].parts # type:ignore
response = await chat.send_message(message=message) # type:ignore
message = messages[-1].parts # type: ignore
response = await chat.send_message(message=message) # type: ignore
if response.usage_metadata:
total_token_count = response.usage_metadata.total_token_count
total_tokens += total_token_count if total_token_count else 0
Expand All @@ -182,10 +182,10 @@ async def _ask_sync(
function_name = function_call.name
function_args = function_call.args

function_return = await function_call_handler(function_name, function_args) # type:ignore
function_return = await function_call_handler(function_name, function_args) # type: ignore

function_response_part = Part.from_function_response(
name=function_name, # type:ignore
name=function_name, # type: ignore
response={"result": function_return},
)

Expand Down Expand Up @@ -254,10 +254,10 @@ async def _ask_stream(
function_name = function_call.name
function_args = function_call.args

function_return = await function_call_handler(function_name, function_args) # type:ignore
function_return = await function_call_handler(function_name, function_args) # type: ignore

function_response_part = Part.from_function_response(
name=function_name, # type:ignore
name=function_name, # type: ignore
response={"result": function_return},
)

Expand Down
4 changes: 2 additions & 2 deletions muicebot/llm/providers/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ async def _ask_stream(
if not tool_calls:
continue

for tool in tool_calls: # type:ignore
for tool in tool_calls: # type: ignore
function_name = tool.function.name
function_args = tool.function.arguments

function_return = await function_call_handler(function_name, dict(function_args))

messages.append(chunk.message) # type:ignore
messages.append(chunk.message) # type: ignore
messages.append({"role": "tool", "content": str(function_return), "name": tool.function.name})

async for content in self._ask_stream(messages, tools, response_format):
Expand Down
28 changes: 13 additions & 15 deletions muicebot/llm/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, model_config: ModelConfig) -> None:
self.max_tokens = self.config.max_tokens
self.temperature = self.config.temperature
self.stream = self.config.stream
self.modalities = [m for m in self.config.modalities if m in {"text", "audio"}] or NOT_GIVEN # type:ignore
self.modalities = [m for m in self.config.modalities if m in {"text", "audio"}] or NOT_GIVEN # type: ignore
self.audio = self.config.audio if (self.modalities and self.config.audio) else NOT_GIVEN
self.extra_body = self.config.extra_body

Expand Down Expand Up @@ -148,20 +148,20 @@ async def _ask_sync(
logger.debug(f"OpenAI response: id={response.id}, choices={response.choices}, usage={response.usage}")

result = ""
message = response.choices[0].message # type:ignore
message = response.choices[0].message # type: ignore
total_tokens += response.usage.total_tokens if response.usage else 0

if (
hasattr(message, "reasoning_content") # type:ignore
and message.reasoning_content # type:ignore
hasattr(message, "reasoning_content") # type: ignore
and message.reasoning_content # type: ignore
):
result += f"<think>{message.reasoning_content}</think>" # type:ignore
result += f"<think>{message.reasoning_content}</think>" # type: ignore

if response.choices[0].finish_reason == "tool_calls" and self._tool_call_request_precheck(
response.choices[0].message
):
messages.append(response.choices[0].message)
tool_call = response.choices[0].message.tool_calls[0] # type:ignore
tool_call = response.choices[0].message.tool_calls[0] # type: ignore
arguments = json.loads(tool_call.function.arguments.replace("'", '"'))

function_return = await function_call_handler(tool_call.function.name, arguments)
Expand All @@ -176,8 +176,8 @@ async def _ask_sync(
)
return await self._ask_sync(messages, tools, response_format, total_tokens)

if message.content: # type:ignore
result += message.content # type:ignore
if message.content: # type: ignore
result += message.content # type: ignore

# 多模态消息处理(目前仅支持 audio 输出)
if response.choices[0].message.audio:
Expand Down Expand Up @@ -259,10 +259,8 @@ async def _ask_stream(
answer_content = delta.content

# 处理思维过程 reasoning_content
if (
hasattr(delta, "reasoning_content") and delta.reasoning_content # type:ignore
):
reasoning_content = chunk.choices[0].delta.reasoning_content # type:ignore
if hasattr(delta, "reasoning_content") and delta.reasoning_content: # type: ignore
reasoning_content = chunk.choices[0].delta.reasoning_content # type: ignore
stream_completions.chunk = (
reasoning_content if is_insert_think_label else "<think>" + reasoning_content
)
Expand All @@ -278,7 +276,7 @@ async def _ask_stream(

# 处理多模态消息 (audio-only) (非标准方法,可能出现问题)
if hasattr(chunk.choices[0].delta, "audio"):
audio = chunk.choices[0].delta.audio # type:ignore
audio = chunk.choices[0].delta.audio # type: ignore
if audio.get("data", None):
audio_string += audio.get("data")
stream_completions.chunk = audio.get("transcript", "")
Expand Down Expand Up @@ -366,6 +364,6 @@ async def ask(
response_format = NOT_GIVEN

if stream:
return self._ask_stream(messages, tools, response_format) # type:ignore
return self._ask_stream(messages, tools, response_format) # type: ignore

return await self._ask_sync(messages, tools, response_format) # type:ignore
return await self._ask_sync(messages, tools, response_format) # type: ignore
8 changes: 3 additions & 5 deletions muicebot/onebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,12 @@ async def handle_command_profile(

@command_model.assign("help")
async def handle_model_help():
await UniMessage(
"""Model 命令指南:
await UniMessage("""Model 命令指南:
- help: 显示此帮助信息
- load <config_name>: 加载模型配置
- reload: 重新加载模型配置文件
- list: 列出所有可用的模型配置
"""
).finish()
""").finish()


@command_reload.handle()
Expand Down Expand Up @@ -484,7 +482,7 @@ async def _extract_multi_resource(
path = await download_file(resource.url, file_name=_get_media_filename(resource, type))
elif resource.origin is not None:
logger.warning("无法通过通用方式获取文件URL,回退至适配器自有方式...")
path = await get_file_via_adapter(resource.origin, event) # type:ignore
path = await get_file_via_adapter(resource.origin, event) # type: ignore
else:
continue

Expand Down
2 changes: 1 addition & 1 deletion muicebot/plugin/func_call/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __call__(self, func: F) -> F:
if is_coroutine_callable(func):
self.function = func # type: ignore
else:
self.function = async_wrap(func) # type:ignore
self.function = async_wrap(func) # type: ignore

self._name = func.__name__

Expand Down
2 changes: 1 addition & 1 deletion muicebot/plugin/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _get_caller_plugin_name() -> Optional[str]:

# find plugin
frame = current_frame
while frame := frame.f_back: # type:ignore
while frame := frame.f_back: # type: ignore
module_name = (module := inspect.getmodule(frame)) and module.__name__

if module_name is None:
Expand Down
Loading