mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-11 13:59:04 +08:00
Fix/typos (#2308)
This commit is contained in:
parent
9e37702d24
commit
2660fbaa20
@ -170,7 +170,7 @@ class AssistantApplicationRunner(AppRunner):
|
||||
# load tool variables
|
||||
tool_conversation_variables = self._load_tool_variables(conversation_id=conversation.id,
|
||||
user_id=application_generate_entity.user_id,
|
||||
tanent_id=application_generate_entity.tenant_id)
|
||||
tenant_id=application_generate_entity.tenant_id)
|
||||
|
||||
# convert db variables to tool variables
|
||||
tool_variables = self._convert_db_variables_to_tool_variables(tool_conversation_variables)
|
||||
@ -254,13 +254,13 @@ class AssistantApplicationRunner(AppRunner):
|
||||
agent=True
|
||||
)
|
||||
|
||||
def _load_tool_variables(self, conversation_id: str, user_id: str, tanent_id: str) -> ToolConversationVariables:
|
||||
def _load_tool_variables(self, conversation_id: str, user_id: str, tenant_id: str) -> ToolConversationVariables:
|
||||
"""
|
||||
load tool variables from database
|
||||
"""
|
||||
tool_variables: ToolConversationVariables = db.session.query(ToolConversationVariables).filter(
|
||||
ToolConversationVariables.conversation_id == conversation_id,
|
||||
ToolConversationVariables.tenant_id == tanent_id
|
||||
ToolConversationVariables.tenant_id == tenant_id
|
||||
).first()
|
||||
|
||||
if tool_variables:
|
||||
@ -271,7 +271,7 @@ class AssistantApplicationRunner(AppRunner):
|
||||
tool_variables = ToolConversationVariables(
|
||||
conversation_id=conversation_id,
|
||||
user_id=user_id,
|
||||
tenant_id=tanent_id,
|
||||
tenant_id=tenant_id,
|
||||
variables_str='[]',
|
||||
)
|
||||
db.session.add(tool_variables)
|
||||
|
@ -12,7 +12,7 @@ from models.model import MessageAgentThought, Message, MessageFile
|
||||
from models.tools import ToolConversationVariables
|
||||
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolInvokeMessageBinary, \
|
||||
ToolRuntimeVariablePool, ToolParamter
|
||||
ToolRuntimeVariablePool, ToolParameter
|
||||
from core.tools.tool.tool import Tool
|
||||
from core.tools.tool_manager import ToolManager
|
||||
from core.tools.tool_file_manager import ToolFileManager
|
||||
@ -108,9 +108,9 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
else:
|
||||
self.stream_tool_call = False
|
||||
|
||||
def _repacket_app_orchestration_config(self, app_orchestration_config: AppOrchestrationConfigEntity) -> AppOrchestrationConfigEntity:
|
||||
def _repack_app_orchestration_config(self, app_orchestration_config: AppOrchestrationConfigEntity) -> AppOrchestrationConfigEntity:
|
||||
"""
|
||||
Repacket app orchestration config
|
||||
Repack app orchestration config
|
||||
"""
|
||||
if app_orchestration_config.prompt_template.simple_prompt_template is None:
|
||||
app_orchestration_config.prompt_template.simple_prompt_template = ''
|
||||
@ -126,7 +126,7 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
if response.type == ToolInvokeMessage.MessageType.TEXT:
|
||||
result += response.message
|
||||
elif response.type == ToolInvokeMessage.MessageType.LINK:
|
||||
result += f"result link: {response.message}. please dirct user to check it."
|
||||
result += f"result link: {response.message}. please tell user to check it."
|
||||
elif response.type == ToolInvokeMessage.MessageType.IMAGE_LINK or \
|
||||
response.type == ToolInvokeMessage.MessageType.IMAGE:
|
||||
result += f"image has been created and sent to user already, you should tell user to check it now."
|
||||
@ -141,7 +141,7 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
"""
|
||||
tool_entity = ToolManager.get_tool_runtime(
|
||||
provider_type=tool.provider_type, provider_name=tool.provider_id, tool_name=tool.tool_name,
|
||||
tanent_id=self.application_generate_entity.tenant_id,
|
||||
tenant_id=self.application_generate_entity.tenant_id,
|
||||
agent_callback=self.agent_callback
|
||||
)
|
||||
tool_entity.load_variables(self.variables_pool)
|
||||
@ -185,20 +185,20 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
for parameter in parameters:
|
||||
parameter_type = 'string'
|
||||
enum = []
|
||||
if parameter.type == ToolParamter.ToolParameterType.STRING:
|
||||
if parameter.type == ToolParameter.ToolParameterType.STRING:
|
||||
parameter_type = 'string'
|
||||
elif parameter.type == ToolParamter.ToolParameterType.BOOLEAN:
|
||||
elif parameter.type == ToolParameter.ToolParameterType.BOOLEAN:
|
||||
parameter_type = 'boolean'
|
||||
elif parameter.type == ToolParamter.ToolParameterType.NUMBER:
|
||||
elif parameter.type == ToolParameter.ToolParameterType.NUMBER:
|
||||
parameter_type = 'number'
|
||||
elif parameter.type == ToolParamter.ToolParameterType.SELECT:
|
||||
elif parameter.type == ToolParameter.ToolParameterType.SELECT:
|
||||
for option in parameter.options:
|
||||
enum.append(option.value)
|
||||
parameter_type = 'string'
|
||||
else:
|
||||
raise ValueError(f"parameter type {parameter.type} is not supported")
|
||||
|
||||
if parameter.form == ToolParamter.ToolParameterForm.FORM:
|
||||
if parameter.form == ToolParameter.ToolParameterForm.FORM:
|
||||
# get tool parameter from form
|
||||
tool_parameter_config = tool.tool_parameters.get(parameter.name)
|
||||
if not tool_parameter_config:
|
||||
@ -207,7 +207,7 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
if not tool_parameter_config and parameter.required:
|
||||
raise ValueError(f"tool parameter {parameter.name} not found in tool config")
|
||||
|
||||
if parameter.type == ToolParamter.ToolParameterType.SELECT:
|
||||
if parameter.type == ToolParameter.ToolParameterType.SELECT:
|
||||
# check if tool_parameter_config in options
|
||||
options = list(map(lambda x: x.value, parameter.options))
|
||||
if tool_parameter_config not in options:
|
||||
@ -215,7 +215,7 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
|
||||
# convert tool parameter config to correct type
|
||||
try:
|
||||
if parameter.type == ToolParamter.ToolParameterType.NUMBER:
|
||||
if parameter.type == ToolParameter.ToolParameterType.NUMBER:
|
||||
# check if tool parameter is integer
|
||||
if isinstance(tool_parameter_config, int):
|
||||
tool_parameter_config = tool_parameter_config
|
||||
@ -226,11 +226,11 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
tool_parameter_config = float(tool_parameter_config)
|
||||
else:
|
||||
tool_parameter_config = int(tool_parameter_config)
|
||||
elif parameter.type == ToolParamter.ToolParameterType.BOOLEAN:
|
||||
elif parameter.type == ToolParameter.ToolParameterType.BOOLEAN:
|
||||
tool_parameter_config = bool(tool_parameter_config)
|
||||
elif parameter.type not in [ToolParamter.ToolParameterType.SELECT, ToolParamter.ToolParameterType.STRING]:
|
||||
elif parameter.type not in [ToolParameter.ToolParameterType.SELECT, ToolParameter.ToolParameterType.STRING]:
|
||||
tool_parameter_config = str(tool_parameter_config)
|
||||
elif parameter.type == ToolParamter.ToolParameterType:
|
||||
elif parameter.type == ToolParameter.ToolParameterType:
|
||||
tool_parameter_config = str(tool_parameter_config)
|
||||
except Exception as e:
|
||||
raise ValueError(f"tool parameter {parameter.name} value {tool_parameter_config} is not correct type")
|
||||
@ -238,7 +238,7 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
# save tool parameter to tool entity memory
|
||||
runtime_parameters[parameter.name] = tool_parameter_config
|
||||
|
||||
elif parameter.form == ToolParamter.ToolParameterForm.LLM:
|
||||
elif parameter.form == ToolParameter.ToolParameterForm.LLM:
|
||||
message_tool.parameters['properties'][parameter.name] = {
|
||||
"type": parameter_type,
|
||||
"description": parameter.llm_description or '',
|
||||
@ -292,20 +292,20 @@ class BaseAssistantApplicationRunner(AppRunner):
|
||||
for parameter in tool_runtime_parameters:
|
||||
parameter_type = 'string'
|
||||
enum = []
|
||||
if parameter.type == ToolParamter.ToolParameterType.STRING:
|
||||
if parameter.type == ToolParameter.ToolParameterType.STRING:
|
||||
parameter_type = 'string'
|
||||
elif parameter.type == ToolParamter.ToolParameterType.BOOLEAN:
|
||||
elif parameter.type == ToolParameter.ToolParameterType.BOOLEAN:
|
||||
parameter_type = 'boolean'
|
||||
elif parameter.type == ToolParamter.ToolParameterType.NUMBER:
|
||||
elif parameter.type == ToolParameter.ToolParameterType.NUMBER:
|
||||
parameter_type = 'number'
|
||||
elif parameter.type == ToolParamter.ToolParameterType.SELECT:
|
||||
elif parameter.type == ToolParameter.ToolParameterType.SELECT:
|
||||
for option in parameter.options:
|
||||
enum.append(option.value)
|
||||
parameter_type = 'string'
|
||||
else:
|
||||
raise ValueError(f"parameter type {parameter.type} is not supported")
|
||||
|
||||
if parameter.form == ToolParamter.ToolParameterForm.LLM:
|
||||
if parameter.form == ToolParameter.ToolParameterForm.LLM:
|
||||
prompt_tool.parameters['properties'][parameter.name] = {
|
||||
"type": parameter_type,
|
||||
"description": parameter.llm_description or '',
|
||||
|
@ -12,7 +12,7 @@ from core.model_runtime.entities.llm_entities import LLMResult, LLMUsage, LLMRes
|
||||
from core.model_manager import ModelInstance
|
||||
|
||||
from core.tools.errors import ToolInvokeError, ToolNotFoundError, \
|
||||
ToolNotSupportedError, ToolProviderNotFoundError, ToolParamterValidationError, \
|
||||
ToolNotSupportedError, ToolProviderNotFoundError, ToolParameterValidationError, \
|
||||
ToolProviderCredentialValidationError
|
||||
|
||||
from core.features.assistant_base_runner import BaseAssistantApplicationRunner
|
||||
@ -28,7 +28,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
Run Cot agent application
|
||||
"""
|
||||
app_orchestration_config = self.app_orchestration_config
|
||||
self._repacket_app_orchestration_config(app_orchestration_config)
|
||||
self._repack_app_orchestration_config(app_orchestration_config)
|
||||
|
||||
agent_scratchpad: List[AgentScratchpadUnit] = []
|
||||
|
||||
@ -71,7 +71,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
}
|
||||
final_answer = ''
|
||||
|
||||
def increse_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage):
|
||||
def increase_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage):
|
||||
if not final_llm_usage_dict['usage']:
|
||||
final_llm_usage_dict['usage'] = usage
|
||||
else:
|
||||
@ -105,7 +105,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
self.queue_manager.publish_agent_thought(agent_thought, PublishFrom.APPLICATION_MANAGER)
|
||||
|
||||
# update prompt messages
|
||||
prompt_messages = self._originze_cot_prompt_messages(
|
||||
prompt_messages = self._organize_cot_prompt_messages(
|
||||
mode=app_orchestration_config.model_config.mode,
|
||||
prompt_messages=prompt_messages,
|
||||
tools=prompt_messages_tools,
|
||||
@ -138,7 +138,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
|
||||
# get llm usage
|
||||
if llm_result.usage:
|
||||
increse_usage(llm_usage, llm_result.usage)
|
||||
increase_usage(llm_usage, llm_result.usage)
|
||||
|
||||
# publish agent thought if it's first iteration
|
||||
if iteration_step == 1:
|
||||
@ -208,7 +208,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
try:
|
||||
tool_response = tool_instance.invoke(
|
||||
user_id=self.user_id,
|
||||
tool_paramters=tool_call_args if isinstance(tool_call_args, dict) else json.loads(tool_call_args)
|
||||
tool_parameters=tool_call_args if isinstance(tool_call_args, dict) else json.loads(tool_call_args)
|
||||
)
|
||||
# transform tool response to llm friendly response
|
||||
tool_response = self.transform_tool_invoke_messages(tool_response)
|
||||
@ -226,15 +226,15 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
|
||||
message_file_ids = [message_file.id for message_file, _ in message_files]
|
||||
except ToolProviderCredentialValidationError as e:
|
||||
error_response = f"Plese check your tool provider credentials"
|
||||
error_response = f"Please check your tool provider credentials"
|
||||
except (
|
||||
ToolNotFoundError, ToolNotSupportedError, ToolProviderNotFoundError
|
||||
) as e:
|
||||
error_response = f"there is not a tool named {tool_call_name}"
|
||||
except (
|
||||
ToolParamterValidationError
|
||||
ToolParameterValidationError
|
||||
) as e:
|
||||
error_response = f"tool paramters validation error: {e}, please check your tool paramters"
|
||||
error_response = f"tool parameters validation error: {e}, please check your tool parameters"
|
||||
except ToolInvokeError as e:
|
||||
error_response = f"tool invoke error: {e}"
|
||||
except Exception as e:
|
||||
@ -469,7 +469,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
if not next_iteration.find("{{observation}}") >= 0:
|
||||
raise ValueError("{{observation}} is required in next_iteration")
|
||||
|
||||
def _convert_strachpad_list_to_str(self, agent_scratchpad: List[AgentScratchpadUnit]) -> str:
|
||||
def _convert_scratchpad_list_to_str(self, agent_scratchpad: List[AgentScratchpadUnit]) -> str:
|
||||
"""
|
||||
convert agent scratchpad list to str
|
||||
"""
|
||||
@ -481,7 +481,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
|
||||
return result
|
||||
|
||||
def _originze_cot_prompt_messages(self, mode: Literal["completion", "chat"],
|
||||
def _organize_cot_prompt_messages(self, mode: Literal["completion", "chat"],
|
||||
prompt_messages: List[PromptMessage],
|
||||
tools: List[PromptMessageTool],
|
||||
agent_scratchpad: List[AgentScratchpadUnit],
|
||||
@ -490,7 +490,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
input: str,
|
||||
) -> List[PromptMessage]:
|
||||
"""
|
||||
originze chain of thought prompt messages, a standard prompt message is like:
|
||||
organize chain of thought prompt messages, a standard prompt message is like:
|
||||
Respond to the human as helpfully and accurately as possible.
|
||||
|
||||
{{instruction}}
|
||||
@ -528,7 +528,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
.replace("{{tools}}", tools_str) \
|
||||
.replace("{{tool_names}}", tool_names)
|
||||
|
||||
# originze prompt messages
|
||||
# organize prompt messages
|
||||
if mode == "chat":
|
||||
# override system message
|
||||
overrided = False
|
||||
@ -559,7 +559,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
||||
return prompt_messages
|
||||
elif mode == "completion":
|
||||
# parse agent scratchpad
|
||||
agent_scratchpad_str = self._convert_strachpad_list_to_str(agent_scratchpad)
|
||||
agent_scratchpad_str = self._convert_scratchpad_list_to_str(agent_scratchpad)
|
||||
# parse prompt messages
|
||||
return [UserPromptMessage(
|
||||
content=first_prompt.replace("{{instruction}}", instruction)
|
||||
|
@ -10,7 +10,7 @@ from core.model_manager import ModelInstance
|
||||
from core.application_queue_manager import PublishFrom
|
||||
|
||||
from core.tools.errors import ToolInvokeError, ToolNotFoundError, \
|
||||
ToolNotSupportedError, ToolProviderNotFoundError, ToolParamterValidationError, \
|
||||
ToolNotSupportedError, ToolProviderNotFoundError, ToolParameterValidationError, \
|
||||
ToolProviderCredentialValidationError
|
||||
|
||||
from core.features.assistant_base_runner import BaseAssistantApplicationRunner
|
||||
@ -247,7 +247,7 @@ class AssistantFunctionCallApplicationRunner(BaseAssistantApplicationRunner):
|
||||
try:
|
||||
tool_invoke_message = tool_instance.invoke(
|
||||
user_id=self.user_id,
|
||||
tool_paramters=tool_call_args,
|
||||
tool_parameters=tool_call_args,
|
||||
)
|
||||
# transform tool invoke message to get LLM friendly message
|
||||
tool_invoke_message = self.transform_tool_invoke_messages(tool_invoke_message)
|
||||
@ -272,9 +272,9 @@ class AssistantFunctionCallApplicationRunner(BaseAssistantApplicationRunner):
|
||||
) as e:
|
||||
error_response = f"there is not a tool named {tool_call_name}"
|
||||
except (
|
||||
ToolParamterValidationError
|
||||
ToolParameterValidationError
|
||||
) as e:
|
||||
error_response = f"tool paramters validation error: {e}, please check your tool paramters"
|
||||
error_response = f"tool parameters validation error: {e}, please check your tool parameters"
|
||||
except ToolInvokeError as e:
|
||||
error_response = f"tool invoke error: {e}"
|
||||
except Exception as e:
|
||||
|
@ -41,7 +41,7 @@ class OpenLLMGenerate(object):
|
||||
if not server_url:
|
||||
raise InvalidAuthenticationError('Invalid server URL')
|
||||
|
||||
defautl_llm_config = {
|
||||
default_llm_config = {
|
||||
"max_new_tokens": 128,
|
||||
"min_length": 0,
|
||||
"early_stopping": False,
|
||||
@ -75,19 +75,19 @@ class OpenLLMGenerate(object):
|
||||
}
|
||||
|
||||
if 'max_tokens' in model_parameters and type(model_parameters['max_tokens']) == int:
|
||||
defautl_llm_config['max_new_tokens'] = model_parameters['max_tokens']
|
||||
default_llm_config['max_new_tokens'] = model_parameters['max_tokens']
|
||||
|
||||
if 'temperature' in model_parameters and type(model_parameters['temperature']) == float:
|
||||
defautl_llm_config['temperature'] = model_parameters['temperature']
|
||||
default_llm_config['temperature'] = model_parameters['temperature']
|
||||
|
||||
if 'top_p' in model_parameters and type(model_parameters['top_p']) == float:
|
||||
defautl_llm_config['top_p'] = model_parameters['top_p']
|
||||
default_llm_config['top_p'] = model_parameters['top_p']
|
||||
|
||||
if 'top_k' in model_parameters and type(model_parameters['top_k']) == int:
|
||||
defautl_llm_config['top_k'] = model_parameters['top_k']
|
||||
default_llm_config['top_k'] = model_parameters['top_k']
|
||||
|
||||
if 'use_cache' in model_parameters and type(model_parameters['use_cache']) == bool:
|
||||
defautl_llm_config['use_cache'] = model_parameters['use_cache']
|
||||
default_llm_config['use_cache'] = model_parameters['use_cache']
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
@ -104,7 +104,7 @@ class OpenLLMGenerate(object):
|
||||
data = {
|
||||
'stop': stop if stop else [],
|
||||
'prompt': '\n'.join([message.content for message in prompt_messages]),
|
||||
'llm_config': defautl_llm_config,
|
||||
'llm_config': default_llm_config,
|
||||
}
|
||||
|
||||
try:
|
||||
|
@ -125,7 +125,7 @@ from openai import OpenAI
|
||||
class DallE3Tool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -135,7 +135,7 @@ class DallE3Tool(BuiltinTool):
|
||||
)
|
||||
|
||||
# prompt
|
||||
prompt = tool_paramters.get('prompt', '')
|
||||
prompt = tool_parameters.get('prompt', '')
|
||||
if not prompt:
|
||||
return self.create_text_message('Please input prompt')
|
||||
|
||||
@ -163,7 +163,7 @@ Next, we use Vectorizer.AI to convert the PNG icon generated by DallE3 into a ve
|
||||
|
||||
```python
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParamter
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
|
||||
from typing import Any, Dict, List, Union
|
||||
@ -171,20 +171,20 @@ from httpx import post
|
||||
from base64 import b64decode
|
||||
|
||||
class VectorizerTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
Tool invocation, the image variable name needs to be passed in from here, so that we can get the image from the variable pool
|
||||
"""
|
||||
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
"""
|
||||
Override the tool parameter list, we can dynamically generate the parameter list based on the actual situation in the current variable pool, so that the LLM can generate the form based on the parameter list
|
||||
"""
|
||||
|
||||
|
||||
def is_tool_avaliable(self) -> bool:
|
||||
def is_tool_available(self) -> bool:
|
||||
"""
|
||||
Whether the current tool is available, if there is no image in the current variable pool, then we don't need to display this tool, just return False here
|
||||
"""
|
||||
@ -194,7 +194,7 @@ Next, let's implement these three functions
|
||||
|
||||
```python
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParamter
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
|
||||
from typing import Any, Dict, List, Union
|
||||
@ -202,7 +202,7 @@ from httpx import post
|
||||
from base64 import b64decode
|
||||
|
||||
class VectorizerTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -214,7 +214,7 @@ class VectorizerTool(BuiltinTool):
|
||||
raise ToolProviderCredentialValidationError('Please input api key name and value')
|
||||
|
||||
# Get image_id, the definition of image_id can be found in get_runtime_parameters
|
||||
image_id = tool_paramters.get('image_id', '')
|
||||
image_id = tool_parameters.get('image_id', '')
|
||||
if not image_id:
|
||||
return self.create_text_message('Please input image id')
|
||||
|
||||
@ -241,24 +241,24 @@ class VectorizerTool(BuiltinTool):
|
||||
meta={'mime_type': 'image/svg+xml'})
|
||||
]
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
"""
|
||||
override the runtime parameters
|
||||
"""
|
||||
# Here, we override the tool parameter list, define the image_id, and set its option list to all images in the current variable pool. The configuration here is consistent with the configuration in yaml.
|
||||
return [
|
||||
ToolParamter.get_simple_instance(
|
||||
ToolParameter.get_simple_instance(
|
||||
name='image_id',
|
||||
llm_description=f'the image id that you want to vectorize, \
|
||||
and the image id should be specified in \
|
||||
{[i.name for i in self.list_default_image_variables()]}',
|
||||
type=ToolParamter.ToolParameterType.SELECT,
|
||||
type=ToolParameter.ToolParameterType.SELECT,
|
||||
required=True,
|
||||
options=[i.name for i in self.list_default_image_variables()]
|
||||
)
|
||||
]
|
||||
|
||||
def is_tool_avaliable(self) -> bool:
|
||||
def is_tool_available(self) -> bool:
|
||||
# Only when there are images in the variable pool, the LLM needs to use this tool
|
||||
return len(self.list_default_image_variables()) > 0
|
||||
```
|
||||
|
@ -146,13 +146,13 @@ from typing import Any, Dict, List, Union
|
||||
class GoogleSearchTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
query = tool_paramters['query']
|
||||
result_type = tool_paramters['result_type']
|
||||
query = tool_parameters['query']
|
||||
result_type = tool_parameters['result_type']
|
||||
api_key = self.runtime.credentials['serpapi_api_key']
|
||||
# TODO: search with serpapi
|
||||
result = SerpAPI(api_key).run(query, result_type=result_type)
|
||||
@ -163,7 +163,7 @@ class GoogleSearchTool(BuiltinTool):
|
||||
```
|
||||
|
||||
### Parameters
|
||||
The overall logic of the tool is in the `_invoke` method, this method accepts two parameters: `user_id` and `tool_paramters`, which represent the user ID and tool parameters respectively
|
||||
The overall logic of the tool is in the `_invoke` method, this method accepts two parameters: `user_id` and `tool_parameters`, which represent the user ID and tool parameters respectively
|
||||
|
||||
### Return Data
|
||||
When the tool returns, you can choose to return one message or multiple messages, here we return one message, using `create_text_message` and `create_link_message` can create a text message or a link message.
|
||||
@ -195,7 +195,7 @@ class GoogleProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"query": "test",
|
||||
"result_type": "link"
|
||||
},
|
||||
|
@ -125,7 +125,7 @@ from openai import OpenAI
|
||||
class DallE3Tool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -135,7 +135,7 @@ class DallE3Tool(BuiltinTool):
|
||||
)
|
||||
|
||||
# prompt
|
||||
prompt = tool_paramters.get('prompt', '')
|
||||
prompt = tool_parameters.get('prompt', '')
|
||||
if not prompt:
|
||||
return self.create_text_message('Please input prompt')
|
||||
|
||||
@ -163,7 +163,7 @@ class DallE3Tool(BuiltinTool):
|
||||
|
||||
```python
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParamter
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
|
||||
from typing import Any, Dict, List, Union
|
||||
@ -171,20 +171,20 @@ from httpx import post
|
||||
from base64 import b64decode
|
||||
|
||||
class VectorizerTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
工具调用,图片变量名需要从这里传递进来,从而我们就可以从变量池中获取到图片
|
||||
"""
|
||||
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
"""
|
||||
重写工具参数列表,我们可以根据当前变量池里的实际情况来动态生成参数列表,从而LLM可以根据参数列表来生成表单
|
||||
"""
|
||||
|
||||
|
||||
def is_tool_avaliable(self) -> bool:
|
||||
def is_tool_available(self) -> bool:
|
||||
"""
|
||||
当前工具是否可用,如果当前变量池中没有图片,那么我们就不需要展示这个工具,这里返回False即可
|
||||
"""
|
||||
@ -194,7 +194,7 @@ class VectorizerTool(BuiltinTool):
|
||||
|
||||
```python
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParamter
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
|
||||
from typing import Any, Dict, List, Union
|
||||
@ -202,7 +202,7 @@ from httpx import post
|
||||
from base64 import b64decode
|
||||
|
||||
class VectorizerTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -214,7 +214,7 @@ class VectorizerTool(BuiltinTool):
|
||||
raise ToolProviderCredentialValidationError('Please input api key name and value')
|
||||
|
||||
# 获取image_id,image_id的定义可以在get_runtime_parameters中找到
|
||||
image_id = tool_paramters.get('image_id', '')
|
||||
image_id = tool_parameters.get('image_id', '')
|
||||
if not image_id:
|
||||
return self.create_text_message('Please input image id')
|
||||
|
||||
@ -241,24 +241,24 @@ class VectorizerTool(BuiltinTool):
|
||||
meta={'mime_type': 'image/svg+xml'})
|
||||
]
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
"""
|
||||
override the runtime parameters
|
||||
"""
|
||||
# 这里,我们重写了工具参数列表,定义了image_id,并设置了它的选项列表为当前变量池中的所有图片,这里的配置与yaml中的配置是一致的
|
||||
return [
|
||||
ToolParamter.get_simple_instance(
|
||||
ToolParameter.get_simple_instance(
|
||||
name='image_id',
|
||||
llm_description=f'the image id that you want to vectorize, \
|
||||
and the image id should be specified in \
|
||||
{[i.name for i in self.list_default_image_variables()]}',
|
||||
type=ToolParamter.ToolParameterType.SELECT,
|
||||
type=ToolParameter.ToolParameterType.SELECT,
|
||||
required=True,
|
||||
options=[i.name for i in self.list_default_image_variables()]
|
||||
)
|
||||
]
|
||||
|
||||
def is_tool_avaliable(self) -> bool:
|
||||
def is_tool_available(self) -> bool:
|
||||
# 只有当变量池中有图片时,LLM才需要使用这个工具
|
||||
return len(self.list_default_image_variables()) > 0
|
||||
```
|
||||
|
@ -146,13 +146,13 @@ from typing import Any, Dict, List, Union
|
||||
class GoogleSearchTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
query = tool_paramters['query']
|
||||
result_type = tool_paramters['result_type']
|
||||
query = tool_parameters['query']
|
||||
result_type = tool_parameters['result_type']
|
||||
api_key = self.runtime.credentials['serpapi_api_key']
|
||||
# TODO: search with serpapi
|
||||
result = SerpAPI(api_key).run(query, result_type=result_type)
|
||||
@ -163,7 +163,7 @@ class GoogleSearchTool(BuiltinTool):
|
||||
```
|
||||
|
||||
### 参数
|
||||
工具的整体逻辑都在`_invoke`方法中,这个方法接收两个参数:`user_id`和`tool_paramters`,分别表示用户ID和工具参数
|
||||
工具的整体逻辑都在`_invoke`方法中,这个方法接收两个参数:`user_id`和`tool_parameters`,分别表示用户ID和工具参数
|
||||
|
||||
### 返回数据
|
||||
在工具返回时,你可以选择返回一个消息或者多个消息,这里我们返回一个消息,使用`create_text_message`和`create_link_message`可以创建一个文本消息或者一个链接消息。
|
||||
@ -195,7 +195,7 @@ class GoogleProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"query": "test",
|
||||
"result_type": "link"
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Dict, Optional, Any, List
|
||||
|
||||
from core.tools.entities.tool_entities import ToolProviderType, ToolParamter
|
||||
from core.tools.entities.tool_entities import ToolProviderType, ToolParameter
|
||||
|
||||
class ApiBasedToolBundle(BaseModel):
|
||||
"""
|
||||
@ -16,7 +16,7 @@ class ApiBasedToolBundle(BaseModel):
|
||||
# operation_id
|
||||
operation_id: str = None
|
||||
# parameters
|
||||
parameters: Optional[List[ToolParamter]] = None
|
||||
parameters: Optional[List[ToolParameter]] = None
|
||||
# author
|
||||
author: str
|
||||
# icon
|
||||
|
@ -88,11 +88,11 @@ class ToolInvokeMessageBinary(BaseModel):
|
||||
url: str = Field(..., description="The url of the binary")
|
||||
save_as: str = ''
|
||||
|
||||
class ToolParamterOption(BaseModel):
|
||||
class ToolParameterOption(BaseModel):
|
||||
value: str = Field(..., description="The value of the option")
|
||||
label: I18nObject = Field(..., description="The label of the option")
|
||||
|
||||
class ToolParamter(BaseModel):
|
||||
class ToolParameter(BaseModel):
|
||||
class ToolParameterType(Enum):
|
||||
STRING = "string"
|
||||
NUMBER = "number"
|
||||
@ -114,12 +114,12 @@ class ToolParamter(BaseModel):
|
||||
default: Optional[str] = None
|
||||
min: Optional[Union[float, int]] = None
|
||||
max: Optional[Union[float, int]] = None
|
||||
options: Optional[List[ToolParamterOption]] = None
|
||||
options: Optional[List[ToolParameterOption]] = None
|
||||
|
||||
@classmethod
|
||||
def get_simple_instance(cls,
|
||||
name: str, llm_description: str, type: ToolParameterType,
|
||||
required: bool, options: Optional[List[str]] = None) -> 'ToolParamter':
|
||||
required: bool, options: Optional[List[str]] = None) -> 'ToolParameter':
|
||||
"""
|
||||
get a simple tool parameter
|
||||
|
||||
@ -129,9 +129,9 @@ class ToolParamter(BaseModel):
|
||||
:param required: if the parameter is required
|
||||
:param options: the options of the parameter
|
||||
"""
|
||||
# convert options to ToolParamterOption
|
||||
# convert options to ToolParameterOption
|
||||
if options:
|
||||
options = [ToolParamterOption(value=option, label=I18nObject(en_US=option, zh_Hans=option)) for option in options]
|
||||
options = [ToolParameterOption(value=option, label=I18nObject(en_US=option, zh_Hans=option)) for option in options]
|
||||
return cls(
|
||||
name=name,
|
||||
label=I18nObject(en_US='', zh_Hans=''),
|
||||
@ -183,7 +183,7 @@ class ToolProviderCredentials(BaseModel):
|
||||
raise ValueError(f'invalid mode value {value}')
|
||||
|
||||
@staticmethod
|
||||
def defaut(value: str) -> str:
|
||||
def default(value: str) -> str:
|
||||
return ""
|
||||
|
||||
name: str = Field(..., description="The name of the credentials")
|
||||
|
@ -4,7 +4,7 @@ from typing import List, Dict, Optional
|
||||
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
from core.tools.entities.tool_entities import ToolProviderCredentials
|
||||
from core.tools.tool.tool import ToolParamter
|
||||
from core.tools.tool.tool import ToolParameter
|
||||
|
||||
class UserToolProvider(BaseModel):
|
||||
class ProviderType(Enum):
|
||||
@ -45,4 +45,4 @@ class UserTool(BaseModel):
|
||||
name: str # identifier
|
||||
label: I18nObject # label
|
||||
description: I18nObject
|
||||
parameters: Optional[List[ToolParamter]]
|
||||
parameters: Optional[List[ToolParameter]]
|
@ -4,7 +4,7 @@ class ToolProviderNotFoundError(ValueError):
|
||||
class ToolNotFoundError(ValueError):
|
||||
pass
|
||||
|
||||
class ToolParamterValidationError(ValueError):
|
||||
class ToolParameterValidationError(ValueError):
|
||||
pass
|
||||
|
||||
class ToolProviderCredentialValidationError(ValueError):
|
||||
|
@ -123,12 +123,12 @@ class ApiBasedToolProviderController(ToolProviderController):
|
||||
|
||||
return self.tools
|
||||
|
||||
def get_tools(self, user_id: str, tanent_id: str) -> List[ApiTool]:
|
||||
def get_tools(self, user_id: str, tenant_id: str) -> List[ApiTool]:
|
||||
"""
|
||||
fetch tools from database
|
||||
|
||||
:param user_id: the user id
|
||||
:param tanent_id: the tanent id
|
||||
:param tenant_id: the tenant id
|
||||
:return: the tools
|
||||
"""
|
||||
if self.tools is not None:
|
||||
@ -136,9 +136,9 @@ class ApiBasedToolProviderController(ToolProviderController):
|
||||
|
||||
tools: List[Tool] = []
|
||||
|
||||
# get tanent api providers
|
||||
# get tenant api providers
|
||||
db_providers: List[ApiToolProvider] = db.session.query(ApiToolProvider).filter(
|
||||
ApiToolProvider.tenant_id == tanent_id,
|
||||
ApiToolProvider.tenant_id == tenant_id,
|
||||
ApiToolProvider.name == self.identity.name
|
||||
).all()
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from typing import Any, Dict, List
|
||||
from core.tools.entities.tool_entities import ToolProviderType, ToolParamter, ToolParamterOption
|
||||
from core.tools.entities.tool_entities import ToolProviderType, ToolParameter, ToolParameterOption
|
||||
from core.tools.tool.tool import Tool
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
from core.tools.provider.tool_provider import ToolProviderController
|
||||
@ -71,7 +71,7 @@ class AppBasedToolProviderEntity(ToolProviderController):
|
||||
variable_name = input_form[form_type]['variable_name']
|
||||
options = input_form[form_type].get('options', [])
|
||||
if form_type == 'paragraph' or form_type == 'text-input':
|
||||
tool['parameters'].append(ToolParamter(
|
||||
tool['parameters'].append(ToolParameter(
|
||||
name=variable_name,
|
||||
label=I18nObject(
|
||||
en_US=label,
|
||||
@ -82,13 +82,13 @@ class AppBasedToolProviderEntity(ToolProviderController):
|
||||
zh_Hans=label
|
||||
),
|
||||
llm_description=label,
|
||||
form=ToolParamter.ToolParameterForm.FORM,
|
||||
type=ToolParamter.ToolParameterType.STRING,
|
||||
form=ToolParameter.ToolParameterForm.FORM,
|
||||
type=ToolParameter.ToolParameterType.STRING,
|
||||
required=required,
|
||||
default=default
|
||||
))
|
||||
elif form_type == 'select':
|
||||
tool['parameters'].append(ToolParamter(
|
||||
tool['parameters'].append(ToolParameter(
|
||||
name=variable_name,
|
||||
label=I18nObject(
|
||||
en_US=label,
|
||||
@ -99,11 +99,11 @@ class AppBasedToolProviderEntity(ToolProviderController):
|
||||
zh_Hans=label
|
||||
),
|
||||
llm_description=label,
|
||||
form=ToolParamter.ToolParameterForm.FORM,
|
||||
type=ToolParamter.ToolParameterType.SELECT,
|
||||
form=ToolParameter.ToolParameterForm.FORM,
|
||||
type=ToolParameter.ToolParameterType.SELECT,
|
||||
required=required,
|
||||
default=default,
|
||||
options=[ToolParamterOption(
|
||||
options=[ToolParameterOption(
|
||||
value=option,
|
||||
label=I18nObject(
|
||||
en_US=option,
|
||||
|
@ -13,7 +13,7 @@ class AzureDALLEProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"prompt": "cute girl, blue eyes, white hair, anime style",
|
||||
"size": "square",
|
||||
"n": 1
|
||||
|
@ -10,7 +10,7 @@ from openai import AzureOpenAI
|
||||
class DallE3Tool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -28,19 +28,19 @@ class DallE3Tool(BuiltinTool):
|
||||
}
|
||||
|
||||
# prompt
|
||||
prompt = tool_paramters.get('prompt', '')
|
||||
prompt = tool_parameters.get('prompt', '')
|
||||
if not prompt:
|
||||
return self.create_text_message('Please input prompt')
|
||||
# get size
|
||||
size = SIZE_MAPPING[tool_paramters.get('size', 'square')]
|
||||
size = SIZE_MAPPING[tool_parameters.get('size', 'square')]
|
||||
# get n
|
||||
n = tool_paramters.get('n', 1)
|
||||
n = tool_parameters.get('n', 1)
|
||||
# get quality
|
||||
quality = tool_paramters.get('quality', 'standard')
|
||||
quality = tool_parameters.get('quality', 'standard')
|
||||
if quality not in ['standard', 'hd']:
|
||||
return self.create_text_message('Invalid quality')
|
||||
# get style
|
||||
style = tool_paramters.get('style', 'vivid')
|
||||
style = tool_parameters.get('style', 'vivid')
|
||||
if style not in ['natural', 'vivid']:
|
||||
return self.create_text_message('Invalid style')
|
||||
|
||||
|
@ -16,7 +16,7 @@ class ChartProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"data": "1,3,5,7,9,2,4,6,8,10",
|
||||
},
|
||||
)
|
||||
|
@ -6,9 +6,9 @@ import io
|
||||
from typing import Any, Dict, List, Union
|
||||
|
||||
class BarChartTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
data = tool_paramters.get('data', '')
|
||||
data = tool_parameters.get('data', '')
|
||||
if not data:
|
||||
return self.create_text_message('Please input data')
|
||||
data = data.split(';')
|
||||
@ -19,7 +19,7 @@ class BarChartTool(BuiltinTool):
|
||||
else:
|
||||
data = [float(i) for i in data]
|
||||
|
||||
axis = tool_paramters.get('x_axis', None) or None
|
||||
axis = tool_parameters.get('x_axis', None) or None
|
||||
if axis:
|
||||
axis = axis.split(';')
|
||||
if len(axis) != len(data):
|
||||
|
@ -8,14 +8,14 @@ from typing import Any, Dict, List, Union
|
||||
class LinearChartTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
data = tool_paramters.get('data', '')
|
||||
data = tool_parameters.get('data', '')
|
||||
if not data:
|
||||
return self.create_text_message('Please input data')
|
||||
data = data.split(';')
|
||||
|
||||
axis = tool_paramters.get('x_axis', None) or None
|
||||
axis = tool_parameters.get('x_axis', None) or None
|
||||
if axis:
|
||||
axis = axis.split(';')
|
||||
if len(axis) != len(data):
|
||||
|
@ -8,13 +8,13 @@ from typing import Any, Dict, List, Union
|
||||
class PieChartTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
data = tool_paramters.get('data', '')
|
||||
data = tool_parameters.get('data', '')
|
||||
if not data:
|
||||
return self.create_text_message('Please input data')
|
||||
data = data.split(';')
|
||||
categories = tool_paramters.get('categories', None) or None
|
||||
categories = tool_parameters.get('categories', None) or None
|
||||
|
||||
# if all data is int, convert to int
|
||||
if all([i.isdigit() for i in data]):
|
||||
|
@ -13,7 +13,7 @@ class DALLEProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"prompt": "cute girl, blue eyes, white hair, anime style",
|
||||
"size": "small",
|
||||
"n": 1
|
||||
|
@ -10,7 +10,7 @@ from openai import OpenAI
|
||||
class DallE2Tool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -37,15 +37,15 @@ class DallE2Tool(BuiltinTool):
|
||||
}
|
||||
|
||||
# prompt
|
||||
prompt = tool_paramters.get('prompt', '')
|
||||
prompt = tool_parameters.get('prompt', '')
|
||||
if not prompt:
|
||||
return self.create_text_message('Please input prompt')
|
||||
|
||||
# get size
|
||||
size = SIZE_MAPPING[tool_paramters.get('size', 'large')]
|
||||
size = SIZE_MAPPING[tool_parameters.get('size', 'large')]
|
||||
|
||||
# get n
|
||||
n = tool_paramters.get('n', 1)
|
||||
n = tool_parameters.get('n', 1)
|
||||
|
||||
# call openapi dalle2
|
||||
response = client.images.generate(
|
||||
|
@ -10,7 +10,7 @@ from openai import OpenAI
|
||||
class DallE3Tool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -37,19 +37,19 @@ class DallE3Tool(BuiltinTool):
|
||||
}
|
||||
|
||||
# prompt
|
||||
prompt = tool_paramters.get('prompt', '')
|
||||
prompt = tool_parameters.get('prompt', '')
|
||||
if not prompt:
|
||||
return self.create_text_message('Please input prompt')
|
||||
# get size
|
||||
size = SIZE_MAPPING[tool_paramters.get('size', 'square')]
|
||||
size = SIZE_MAPPING[tool_parameters.get('size', 'square')]
|
||||
# get n
|
||||
n = tool_paramters.get('n', 1)
|
||||
n = tool_parameters.get('n', 1)
|
||||
# get quality
|
||||
quality = tool_paramters.get('quality', 'standard')
|
||||
quality = tool_parameters.get('quality', 'standard')
|
||||
if quality not in ['standard', 'hd']:
|
||||
return self.create_text_message('Invalid quality')
|
||||
# get style
|
||||
style = tool_paramters.get('style', 'vivid')
|
||||
style = tool_parameters.get('style', 'vivid')
|
||||
if style not in ['natural', 'vivid']:
|
||||
return self.create_text_message('Invalid style')
|
||||
|
||||
|
@ -6,11 +6,11 @@ from typing import Any, Dict, List, Union
|
||||
|
||||
|
||||
class GaodeRepositoriesTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
city = tool_paramters.get('city', '')
|
||||
city = tool_parameters.get('city', '')
|
||||
if not city:
|
||||
return self.create_text_message('Please tell me your city')
|
||||
|
||||
|
@ -9,12 +9,12 @@ from typing import Any, Dict, List, Union
|
||||
|
||||
|
||||
class GihubRepositoriesTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
top_n = tool_paramters.get('top_n', 5)
|
||||
query = tool_paramters.get('query', '')
|
||||
top_n = tool_parameters.get('top_n', 5)
|
||||
query = tool_parameters.get('query', '')
|
||||
if not query:
|
||||
return self.create_text_message('Please input symbol')
|
||||
|
||||
|
@ -14,7 +14,7 @@ class GoogleProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"query": "test",
|
||||
"result_type": "link"
|
||||
},
|
||||
|
@ -148,13 +148,13 @@ class SerpAPI:
|
||||
class GoogleSearchTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
query = tool_paramters['query']
|
||||
result_type = tool_paramters['result_type']
|
||||
query = tool_parameters['query']
|
||||
result_type = tool_parameters['result_type']
|
||||
api_key = self.runtime.credentials['serpapi_api_key']
|
||||
result = SerpAPI(api_key).run(query, result_type=result_type)
|
||||
if result_type == 'text':
|
||||
|
@ -14,7 +14,7 @@ class StableDiffusionProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"prompt": "cat",
|
||||
"lora": "",
|
||||
"steps": 1,
|
||||
|
@ -1,5 +1,5 @@
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParamter, ToolParamterOption
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter, ToolParameterOption
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
|
||||
@ -60,7 +60,7 @@ DRAW_TEXT_OPTIONS = {
|
||||
}
|
||||
|
||||
class StableDiffusionTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
@ -86,25 +86,25 @@ class StableDiffusionTool(BuiltinTool):
|
||||
|
||||
|
||||
# prompt
|
||||
prompt = tool_paramters.get('prompt', '')
|
||||
prompt = tool_parameters.get('prompt', '')
|
||||
if not prompt:
|
||||
return self.create_text_message('Please input prompt')
|
||||
|
||||
# get negative prompt
|
||||
negative_prompt = tool_paramters.get('negative_prompt', '')
|
||||
negative_prompt = tool_parameters.get('negative_prompt', '')
|
||||
|
||||
# get size
|
||||
width = tool_paramters.get('width', 1024)
|
||||
height = tool_paramters.get('height', 1024)
|
||||
width = tool_parameters.get('width', 1024)
|
||||
height = tool_parameters.get('height', 1024)
|
||||
|
||||
# get steps
|
||||
steps = tool_paramters.get('steps', 1)
|
||||
steps = tool_parameters.get('steps', 1)
|
||||
|
||||
# get lora
|
||||
lora = tool_paramters.get('lora', '')
|
||||
lora = tool_parameters.get('lora', '')
|
||||
|
||||
# get image id
|
||||
image_id = tool_paramters.get('image_id', '')
|
||||
image_id = tool_parameters.get('image_id', '')
|
||||
if image_id.strip():
|
||||
image_variable = self.get_default_image_variable()
|
||||
if image_variable:
|
||||
@ -212,32 +212,32 @@ class StableDiffusionTool(BuiltinTool):
|
||||
return self.create_text_message('Failed to generate image')
|
||||
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
parameters = [
|
||||
ToolParamter(name='prompt',
|
||||
ToolParameter(name='prompt',
|
||||
label=I18nObject(en_US='Prompt', zh_Hans='Prompt'),
|
||||
human_description=I18nObject(
|
||||
en_US='Image prompt, you can check the official documentation of Stable Diffusion',
|
||||
zh_Hans='图像提示词,您可以查看 Stable Diffusion 的官方文档',
|
||||
),
|
||||
type=ToolParamter.ToolParameterType.STRING,
|
||||
form=ToolParamter.ToolParameterForm.LLM,
|
||||
type=ToolParameter.ToolParameterType.STRING,
|
||||
form=ToolParameter.ToolParameterForm.LLM,
|
||||
llm_description='Image prompt of Stable Diffusion, you should describe the image you want to generate as a list of words as possible as detailed, the prompt must be written in English.',
|
||||
required=True),
|
||||
]
|
||||
if len(self.list_default_image_variables()) != 0:
|
||||
parameters.append(
|
||||
ToolParamter(name='image_id',
|
||||
ToolParameter(name='image_id',
|
||||
label=I18nObject(en_US='image_id', zh_Hans='image_id'),
|
||||
human_description=I18nObject(
|
||||
en_US='Image id of the image you want to generate based on, if you want to generate image based on the default image, you can leave this field empty.',
|
||||
zh_Hans='您想要生成的图像的图像 ID,如果您想要基于默认图像生成图像,则可以将此字段留空。',
|
||||
),
|
||||
type=ToolParamter.ToolParameterType.STRING,
|
||||
form=ToolParamter.ToolParameterForm.LLM,
|
||||
type=ToolParameter.ToolParameterType.STRING,
|
||||
form=ToolParameter.ToolParameterForm.LLM,
|
||||
llm_description='Image id of the original image, you can leave this field empty if you want to generate a new image.',
|
||||
required=True,
|
||||
options=[ToolParamterOption(
|
||||
options=[ToolParameterOption(
|
||||
value=i.name,
|
||||
label=I18nObject(en_US=i.name, zh_Hans=i.name)
|
||||
) for i in self.list_default_image_variables()])
|
||||
|
@ -10,7 +10,7 @@ class WikiPediaProvider(BuiltinToolProviderController):
|
||||
try:
|
||||
CurrentTimeTool().invoke(
|
||||
user_id='',
|
||||
tool_paramters={},
|
||||
tool_parameters={},
|
||||
)
|
||||
except Exception as e:
|
||||
raise ToolProviderCredentialValidationError(str(e))
|
@ -8,7 +8,7 @@ from datetime import datetime, timezone
|
||||
class CurrentTimeTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
|
@ -1,5 +1,5 @@
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParamter
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
|
||||
from core.tools.provider.builtin.vectorizer.tools.test_data import VECTORIZER_ICON_PNG
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
|
||||
@ -8,21 +8,21 @@ from httpx import post
|
||||
from base64 import b64decode
|
||||
|
||||
class VectorizerTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
api_key_name = self.runtime.credentials.get('api_key_name', None)
|
||||
api_key_value = self.runtime.credentials.get('api_key_value', None)
|
||||
mode = tool_paramters.get('mode', 'test')
|
||||
mode = tool_parameters.get('mode', 'test')
|
||||
if mode == 'production':
|
||||
mode = 'preview'
|
||||
|
||||
if not api_key_name or not api_key_value:
|
||||
raise ToolProviderCredentialValidationError('Please input api key name and value')
|
||||
|
||||
image_id = tool_paramters.get('image_id', '')
|
||||
image_id = tool_parameters.get('image_id', '')
|
||||
if not image_id:
|
||||
return self.create_text_message('Please input image id')
|
||||
|
||||
@ -54,21 +54,21 @@ class VectorizerTool(BuiltinTool):
|
||||
meta={'mime_type': 'image/svg+xml'})
|
||||
]
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
"""
|
||||
override the runtime parameters
|
||||
"""
|
||||
return [
|
||||
ToolParamter.get_simple_instance(
|
||||
ToolParameter.get_simple_instance(
|
||||
name='image_id',
|
||||
llm_description=f'the image id that you want to vectorize, \
|
||||
and the image id should be specified in \
|
||||
{[i.name for i in self.list_default_image_variables()]}',
|
||||
type=ToolParamter.ToolParameterType.SELECT,
|
||||
type=ToolParameter.ToolParameterType.SELECT,
|
||||
required=True,
|
||||
options=[i.name for i in self.list_default_image_variables()]
|
||||
)
|
||||
]
|
||||
|
||||
def is_tool_avaliable(self) -> bool:
|
||||
def is_tool_available(self) -> bool:
|
||||
return len(self.list_default_image_variables()) > 0
|
@ -14,7 +14,7 @@ class VectorizerProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"mode": "test",
|
||||
"image_id": "__test_123"
|
||||
},
|
||||
|
@ -7,14 +7,14 @@ from typing import Any, Dict, List, Union
|
||||
class WebscraperTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
try:
|
||||
url = tool_paramters.get('url', '')
|
||||
user_agent = tool_paramters.get('user_agent', '')
|
||||
url = tool_parameters.get('url', '')
|
||||
user_agent = tool_parameters.get('user_agent', '')
|
||||
if not url:
|
||||
return self.create_text_message('Please input url')
|
||||
|
||||
|
@ -14,7 +14,7 @@ class WebscraperProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
'url': 'https://www.google.com',
|
||||
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
|
||||
},
|
||||
|
@ -14,12 +14,12 @@ class WikipediaInput(BaseModel):
|
||||
class WikiPediaSearchTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
query = tool_paramters.get('query', '')
|
||||
query = tool_parameters.get('query', '')
|
||||
if not query:
|
||||
return self.create_text_message('Please input query')
|
||||
|
||||
|
@ -12,7 +12,7 @@ class WikiPediaProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"query": "misaka mikoto",
|
||||
},
|
||||
)
|
||||
|
@ -11,12 +11,12 @@ class WolframAlphaTool(BuiltinTool):
|
||||
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
tool_parameters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
query = tool_paramters.get('query', '')
|
||||
query = tool_parameters.get('query', '')
|
||||
if not query:
|
||||
return self.create_text_message('Please input query')
|
||||
appid = self.runtime.credentials.get('appid', '')
|
||||
|
@ -16,7 +16,7 @@ class GoogleProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"query": "1+2+....+111",
|
||||
},
|
||||
)
|
||||
|
@ -9,23 +9,23 @@ from yfinance import download
|
||||
import pandas as pd
|
||||
|
||||
class YahooFinanceAnalyticsTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
symbol = tool_paramters.get('symbol', '')
|
||||
symbol = tool_parameters.get('symbol', '')
|
||||
if not symbol:
|
||||
return self.create_text_message('Please input symbol')
|
||||
|
||||
time_range = [None, None]
|
||||
start_date = tool_paramters.get('start_date', '')
|
||||
start_date = tool_parameters.get('start_date', '')
|
||||
if start_date:
|
||||
time_range[0] = start_date
|
||||
else:
|
||||
time_range[0] = '1800-01-01'
|
||||
|
||||
end_date = tool_paramters.get('end_date', '')
|
||||
end_date = tool_parameters.get('end_date', '')
|
||||
if end_date:
|
||||
time_range[1] = end_date
|
||||
else:
|
||||
|
@ -7,13 +7,13 @@ from requests.exceptions import HTTPError, ReadTimeout
|
||||
import yfinance
|
||||
|
||||
class YahooFinanceSearchTickerTool(BuiltinTool):
|
||||
def _invoke(self,user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self,user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
'''
|
||||
invoke tools
|
||||
'''
|
||||
|
||||
query = tool_paramters.get('symbol', '')
|
||||
query = tool_parameters.get('symbol', '')
|
||||
if not query:
|
||||
return self.create_text_message('Please input symbol')
|
||||
|
||||
|
@ -7,12 +7,12 @@ from requests.exceptions import HTTPError, ReadTimeout
|
||||
from yfinance import Ticker
|
||||
|
||||
class YahooFinanceSearchTickerTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
query = tool_paramters.get('symbol', '')
|
||||
query = tool_parameters.get('symbol', '')
|
||||
if not query:
|
||||
return self.create_text_message('Please input symbol')
|
||||
|
||||
|
@ -12,7 +12,7 @@ class YahooFinanceProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"ticker": "MSFT",
|
||||
},
|
||||
)
|
||||
|
@ -7,23 +7,23 @@ from datetime import datetime
|
||||
from googleapiclient.discovery import build
|
||||
|
||||
class YoutubeVideosAnalyticsTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
|
||||
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
channel = tool_paramters.get('channel', '')
|
||||
channel = tool_parameters.get('channel', '')
|
||||
if not channel:
|
||||
return self.create_text_message('Please input symbol')
|
||||
|
||||
time_range = [None, None]
|
||||
start_date = tool_paramters.get('start_date', '')
|
||||
start_date = tool_parameters.get('start_date', '')
|
||||
if start_date:
|
||||
time_range[0] = start_date
|
||||
else:
|
||||
time_range[0] = '1800-01-01'
|
||||
|
||||
end_date = tool_paramters.get('end_date', '')
|
||||
end_date = tool_parameters.get('end_date', '')
|
||||
if end_date:
|
||||
time_range[1] = end_date
|
||||
else:
|
||||
|
@ -12,7 +12,7 @@ class YahooFinanceProvider(BuiltinToolProviderController):
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
tool_parameters={
|
||||
"channel": "TOKYO GIRLS COLLECTION",
|
||||
"start_date": "2020-01-01",
|
||||
"end_date": "2024-12-31",
|
||||
|
@ -5,13 +5,13 @@ from os import path, listdir
|
||||
from yaml import load, FullLoader
|
||||
|
||||
from core.tools.entities.tool_entities import ToolProviderType, \
|
||||
ToolParamter, ToolProviderCredentials
|
||||
ToolParameter, ToolProviderCredentials
|
||||
from core.tools.tool.tool import Tool
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.provider.tool_provider import ToolProviderController
|
||||
from core.tools.entities.user_entities import UserToolProviderCredentials
|
||||
from core.tools.errors import ToolNotFoundError, ToolProviderNotFoundError, \
|
||||
ToolParamterValidationError, ToolProviderCredentialValidationError
|
||||
ToolParameterValidationError, ToolProviderCredentialValidationError
|
||||
|
||||
import importlib
|
||||
|
||||
@ -109,7 +109,7 @@ class BuiltinToolProviderController(ToolProviderController):
|
||||
"""
|
||||
return next(filter(lambda x: x.identity.name == tool_name, self.get_tools()), None)
|
||||
|
||||
def get_parameters(self, tool_name: str) -> List[ToolParamter]:
|
||||
def get_parameters(self, tool_name: str) -> List[ToolParameter]:
|
||||
"""
|
||||
returns the parameters of the tool
|
||||
|
||||
@ -148,62 +148,62 @@ class BuiltinToolProviderController(ToolProviderController):
|
||||
"""
|
||||
tool_parameters_schema = self.get_parameters(tool_name)
|
||||
|
||||
tool_parameters_need_to_validate: Dict[str, ToolParamter] = {}
|
||||
tool_parameters_need_to_validate: Dict[str, ToolParameter] = {}
|
||||
for parameter in tool_parameters_schema:
|
||||
tool_parameters_need_to_validate[parameter.name] = parameter
|
||||
|
||||
for parameter in tool_parameters:
|
||||
if parameter not in tool_parameters_need_to_validate:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} not found in tool {tool_name}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} not found in tool {tool_name}')
|
||||
|
||||
# check type
|
||||
parameter_schema = tool_parameters_need_to_validate[parameter]
|
||||
if parameter_schema.type == ToolParamter.ToolParameterType.STRING:
|
||||
if parameter_schema.type == ToolParameter.ToolParameterType.STRING:
|
||||
if not isinstance(tool_parameters[parameter], str):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be string')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be string')
|
||||
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.NUMBER:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.NUMBER:
|
||||
if not isinstance(tool_parameters[parameter], (int, float)):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be number')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be number')
|
||||
|
||||
if parameter_schema.min is not None and tool_parameters[parameter] < parameter_schema.min:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be greater than {parameter_schema.min}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be greater than {parameter_schema.min}')
|
||||
|
||||
if parameter_schema.max is not None and tool_parameters[parameter] > parameter_schema.max:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be less than {parameter_schema.max}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be less than {parameter_schema.max}')
|
||||
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.BOOLEAN:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.BOOLEAN:
|
||||
if not isinstance(tool_parameters[parameter], bool):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be boolean')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be boolean')
|
||||
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.SELECT:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.SELECT:
|
||||
if not isinstance(tool_parameters[parameter], str):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be string')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be string')
|
||||
|
||||
options = parameter_schema.options
|
||||
if not isinstance(options, list):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} options should be list')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} options should be list')
|
||||
|
||||
if tool_parameters[parameter] not in [x.value for x in options]:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be one of {options}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be one of {options}')
|
||||
|
||||
tool_parameters_need_to_validate.pop(parameter)
|
||||
|
||||
for parameter in tool_parameters_need_to_validate:
|
||||
parameter_schema = tool_parameters_need_to_validate[parameter]
|
||||
if parameter_schema.required:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} is required')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} is required')
|
||||
|
||||
# the parameter is not set currently, set the default value if needed
|
||||
if parameter_schema.default is not None:
|
||||
default_value = parameter_schema.default
|
||||
# parse default value into the correct type
|
||||
if parameter_schema.type == ToolParamter.ToolParameterType.STRING or \
|
||||
parameter_schema.type == ToolParamter.ToolParameterType.SELECT:
|
||||
if parameter_schema.type == ToolParameter.ToolParameterType.STRING or \
|
||||
parameter_schema.type == ToolParameter.ToolParameterType.SELECT:
|
||||
default_value = str(default_value)
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.NUMBER:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.NUMBER:
|
||||
default_value = float(default_value)
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.BOOLEAN:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.BOOLEAN:
|
||||
default_value = bool(default_value)
|
||||
|
||||
tool_parameters[parameter] = default_value
|
||||
|
@ -4,11 +4,11 @@ from typing import List, Dict, Any, Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
from core.tools.entities.tool_entities import ToolProviderType, \
|
||||
ToolProviderIdentity, ToolParamter, ToolProviderCredentials
|
||||
ToolProviderIdentity, ToolParameter, ToolProviderCredentials
|
||||
from core.tools.tool.tool import Tool
|
||||
from core.tools.entities.user_entities import UserToolProviderCredentials
|
||||
from core.tools.errors import ToolNotFoundError, \
|
||||
ToolParamterValidationError, ToolProviderCredentialValidationError
|
||||
ToolParameterValidationError, ToolProviderCredentialValidationError
|
||||
|
||||
class ToolProviderController(BaseModel, ABC):
|
||||
identity: Optional[ToolProviderIdentity] = None
|
||||
@ -50,7 +50,7 @@ class ToolProviderController(BaseModel, ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_parameters(self, tool_name: str) -> List[ToolParamter]:
|
||||
def get_parameters(self, tool_name: str) -> List[ToolParameter]:
|
||||
"""
|
||||
returns the parameters of the tool
|
||||
|
||||
@ -80,62 +80,62 @@ class ToolProviderController(BaseModel, ABC):
|
||||
"""
|
||||
tool_parameters_schema = self.get_parameters(tool_name)
|
||||
|
||||
tool_parameters_need_to_validate: Dict[str, ToolParamter] = {}
|
||||
tool_parameters_need_to_validate: Dict[str, ToolParameter] = {}
|
||||
for parameter in tool_parameters_schema:
|
||||
tool_parameters_need_to_validate[parameter.name] = parameter
|
||||
|
||||
for parameter in tool_parameters:
|
||||
if parameter not in tool_parameters_need_to_validate:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} not found in tool {tool_name}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} not found in tool {tool_name}')
|
||||
|
||||
# check type
|
||||
parameter_schema = tool_parameters_need_to_validate[parameter]
|
||||
if parameter_schema.type == ToolParamter.ToolParameterType.STRING:
|
||||
if parameter_schema.type == ToolParameter.ToolParameterType.STRING:
|
||||
if not isinstance(tool_parameters[parameter], str):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be string')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be string')
|
||||
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.NUMBER:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.NUMBER:
|
||||
if not isinstance(tool_parameters[parameter], (int, float)):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be number')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be number')
|
||||
|
||||
if parameter_schema.min is not None and tool_parameters[parameter] < parameter_schema.min:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be greater than {parameter_schema.min}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be greater than {parameter_schema.min}')
|
||||
|
||||
if parameter_schema.max is not None and tool_parameters[parameter] > parameter_schema.max:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be less than {parameter_schema.max}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be less than {parameter_schema.max}')
|
||||
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.BOOLEAN:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.BOOLEAN:
|
||||
if not isinstance(tool_parameters[parameter], bool):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be boolean')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be boolean')
|
||||
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.SELECT:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.SELECT:
|
||||
if not isinstance(tool_parameters[parameter], str):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be string')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be string')
|
||||
|
||||
options = parameter_schema.options
|
||||
if not isinstance(options, list):
|
||||
raise ToolParamterValidationError(f'parameter {parameter} options should be list')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} options should be list')
|
||||
|
||||
if tool_parameters[parameter] not in [x.value for x in options]:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} should be one of {options}')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} should be one of {options}')
|
||||
|
||||
tool_parameters_need_to_validate.pop(parameter)
|
||||
|
||||
for parameter in tool_parameters_need_to_validate:
|
||||
parameter_schema = tool_parameters_need_to_validate[parameter]
|
||||
if parameter_schema.required:
|
||||
raise ToolParamterValidationError(f'parameter {parameter} is required')
|
||||
raise ToolParameterValidationError(f'parameter {parameter} is required')
|
||||
|
||||
# the parameter is not set currently, set the default value if needed
|
||||
if parameter_schema.default is not None:
|
||||
default_value = parameter_schema.default
|
||||
# parse default value into the correct type
|
||||
if parameter_schema.type == ToolParamter.ToolParameterType.STRING or \
|
||||
parameter_schema.type == ToolParamter.ToolParameterType.SELECT:
|
||||
if parameter_schema.type == ToolParameter.ToolParameterType.STRING or \
|
||||
parameter_schema.type == ToolParameter.ToolParameterType.SELECT:
|
||||
default_value = str(default_value)
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.NUMBER:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.NUMBER:
|
||||
default_value = float(default_value)
|
||||
elif parameter_schema.type == ToolParamter.ToolParameterType.BOOLEAN:
|
||||
elif parameter_schema.type == ToolParameter.ToolParameterType.BOOLEAN:
|
||||
default_value = bool(default_value)
|
||||
|
||||
tool_parameters[parameter] = default_value
|
||||
|
@ -223,15 +223,15 @@ class ApiTool(Tool):
|
||||
|
||||
return response
|
||||
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) -> ToolInvokeMessage | List[ToolInvokeMessage]:
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> ToolInvokeMessage | List[ToolInvokeMessage]:
|
||||
"""
|
||||
invoke http request
|
||||
"""
|
||||
# assemble request
|
||||
headers = self.assembling_request(tool_paramters)
|
||||
headers = self.assembling_request(tool_parameters)
|
||||
|
||||
# do http request
|
||||
response = self.do_http_request(self.api_bundle.server_url, self.api_bundle.method, headers, tool_paramters)
|
||||
response = self.do_http_request(self.api_bundle.server_url, self.api_bundle.method, headers, tool_parameters)
|
||||
|
||||
# validate response
|
||||
response = self.validate_and_parse_response(response)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Any, Dict, List, Union
|
||||
from core.features.dataset_retrieval import DatasetRetrievalFeature
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParamter, ToolIdentity, ToolDescription
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter, ToolIdentity, ToolDescription
|
||||
from core.tools.tool.tool import Tool
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
from core.callback_handler.index_tool_callback_handler import DatasetIndexToolCallbackHandler
|
||||
@ -63,23 +63,23 @@ class DatasetRetrieverTool(Tool):
|
||||
|
||||
return tools
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
return [
|
||||
ToolParamter(name='query',
|
||||
ToolParameter(name='query',
|
||||
label=I18nObject(en_US='', zh_Hans=''),
|
||||
human_description=I18nObject(en_US='', zh_Hans=''),
|
||||
type=ToolParamter.ToolParameterType.STRING,
|
||||
form=ToolParamter.ToolParameterForm.LLM,
|
||||
type=ToolParameter.ToolParameterType.STRING,
|
||||
form=ToolParameter.ToolParameterForm.LLM,
|
||||
llm_description='Query for the dataset to be used to retrieve the dataset.',
|
||||
required=True,
|
||||
default=''),
|
||||
]
|
||||
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) -> ToolInvokeMessage | List[ToolInvokeMessage]:
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> ToolInvokeMessage | List[ToolInvokeMessage]:
|
||||
"""
|
||||
invoke dataset retriever tool
|
||||
"""
|
||||
query = tool_paramters.get('query', None)
|
||||
query = tool_parameters.get('query', None)
|
||||
if not query:
|
||||
return self.create_text_message(text='please input query')
|
||||
|
||||
|
@ -5,13 +5,13 @@ from abc import abstractmethod, ABC
|
||||
from enum import Enum
|
||||
|
||||
from core.tools.entities.tool_entities import ToolIdentity, ToolInvokeMessage,\
|
||||
ToolParamter, ToolDescription, ToolRuntimeVariablePool, ToolRuntimeVariable, ToolRuntimeImageVariable
|
||||
ToolParameter, ToolDescription, ToolRuntimeVariablePool, ToolRuntimeVariable, ToolRuntimeImageVariable
|
||||
from core.tools.tool_file_manager import ToolFileManager
|
||||
from core.callback_handler.agent_tool_callback_handler import DifyAgentCallbackHandler
|
||||
|
||||
class Tool(BaseModel, ABC):
|
||||
identity: ToolIdentity = None
|
||||
parameters: Optional[List[ToolParamter]] = None
|
||||
parameters: Optional[List[ToolParameter]] = None
|
||||
description: ToolDescription = None
|
||||
is_team_authorization: bool = False
|
||||
agent_callback: Optional[DifyAgentCallbackHandler] = None
|
||||
@ -166,22 +166,22 @@ class Tool(BaseModel, ABC):
|
||||
|
||||
return result
|
||||
|
||||
def invoke(self, user_id: str, tool_paramters: Dict[str, Any]) -> List[ToolInvokeMessage]:
|
||||
# update tool_paramters
|
||||
def invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> List[ToolInvokeMessage]:
|
||||
# update tool_parameters
|
||||
if self.runtime.runtime_parameters:
|
||||
tool_paramters.update(self.runtime.runtime_parameters)
|
||||
tool_parameters.update(self.runtime.runtime_parameters)
|
||||
|
||||
# hit callback
|
||||
if self.use_callback:
|
||||
self.agent_callback.on_tool_start(
|
||||
tool_name=self.identity.name,
|
||||
tool_inputs=tool_paramters
|
||||
tool_inputs=tool_parameters
|
||||
)
|
||||
|
||||
try:
|
||||
result = self._invoke(
|
||||
user_id=user_id,
|
||||
tool_paramters=tool_paramters,
|
||||
tool_parameters=tool_parameters,
|
||||
)
|
||||
except Exception as e:
|
||||
if self.use_callback:
|
||||
@ -195,7 +195,7 @@ class Tool(BaseModel, ABC):
|
||||
if self.use_callback:
|
||||
self.agent_callback.on_tool_end(
|
||||
tool_name=self.identity.name,
|
||||
tool_inputs=tool_paramters,
|
||||
tool_inputs=tool_parameters,
|
||||
tool_outputs=self._convert_tool_response_to_str(result)
|
||||
)
|
||||
|
||||
@ -210,7 +210,7 @@ class Tool(BaseModel, ABC):
|
||||
if response.type == ToolInvokeMessage.MessageType.TEXT:
|
||||
result += response.message
|
||||
elif response.type == ToolInvokeMessage.MessageType.LINK:
|
||||
result += f"result link: {response.message}. please dirct user to check it."
|
||||
result += f"result link: {response.message}. please tell user to check it."
|
||||
elif response.type == ToolInvokeMessage.MessageType.IMAGE_LINK or \
|
||||
response.type == ToolInvokeMessage.MessageType.IMAGE:
|
||||
result += f"image has been created and sent to user already, you should tell user to check it now."
|
||||
@ -225,7 +225,7 @@ class Tool(BaseModel, ABC):
|
||||
return result
|
||||
|
||||
@abstractmethod
|
||||
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
pass
|
||||
|
||||
def validate_credentials(self, credentials: Dict[str, Any], parameters: Dict[str, Any]) -> None:
|
||||
@ -237,7 +237,7 @@ class Tool(BaseModel, ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParamter]:
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
"""
|
||||
get the runtime parameters
|
||||
|
||||
@ -247,11 +247,11 @@ class Tool(BaseModel, ABC):
|
||||
"""
|
||||
return self.parameters
|
||||
|
||||
def is_tool_avaliable(self) -> bool:
|
||||
def is_tool_available(self) -> bool:
|
||||
"""
|
||||
check if the tool is avaliable
|
||||
check if the tool is available
|
||||
|
||||
:return: if the tool is avaliable
|
||||
:return: if the tool is available
|
||||
"""
|
||||
return True
|
||||
|
||||
|
@ -12,7 +12,7 @@ from core.tools.errors import ToolProviderNotFoundError
|
||||
from core.tools.provider.api_tool_provider import ApiBasedToolProviderController
|
||||
from core.tools.provider.app_tool_provider import AppBasedToolProviderEntity
|
||||
from core.tools.entities.user_entities import UserToolProvider
|
||||
from core.tools.utils.configration import ToolConfiguration
|
||||
from core.tools.utils.configuration import ToolConfiguration
|
||||
from core.tools.utils.encoder import serialize_base_model_dict
|
||||
from core.tools.provider.builtin._positions import BuiltinToolProviderSort
|
||||
|
||||
@ -115,7 +115,7 @@ class ToolManager:
|
||||
return tool
|
||||
|
||||
@staticmethod
|
||||
def get_tool(provider_type: str, provider_id: str, tool_name: str, tanent_id: str = None) \
|
||||
def get_tool(provider_type: str, provider_id: str, tool_name: str, tenant_id: str = None) \
|
||||
-> Union[BuiltinTool, ApiTool]:
|
||||
"""
|
||||
get the tool
|
||||
@ -129,9 +129,9 @@ class ToolManager:
|
||||
if provider_type == 'builtin':
|
||||
return ToolManager.get_builtin_tool(provider_id, tool_name)
|
||||
elif provider_type == 'api':
|
||||
if tanent_id is None:
|
||||
raise ValueError('tanent id is required for api provider')
|
||||
api_provider, _ = ToolManager.get_api_provider_controller(tanent_id, provider_id)
|
||||
if tenant_id is None:
|
||||
raise ValueError('tenant id is required for api provider')
|
||||
api_provider, _ = ToolManager.get_api_provider_controller(tenant_id, provider_id)
|
||||
return api_provider.get_tool(tool_name)
|
||||
elif provider_type == 'app':
|
||||
raise NotImplementedError('app provider not implemented')
|
||||
@ -139,7 +139,7 @@ class ToolManager:
|
||||
raise ToolProviderNotFoundError(f'provider type {provider_type} not found')
|
||||
|
||||
@staticmethod
|
||||
def get_tool_runtime(provider_type: str, provider_name: str, tool_name: str, tanent_id,
|
||||
def get_tool_runtime(provider_type: str, provider_name: str, tool_name: str, tenant_id,
|
||||
agent_callback: DifyAgentCallbackHandler = None) \
|
||||
-> Union[BuiltinTool, ApiTool]:
|
||||
"""
|
||||
@ -158,13 +158,13 @@ class ToolManager:
|
||||
provider_controller = ToolManager.get_builtin_provider(provider_name)
|
||||
if not provider_controller.need_credentials:
|
||||
return builtin_tool.fork_tool_runtime(meta={
|
||||
'tenant_id': tanent_id,
|
||||
'tenant_id': tenant_id,
|
||||
'credentials': {},
|
||||
}, agent_callback=agent_callback)
|
||||
|
||||
# get credentials
|
||||
builtin_provider: BuiltinToolProvider = db.session.query(BuiltinToolProvider).filter(
|
||||
BuiltinToolProvider.tenant_id == tanent_id,
|
||||
BuiltinToolProvider.tenant_id == tenant_id,
|
||||
BuiltinToolProvider.provider == provider_name,
|
||||
).first()
|
||||
|
||||
@ -174,28 +174,28 @@ class ToolManager:
|
||||
# decrypt the credentials
|
||||
credentials = builtin_provider.credentials
|
||||
controller = ToolManager.get_builtin_provider(provider_name)
|
||||
tool_configuration = ToolConfiguration(tenant_id=tanent_id, provider_controller=controller)
|
||||
tool_configuration = ToolConfiguration(tenant_id=tenant_id, provider_controller=controller)
|
||||
|
||||
decrypted_credentials = tool_configuration.decrypt_tool_credentials(credentials)
|
||||
|
||||
return builtin_tool.fork_tool_runtime(meta={
|
||||
'tenant_id': tanent_id,
|
||||
'tenant_id': tenant_id,
|
||||
'credentials': decrypted_credentials,
|
||||
'runtime_parameters': {}
|
||||
}, agent_callback=agent_callback)
|
||||
|
||||
elif provider_type == 'api':
|
||||
if tanent_id is None:
|
||||
raise ValueError('tanent id is required for api provider')
|
||||
if tenant_id is None:
|
||||
raise ValueError('tenant id is required for api provider')
|
||||
|
||||
api_provider, credentials = ToolManager.get_api_provider_controller(tanent_id, provider_name)
|
||||
api_provider, credentials = ToolManager.get_api_provider_controller(tenant_id, provider_name)
|
||||
|
||||
# decrypt the credentials
|
||||
tool_configuration = ToolConfiguration(tenant_id=tanent_id, provider_controller=api_provider)
|
||||
tool_configuration = ToolConfiguration(tenant_id=tenant_id, provider_controller=api_provider)
|
||||
decrypted_credentials = tool_configuration.decrypt_tool_credentials(credentials)
|
||||
|
||||
return api_provider.get_tool(tool_name).fork_tool_runtime(meta={
|
||||
'tenant_id': tanent_id,
|
||||
'tenant_id': tenant_id,
|
||||
'credentials': decrypted_credentials,
|
||||
})
|
||||
elif provider_type == 'app':
|
||||
@ -321,7 +321,7 @@ class ToolManager:
|
||||
schema = provider.get_credentials_schema()
|
||||
for name, value in schema.items():
|
||||
result_providers[provider.identity.name].team_credentials[name] = \
|
||||
ToolProviderCredentials.CredentialsType.defaut(value.type)
|
||||
ToolProviderCredentials.CredentialsType.default(value.type)
|
||||
|
||||
# check if the provider need credentials
|
||||
if not provider.need_credentials:
|
||||
@ -398,7 +398,7 @@ class ToolManager:
|
||||
return BuiltinToolProviderSort.sort(list(result_providers.values()))
|
||||
|
||||
@staticmethod
|
||||
def get_api_provider_controller(tanent_id: str, provider_id: str) -> Tuple[ApiBasedToolProviderController, Dict[str, Any]]:
|
||||
def get_api_provider_controller(tenant_id: str, provider_id: str) -> Tuple[ApiBasedToolProviderController, Dict[str, Any]]:
|
||||
"""
|
||||
get the api provider
|
||||
|
||||
@ -408,7 +408,7 @@ class ToolManager:
|
||||
"""
|
||||
provider: ApiToolProvider = db.session.query(ApiToolProvider).filter(
|
||||
ApiToolProvider.id == provider_id,
|
||||
ApiToolProvider.tenant_id == tanent_id,
|
||||
ApiToolProvider.tenant_id == tenant_id,
|
||||
).first()
|
||||
|
||||
if provider is None:
|
||||
@ -435,7 +435,7 @@ class ToolManager:
|
||||
).first()
|
||||
|
||||
if provider is None:
|
||||
raise ValueError(f'yout have not added provider {provider}')
|
||||
raise ValueError(f'you have not added provider {provider}')
|
||||
|
||||
try:
|
||||
credentials = json.loads(provider.credentials_str) or {}
|
||||
|
@ -17,7 +17,7 @@ class ToolConfiguration(BaseModel):
|
||||
|
||||
def encrypt_tool_credentials(self, credentials: Dict[str, str]) -> Dict[str, str]:
|
||||
"""
|
||||
encrypt tool credentials with tanent id
|
||||
encrypt tool credentials with tenant id
|
||||
|
||||
return a deep copy of credentials with encrypted values
|
||||
"""
|
||||
@ -58,7 +58,7 @@ class ToolConfiguration(BaseModel):
|
||||
|
||||
def decrypt_tool_credentials(self, credentials: Dict[str, str]) -> Dict[str, str]:
|
||||
"""
|
||||
decrypt tool credentials with tanent id
|
||||
decrypt tool credentials with tenant id
|
||||
|
||||
return a deep copy of credentials with decrypted values
|
||||
"""
|
@ -1,6 +1,6 @@
|
||||
|
||||
from core.tools.entities.tool_bundle import ApiBasedToolBundle
|
||||
from core.tools.entities.tool_entities import ToolParamter, ToolParamterOption, ApiProviderSchemaType
|
||||
from core.tools.entities.tool_entities import ToolParameter, ToolParameterOption, ApiProviderSchemaType
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
from core.tools.errors import ToolProviderNotFoundError, ToolNotSupportedError, \
|
||||
ToolApiSchemaError
|
||||
@ -47,7 +47,7 @@ class ApiBasedToolSchemaParser:
|
||||
parameters = []
|
||||
if 'parameters' in interface['operation']:
|
||||
for parameter in interface['operation']['parameters']:
|
||||
parameters.append(ToolParamter(
|
||||
parameters.append(ToolParameter(
|
||||
name=parameter['name'],
|
||||
label=I18nObject(
|
||||
en_US=parameter['name'],
|
||||
@ -57,9 +57,9 @@ class ApiBasedToolSchemaParser:
|
||||
en_US=parameter.get('description', ''),
|
||||
zh_Hans=parameter.get('description', '')
|
||||
),
|
||||
type=ToolParamter.ToolParameterType.STRING,
|
||||
type=ToolParameter.ToolParameterType.STRING,
|
||||
required=parameter.get('required', False),
|
||||
form=ToolParamter.ToolParameterForm.LLM,
|
||||
form=ToolParameter.ToolParameterForm.LLM,
|
||||
llm_description=parameter.get('description'),
|
||||
default=parameter['default'] if 'default' in parameter else None,
|
||||
))
|
||||
@ -87,7 +87,7 @@ class ApiBasedToolSchemaParser:
|
||||
required = body_schema['required'] if 'required' in body_schema else []
|
||||
properties = body_schema['properties'] if 'properties' in body_schema else {}
|
||||
for name, property in properties.items():
|
||||
parameters.append(ToolParamter(
|
||||
parameters.append(ToolParameter(
|
||||
name=name,
|
||||
label=I18nObject(
|
||||
en_US=name,
|
||||
@ -97,9 +97,9 @@ class ApiBasedToolSchemaParser:
|
||||
en_US=property['description'] if 'description' in property else '',
|
||||
zh_Hans=property['description'] if 'description' in property else ''
|
||||
),
|
||||
type=ToolParamter.ToolParameterType.STRING,
|
||||
type=ToolParameter.ToolParameterType.STRING,
|
||||
required=name in required,
|
||||
form=ToolParamter.ToolParameterForm.LLM,
|
||||
form=ToolParameter.ToolParameterForm.LLM,
|
||||
llm_description=property['description'] if 'description' in property else '',
|
||||
default=property['default'] if 'default' in property else None,
|
||||
))
|
||||
|
@ -100,7 +100,7 @@ class ApiToolProvider(db.Model):
|
||||
schema_type_str = db.Column(db.String(40), nullable=False)
|
||||
# who created this tool
|
||||
user_id = db.Column(UUID, nullable=False)
|
||||
# tanent id
|
||||
# tenant id
|
||||
tenant_id = db.Column(UUID, nullable=False)
|
||||
# description of the provider
|
||||
description = db.Column(db.Text, nullable=False)
|
||||
@ -135,7 +135,7 @@ class ApiToolProvider(db.Model):
|
||||
return db.session.query(Account).filter(Account.id == self.user_id).first()
|
||||
|
||||
@property
|
||||
def tanent(self) -> Tenant:
|
||||
def tenant(self) -> Tenant:
|
||||
return db.session.query(Tenant).filter(Tenant.id == self.tenant_id).first()
|
||||
|
||||
class ToolModelInvoke(db.Model):
|
||||
@ -150,7 +150,7 @@ class ToolModelInvoke(db.Model):
|
||||
id = db.Column(UUID, server_default=db.text('uuid_generate_v4()'))
|
||||
# who invoke this tool
|
||||
user_id = db.Column(UUID, nullable=False)
|
||||
# tanent id
|
||||
# tenant id
|
||||
tenant_id = db.Column(UUID, nullable=False)
|
||||
# provider
|
||||
provider = db.Column(db.String(40), nullable=False)
|
||||
@ -190,7 +190,7 @@ class ToolConversationVariables(db.Model):
|
||||
id = db.Column(UUID, server_default=db.text('uuid_generate_v4()'))
|
||||
# conversation user id
|
||||
user_id = db.Column(UUID, nullable=False)
|
||||
# tanent id
|
||||
# tenant id
|
||||
tenant_id = db.Column(UUID, nullable=False)
|
||||
# conversation id
|
||||
conversation_id = db.Column(UUID, nullable=False)
|
||||
@ -218,7 +218,7 @@ class ToolFile(db.Model):
|
||||
id = db.Column(UUID, server_default=db.text('uuid_generate_v4()'))
|
||||
# conversation user id
|
||||
user_id = db.Column(UUID, nullable=False)
|
||||
# tanent id
|
||||
# tenant id
|
||||
tenant_id = db.Column(UUID, nullable=False)
|
||||
# conversation id
|
||||
conversation_id = db.Column(UUID, nullable=False)
|
||||
|
@ -12,7 +12,7 @@ from core.tools.provider.tool_provider import ToolProviderController
|
||||
from core.tools.provider.api_tool_provider import ApiBasedToolProviderController
|
||||
from core.tools.utils.parser import ApiBasedToolSchemaParser
|
||||
from core.tools.utils.encoder import serialize_base_model_array, serialize_base_model_dict
|
||||
from core.tools.utils.configration import ToolConfiguration
|
||||
from core.tools.utils.configuration import ToolConfiguration
|
||||
from core.tools.errors import ToolProviderCredentialValidationError, ToolProviderNotFoundError, ToolNotFoundError
|
||||
|
||||
from extensions.ext_database import db
|
||||
@ -24,26 +24,26 @@ import json
|
||||
|
||||
class ToolManageService:
|
||||
@staticmethod
|
||||
def list_tool_providers(user_id: str, tanent_id: str):
|
||||
def list_tool_providers(user_id: str, tenant_id: str):
|
||||
"""
|
||||
list tool providers
|
||||
|
||||
:return: the list of tool providers
|
||||
"""
|
||||
result = [provider.to_dict() for provider in ToolManager.user_list_providers(
|
||||
user_id, tanent_id
|
||||
user_id, tenant_id
|
||||
)]
|
||||
|
||||
# add icon url prefix
|
||||
for provider in result:
|
||||
ToolManageService.repacket_provider(provider)
|
||||
ToolManageService.repack_provider(provider)
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def repacket_provider(provider: dict):
|
||||
def repack_provider(provider: dict):
|
||||
"""
|
||||
repacket provider
|
||||
repack provider
|
||||
|
||||
:param provider: the provider dict
|
||||
"""
|
||||
@ -286,7 +286,7 @@ class ToolManageService:
|
||||
).first()
|
||||
|
||||
if provider is None:
|
||||
raise ValueError(f'yout have not added provider {provider}')
|
||||
raise ValueError(f'you have not added provider {provider}')
|
||||
|
||||
return json.loads(
|
||||
serialize_base_model_array([
|
||||
@ -424,7 +424,7 @@ class ToolManageService:
|
||||
).first()
|
||||
|
||||
if provider is None:
|
||||
raise ValueError(f'yout have not added provider {provider}')
|
||||
raise ValueError(f'you have not added provider {provider}')
|
||||
|
||||
db.session.delete(provider)
|
||||
db.session.commit()
|
||||
@ -457,7 +457,7 @@ class ToolManageService:
|
||||
).first()
|
||||
|
||||
if provider is None:
|
||||
raise ValueError(f'yout have not added provider {provider}')
|
||||
raise ValueError(f'you have not added provider {provider}')
|
||||
|
||||
db.session.delete(provider)
|
||||
db.session.commit()
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""
|
||||
LocalAI Embedding Interface is temporarily unavaliable due to
|
||||
LocalAI Embedding Interface is temporarily unavailable due to
|
||||
we could not find a way to test it for now.
|
||||
"""
|
@ -9,7 +9,7 @@ const translation = {
|
||||
three: 'Execute and finish',
|
||||
},
|
||||
error: {
|
||||
unavailable: 'This Knowledge is not avaliable',
|
||||
unavailable: 'This Knowledge is not available',
|
||||
},
|
||||
stepOne: {
|
||||
filePreview: 'File Preview',
|
||||
|
Loading…
x
Reference in New Issue
Block a user