mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-12 16:56:02 +00:00
style: introduce ruff as linter and formatter (#1356)
* style: remove necessary imports * style: fix F841 * style: fix F401 * style: fix F811 * style: fix E402 * style: fix E721 * style: fix E722 * style: fix E722 * style: fix F541 * style: ruff format * style: all passed * style: add ruff in deps * style: more ignores in ruff.toml * style: add pre-commit
This commit is contained in:
committed by
GitHub
parent
09e70d70e9
commit
209f16af76
@@ -1,12 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import typing
|
||||
import traceback
|
||||
|
||||
from ...core import app, entities as core_entities
|
||||
from . import entities, loader as tools_loader
|
||||
from ...plugin import context as plugin_context
|
||||
from .loaders import plugin, mcp
|
||||
from ...utils import importutil
|
||||
from . import loaders
|
||||
|
||||
importutil.import_modules_in_pkg(loaders)
|
||||
|
||||
|
||||
class ToolManager:
|
||||
@@ -22,13 +23,14 @@ class ToolManager:
|
||||
self.loaders = []
|
||||
|
||||
async def initialize(self):
|
||||
|
||||
for loader_cls in tools_loader.preregistered_loaders:
|
||||
loader_inst = loader_cls(self.ap)
|
||||
await loader_inst.initialize()
|
||||
self.loaders.append(loader_inst)
|
||||
|
||||
async def get_all_functions(self, plugin_enabled: bool=None) -> list[entities.LLMFunction]:
|
||||
async def get_all_functions(
|
||||
self, plugin_enabled: bool = None
|
||||
) -> list[entities.LLMFunction]:
|
||||
"""获取所有函数"""
|
||||
all_functions: list[entities.LLMFunction] = []
|
||||
|
||||
@@ -37,17 +39,19 @@ class ToolManager:
|
||||
|
||||
return all_functions
|
||||
|
||||
async def generate_tools_for_openai(self, use_funcs: list[entities.LLMFunction]) -> list:
|
||||
async def generate_tools_for_openai(
|
||||
self, use_funcs: list[entities.LLMFunction]
|
||||
) -> list:
|
||||
"""生成函数列表"""
|
||||
tools = []
|
||||
|
||||
for function in use_funcs:
|
||||
function_schema = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": function.name,
|
||||
"description": function.description,
|
||||
"parameters": function.parameters,
|
||||
'type': 'function',
|
||||
'function': {
|
||||
'name': function.name,
|
||||
'description': function.description,
|
||||
'parameters': function.parameters,
|
||||
},
|
||||
}
|
||||
tools.append(function_schema)
|
||||
@@ -83,9 +87,9 @@ class ToolManager:
|
||||
|
||||
for function in use_funcs:
|
||||
function_schema = {
|
||||
"name": function.name,
|
||||
"description": function.description,
|
||||
"input_schema": function.parameters,
|
||||
'name': function.name,
|
||||
'description': function.description,
|
||||
'input_schema': function.parameters,
|
||||
}
|
||||
tools.append(function_schema)
|
||||
|
||||
@@ -100,7 +104,7 @@ class ToolManager:
|
||||
if await loader.has_tool(name):
|
||||
return await loader.invoke_tool(query, name, parameters)
|
||||
else:
|
||||
raise ValueError(f"未找到工具: {name}")
|
||||
raise ValueError(f'未找到工具: {name}')
|
||||
|
||||
async def shutdown(self):
|
||||
"""关闭所有工具"""
|
||||
|
||||
Reference in New Issue
Block a user