From 4bfca74c5c6fe00fba8a0e5fce27954d2dcc6111 Mon Sep 17 00:00:00 2001 From: Ricky Date: Wed, 31 Jan 2024 10:33:44 +0800 Subject: [PATCH 1/4] Fix typos --- api/core/app_runner/assistant_app_runner.py | 8 ++-- api/core/features/assistant_base_runner.py | 42 +++++++++--------- api/core/features/assistant_cot_runner.py | 28 ++++++------ api/core/features/assistant_fc_runner.py | 8 ++-- .../openllm/llm/openllm_generate.py | 14 +++--- .../tools/docs/en_US/advanced_scale_out.md | 26 +++++------ api/core/tools/docs/en_US/tool_scale_out.md | 10 ++--- .../tools/docs/zh_Hans/advanced_scale_out.md | 26 +++++------ api/core/tools/docs/zh_Hans/tool_scale_out.md | 10 ++--- api/core/tools/entities/tool_bundle.py | 4 +- api/core/tools/entities/tool_entities.py | 14 +++--- api/core/tools/entities/user_entities.py | 4 +- api/core/tools/errors.py | 2 +- api/core/tools/provider/api_tool_provider.py | 8 ++-- api/core/tools/provider/app_tool_provider.py | 16 +++---- .../provider/builtin/azuredalle/azuredalle.py | 2 +- .../builtin/azuredalle/tools/dalle3.py | 12 ++--- .../tools/provider/builtin/chart/chart.py | 2 +- .../tools/provider/builtin/chart/tools/bar.py | 6 +-- .../provider/builtin/chart/tools/line.py | 6 +-- .../tools/provider/builtin/chart/tools/pie.py | 6 +-- .../tools/provider/builtin/dalle/dalle.py | 2 +- .../provider/builtin/dalle/tools/dalle2.py | 8 ++-- .../provider/builtin/dalle/tools/dalle3.py | 12 ++--- .../builtin/gaode/tools/gaode_weather.py | 4 +- .../github/tools/github_repositories.py | 6 +-- .../tools/provider/builtin/google/google.py | 2 +- .../builtin/google/tools/google_search.py | 6 +-- .../stablediffusion/stablediffusion.py | 2 +- .../stablediffusion/tools/stable_diffusion.py | 34 +++++++------- api/core/tools/provider/builtin/time/time.py | 2 +- .../builtin/time/tools/current_time.py | 2 +- .../builtin/vectorizer/tools/vectorizer.py | 16 +++---- .../provider/builtin/vectorizer/vectorizer.py | 2 +- .../builtin/webscraper/tools/webscraper.py | 6 +-- .../provider/builtin/webscraper/webscraper.py | 2 +- .../wikipedia/tools/wikipedia_search.py | 4 +- .../provider/builtin/wikipedia/wikipedia.py | 2 +- .../wolframalpha/tools/wolframalpha.py | 4 +- .../builtin/wolframalpha/wolframalpha.py | 2 +- .../provider/builtin/yahoo/tools/analytics.py | 8 ++-- .../provider/builtin/yahoo/tools/news.py | 4 +- .../provider/builtin/yahoo/tools/ticker.py | 4 +- .../tools/provider/builtin/yahoo/yahoo.py | 2 +- .../provider/builtin/youtube/tools/videos.py | 8 ++-- .../tools/provider/builtin/youtube/youtube.py | 2 +- .../tools/provider/builtin_tool_provider.py | 44 +++++++++---------- api/core/tools/provider/tool_provider.py | 44 +++++++++---------- api/core/tools/tool/api_tool.py | 6 +-- api/core/tools/tool/dataset_retriever_tool.py | 14 +++--- api/core/tools/tool/tool.py | 28 ++++++------ api/core/tools/tool_manager.py | 38 ++++++++-------- .../{configration.py => configuration.py} | 4 +- api/core/tools/utils/parser.py | 14 +++--- api/models/tools.py | 10 ++--- api/services/tools_manage_service.py | 18 ++++---- .../model_runtime/localai/test_embedding.py | 2 +- web/i18n/lang/dataset-creation.en.ts | 2 +- 58 files changed, 312 insertions(+), 312 deletions(-) rename api/core/tools/utils/{configration.py => configuration.py} (96%) diff --git a/api/core/app_runner/assistant_app_runner.py b/api/core/app_runner/assistant_app_runner.py index b3cbeaf81c321..1bb1b246a9337 100644 --- a/api/core/app_runner/assistant_app_runner.py +++ b/api/core/app_runner/assistant_app_runner.py @@ -170,7 +170,7 @@ def run(self, application_generate_entity: ApplicationGenerateEntity, # 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 @@ def run(self, application_generate_entity: ApplicationGenerateEntity, 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 @@ def _load_tool_variables(self, conversation_id: str, user_id: str, tanent_id: st 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) diff --git a/api/core/features/assistant_base_runner.py b/api/core/features/assistant_base_runner.py index 8919033a1e69d..e9ee59263c163 100644 --- a/api/core/features/assistant_base_runner.py +++ b/api/core/features/assistant_base_runner.py @@ -12,7 +12,7 @@ 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 @@ def __init__(self, tenant_id: str, 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 @@ def _convert_tool_response_to_str(self, tool_response: List[ToolInvokeMessage]) 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 @@ def _convert_tool_to_prompt_message_tool(self, tool: AgentToolEntity) -> Tuple[P """ 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 @@ def _convert_tool_to_prompt_message_tool(self, tool: AgentToolEntity) -> Tuple[P 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 @@ def _convert_tool_to_prompt_message_tool(self, tool: AgentToolEntity) -> Tuple[P 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 @@ def _convert_tool_to_prompt_message_tool(self, tool: AgentToolEntity) -> Tuple[P # 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 @@ def _convert_tool_to_prompt_message_tool(self, tool: AgentToolEntity) -> Tuple[P 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 @@ def _convert_tool_to_prompt_message_tool(self, tool: AgentToolEntity) -> Tuple[P # 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 @@ def update_prompt_message_tool(self, tool: Tool, prompt_tool: PromptMessageTool) 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 '', diff --git a/api/core/features/assistant_cot_runner.py b/api/core/features/assistant_cot_runner.py index c7aec6965cd71..f07af0e694e33 100644 --- a/api/core/features/assistant_cot_runner.py +++ b/api/core/features/assistant_cot_runner.py @@ -12,7 +12,7 @@ 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 @@ def run(self, conversation: Conversation, 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 @@ def run(self, conversation: Conversation, } 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 @@ def increse_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage): 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 @@ def increse_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage): # 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 @@ def increse_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage): 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 @@ def increse_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage): 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 @@ def _check_cot_prompt_messages(self, mode: Literal["completion", "chat"], 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 @@ def _convert_strachpad_list_to_str(self, agent_scratchpad: List[AgentScratchpadU 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 @@ def _originze_cot_prompt_messages(self, mode: Literal["completion", "chat"], 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 @@ def _originze_cot_prompt_messages(self, mode: Literal["completion", "chat"], .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 @@ def _originze_cot_prompt_messages(self, mode: Literal["completion", "chat"], 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) diff --git a/api/core/features/assistant_fc_runner.py b/api/core/features/assistant_fc_runner.py index c6df20dfd3b81..08c49f992199c 100644 --- a/api/core/features/assistant_fc_runner.py +++ b/api/core/features/assistant_fc_runner.py @@ -10,7 +10,7 @@ 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 @@ def increase_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage): 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 @@ def increase_usage(final_llm_usage_dict: Dict[str, LLMUsage], usage: LLMUsage): ) 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: diff --git a/api/core/model_runtime/model_providers/openllm/llm/openllm_generate.py b/api/core/model_runtime/model_providers/openllm/llm/openllm_generate.py index f14f4cd646d18..2d9a10fa2aa9f 100644 --- a/api/core/model_runtime/model_providers/openllm/llm/openllm_generate.py +++ b/api/core/model_runtime/model_providers/openllm/llm/openllm_generate.py @@ -41,7 +41,7 @@ def generate( 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 @@ def generate( } 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 @@ def generate( 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: diff --git a/api/core/tools/docs/en_US/advanced_scale_out.md b/api/core/tools/docs/en_US/advanced_scale_out.md index c6f516e1dedf4..56c8509785970 100644 --- a/api/core/tools/docs/en_US/advanced_scale_out.md +++ b/api/core/tools/docs/en_US/advanced_scale_out.md @@ -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 ``` diff --git a/api/core/tools/docs/en_US/tool_scale_out.md b/api/core/tools/docs/en_US/tool_scale_out.md index f791942397679..589a3c881091e 100644 --- a/api/core/tools/docs/en_US/tool_scale_out.md +++ b/api/core/tools/docs/en_US/tool_scale_out.md @@ -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" }, diff --git a/api/core/tools/docs/zh_Hans/advanced_scale_out.md b/api/core/tools/docs/zh_Hans/advanced_scale_out.md index 520b48d289bac..3a760e7a727c5 100644 --- a/api/core/tools/docs/zh_Hans/advanced_scale_out.md +++ b/api/core/tools/docs/zh_Hans/advanced_scale_out.md @@ -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 ``` diff --git a/api/core/tools/docs/zh_Hans/tool_scale_out.md b/api/core/tools/docs/zh_Hans/tool_scale_out.md index 034e24e784fe8..be146a5aebd15 100644 --- a/api/core/tools/docs/zh_Hans/tool_scale_out.md +++ b/api/core/tools/docs/zh_Hans/tool_scale_out.md @@ -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" }, diff --git a/api/core/tools/entities/tool_bundle.py b/api/core/tools/entities/tool_bundle.py index 51ff11b9f8231..6958ccda36c8b 100644 --- a/api/core/tools/entities/tool_bundle.py +++ b/api/core/tools/entities/tool_bundle.py @@ -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 diff --git a/api/core/tools/entities/tool_entities.py b/api/core/tools/entities/tool_entities.py index b17bce54018d1..6afc3e9615673 100644 --- a/api/core/tools/entities/tool_entities.py +++ b/api/core/tools/entities/tool_entities.py @@ -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 ToolParameterForm(Enum): 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 @@ def get_simple_instance(cls, :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 @@ def value_of(cls, value: str) -> "ToolProviderCredentials.CredentialsType": 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") diff --git a/api/core/tools/entities/user_entities.py b/api/core/tools/entities/user_entities.py index 305b6668b538e..99d02f32c1dfb 100644 --- a/api/core/tools/entities/user_entities.py +++ b/api/core/tools/entities/user_entities.py @@ -4,7 +4,7 @@ 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]] \ No newline at end of file + parameters: Optional[List[ToolParameter]] \ No newline at end of file diff --git a/api/core/tools/errors.py b/api/core/tools/errors.py index 28fc241bb07cc..d1acb073ac8db 100644 --- a/api/core/tools/errors.py +++ b/api/core/tools/errors.py @@ -4,7 +4,7 @@ class ToolProviderNotFoundError(ValueError): class ToolNotFoundError(ValueError): pass -class ToolParamterValidationError(ValueError): +class ToolParameterValidationError(ValueError): pass class ToolProviderCredentialValidationError(ValueError): diff --git a/api/core/tools/provider/api_tool_provider.py b/api/core/tools/provider/api_tool_provider.py index 1d1f09f7155c6..6472a34ddaa2c 100644 --- a/api/core/tools/provider/api_tool_provider.py +++ b/api/core/tools/provider/api_tool_provider.py @@ -123,12 +123,12 @@ def load_bundled_tools(self, tools: List[ApiBasedToolBundle]) -> List[ApiTool]: 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 @@ def get_tools(self, user_id: str, tanent_id: str) -> List[ApiTool]: 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() diff --git a/api/core/tools/provider/app_tool_provider.py b/api/core/tools/provider/app_tool_provider.py index 20f6b55731dd8..1b3e391d5320c 100644 --- a/api/core/tools/provider/app_tool_provider.py +++ b/api/core/tools/provider/app_tool_provider.py @@ -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 @@ def get_tools(self, user_id: str) -> List[Tool]: 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 @@ def get_tools(self, user_id: str) -> List[Tool]: 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 @@ def get_tools(self, user_id: str) -> List[Tool]: 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, diff --git a/api/core/tools/provider/builtin/azuredalle/azuredalle.py b/api/core/tools/provider/builtin/azuredalle/azuredalle.py index 1cef148b65dd7..e218d09efa0dd 100644 --- a/api/core/tools/provider/builtin/azuredalle/azuredalle.py +++ b/api/core/tools/provider/builtin/azuredalle/azuredalle.py @@ -13,7 +13,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "prompt": "cute girl, blue eyes, white hair, anime style", "size": "square", "n": 1 diff --git a/api/core/tools/provider/builtin/azuredalle/tools/dalle3.py b/api/core/tools/provider/builtin/azuredalle/tools/dalle3.py index e9320a82202d8..280924795786a 100644 --- a/api/core/tools/provider/builtin/azuredalle/tools/dalle3.py +++ b/api/core/tools/provider/builtin/azuredalle/tools/dalle3.py @@ -10,7 +10,7 @@ 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 @@ def _invoke(self, } # 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') diff --git a/api/core/tools/provider/builtin/chart/chart.py b/api/core/tools/provider/builtin/chart/chart.py index 53667f3099176..679c4e05cf897 100644 --- a/api/core/tools/provider/builtin/chart/chart.py +++ b/api/core/tools/provider/builtin/chart/chart.py @@ -16,7 +16,7 @@ def _validate_credentials(self, credentials: dict) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "data": "1,3,5,7,9,2,4,6,8,10", }, ) diff --git a/api/core/tools/provider/builtin/chart/tools/bar.py b/api/core/tools/provider/builtin/chart/tools/bar.py index fff60c54d6907..04034303572f4 100644 --- a/api/core/tools/provider/builtin/chart/tools/bar.py +++ b/api/core/tools/provider/builtin/chart/tools/bar.py @@ -6,9 +6,9 @@ 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 @@ def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \ 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): diff --git a/api/core/tools/provider/builtin/chart/tools/line.py b/api/core/tools/provider/builtin/chart/tools/line.py index 2b0a44250a9df..d77ab2e43d19d 100644 --- a/api/core/tools/provider/builtin/chart/tools/line.py +++ b/api/core/tools/provider/builtin/chart/tools/line.py @@ -8,14 +8,14 @@ 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): diff --git a/api/core/tools/provider/builtin/chart/tools/pie.py b/api/core/tools/provider/builtin/chart/tools/pie.py index 5fec67df11091..0635b2afb30c5 100644 --- a/api/core/tools/provider/builtin/chart/tools/pie.py +++ b/api/core/tools/provider/builtin/chart/tools/pie.py @@ -8,13 +8,13 @@ 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]): diff --git a/api/core/tools/provider/builtin/dalle/dalle.py b/api/core/tools/provider/builtin/dalle/dalle.py index b8dc0b5b82a24..26e09aaab62f6 100644 --- a/api/core/tools/provider/builtin/dalle/dalle.py +++ b/api/core/tools/provider/builtin/dalle/dalle.py @@ -13,7 +13,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "prompt": "cute girl, blue eyes, white hair, anime style", "size": "small", "n": 1 diff --git a/api/core/tools/provider/builtin/dalle/tools/dalle2.py b/api/core/tools/provider/builtin/dalle/tools/dalle2.py index 2a18e05aba6e3..a542f01796bed 100644 --- a/api/core/tools/provider/builtin/dalle/tools/dalle2.py +++ b/api/core/tools/provider/builtin/dalle/tools/dalle2.py @@ -10,7 +10,7 @@ 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 @@ def _invoke(self, } # 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( diff --git a/api/core/tools/provider/builtin/dalle/tools/dalle3.py b/api/core/tools/provider/builtin/dalle/tools/dalle3.py index 0b2d8df0eeb9e..6f75719859aab 100644 --- a/api/core/tools/provider/builtin/dalle/tools/dalle3.py +++ b/api/core/tools/provider/builtin/dalle/tools/dalle3.py @@ -10,7 +10,7 @@ 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 @@ def _invoke(self, } # 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') diff --git a/api/core/tools/provider/builtin/gaode/tools/gaode_weather.py b/api/core/tools/provider/builtin/gaode/tools/gaode_weather.py index 4147a2c56449d..dd50622394744 100644 --- a/api/core/tools/provider/builtin/gaode/tools/gaode_weather.py +++ b/api/core/tools/provider/builtin/gaode/tools/gaode_weather.py @@ -6,11 +6,11 @@ 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') diff --git a/api/core/tools/provider/builtin/github/tools/github_repositories.py b/api/core/tools/provider/builtin/github/tools/github_repositories.py index 9847b54f04c91..cb0099f6e90cb 100644 --- a/api/core/tools/provider/builtin/github/tools/github_repositories.py +++ b/api/core/tools/provider/builtin/github/tools/github_repositories.py @@ -9,12 +9,12 @@ 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') diff --git a/api/core/tools/provider/builtin/google/google.py b/api/core/tools/provider/builtin/google/google.py index 9ce52f470f01f..09a802757b9a9 100644 --- a/api/core/tools/provider/builtin/google/google.py +++ b/api/core/tools/provider/builtin/google/google.py @@ -14,7 +14,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "query": "test", "result_type": "link" }, diff --git a/api/core/tools/provider/builtin/google/tools/google_search.py b/api/core/tools/provider/builtin/google/tools/google_search.py index c902f1477cd44..cfc1508481851 100644 --- a/api/core/tools/provider/builtin/google/tools/google_search.py +++ b/api/core/tools/provider/builtin/google/tools/google_search.py @@ -148,13 +148,13 @@ def _process_response(res: dict, typ: str) -> str: 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': diff --git a/api/core/tools/provider/builtin/stablediffusion/stablediffusion.py b/api/core/tools/provider/builtin/stablediffusion/stablediffusion.py index ea18349ae6ff7..5820d0f62b9fe 100644 --- a/api/core/tools/provider/builtin/stablediffusion/stablediffusion.py +++ b/api/core/tools/provider/builtin/stablediffusion/stablediffusion.py @@ -14,7 +14,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "prompt": "cat", "lora": "", "steps": 1, diff --git a/api/core/tools/provider/builtin/stablediffusion/tools/stable_diffusion.py b/api/core/tools/provider/builtin/stablediffusion/tools/stable_diffusion.py index 7626048f9894e..1a52ba0f2f6c4 100644 --- a/api/core/tools/provider/builtin/stablediffusion/tools/stable_diffusion.py +++ b/api/core/tools/provider/builtin/stablediffusion/tools/stable_diffusion.py @@ -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 @@ } 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 @@ def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \ # 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 @@ def text2img(self, base_url: str, lora: str, prompt: str, negative_prompt: str, 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()]) diff --git a/api/core/tools/provider/builtin/time/time.py b/api/core/tools/provider/builtin/time/time.py index 24fd287d10794..e2b25238e5885 100644 --- a/api/core/tools/provider/builtin/time/time.py +++ b/api/core/tools/provider/builtin/time/time.py @@ -10,7 +10,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: try: CurrentTimeTool().invoke( user_id='', - tool_paramters={}, + tool_parameters={}, ) except Exception as e: raise ToolProviderCredentialValidationError(str(e)) \ No newline at end of file diff --git a/api/core/tools/provider/builtin/time/tools/current_time.py b/api/core/tools/provider/builtin/time/tools/current_time.py index ce380cd5bf80a..6919fb82de2fa 100644 --- a/api/core/tools/provider/builtin/time/tools/current_time.py +++ b/api/core/tools/provider/builtin/time/tools/current_time.py @@ -8,7 +8,7 @@ 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 diff --git a/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.py b/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.py index d6d70b345a603..725c596e233ad 100644 --- a/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.py +++ b/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.py @@ -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 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 @@ def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \ 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 \ No newline at end of file diff --git a/api/core/tools/provider/builtin/vectorizer/vectorizer.py b/api/core/tools/provider/builtin/vectorizer/vectorizer.py index 6abf11fbe1357..6b4edd67b89d9 100644 --- a/api/core/tools/provider/builtin/vectorizer/vectorizer.py +++ b/api/core/tools/provider/builtin/vectorizer/vectorizer.py @@ -14,7 +14,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "mode": "test", "image_id": "__test_123" }, diff --git a/api/core/tools/provider/builtin/webscraper/tools/webscraper.py b/api/core/tools/provider/builtin/webscraper/tools/webscraper.py index d646720a369b2..4d5251533b18b 100644 --- a/api/core/tools/provider/builtin/webscraper/tools/webscraper.py +++ b/api/core/tools/provider/builtin/webscraper/tools/webscraper.py @@ -7,14 +7,14 @@ 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') diff --git a/api/core/tools/provider/builtin/webscraper/webscraper.py b/api/core/tools/provider/builtin/webscraper/webscraper.py index 9cfb7ecac224e..edea0384d890e 100644 --- a/api/core/tools/provider/builtin/webscraper/webscraper.py +++ b/api/core/tools/provider/builtin/webscraper/webscraper.py @@ -14,7 +14,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: } ).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 ' }, diff --git a/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py b/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py index c2764455c61d9..6ecd4491317bc 100644 --- a/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py +++ b/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py @@ -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') diff --git a/api/core/tools/provider/builtin/wikipedia/wikipedia.py b/api/core/tools/provider/builtin/wikipedia/wikipedia.py index 11af4de739b01..d3af7d62247e7 100644 --- a/api/core/tools/provider/builtin/wikipedia/wikipedia.py +++ b/api/core/tools/provider/builtin/wikipedia/wikipedia.py @@ -12,7 +12,7 @@ def _validate_credentials(self, credentials: dict) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "query": "misaka mikoto", }, ) diff --git a/api/core/tools/provider/builtin/wolframalpha/tools/wolframalpha.py b/api/core/tools/provider/builtin/wolframalpha/tools/wolframalpha.py index 787bca32ca2c2..40075b3b8e5e0 100644 --- a/api/core/tools/provider/builtin/wolframalpha/tools/wolframalpha.py +++ b/api/core/tools/provider/builtin/wolframalpha/tools/wolframalpha.py @@ -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', '') diff --git a/api/core/tools/provider/builtin/wolframalpha/wolframalpha.py b/api/core/tools/provider/builtin/wolframalpha/wolframalpha.py index 56e3672572a1a..92938700296a3 100644 --- a/api/core/tools/provider/builtin/wolframalpha/wolframalpha.py +++ b/api/core/tools/provider/builtin/wolframalpha/wolframalpha.py @@ -16,7 +16,7 @@ def _validate_credentials(self, credentials: Dict[str, Any]) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "query": "1+2+....+111", }, ) diff --git a/api/core/tools/provider/builtin/yahoo/tools/analytics.py b/api/core/tools/provider/builtin/yahoo/tools/analytics.py index b2336f547f5fd..557ea176fd2c2 100644 --- a/api/core/tools/provider/builtin/yahoo/tools/analytics.py +++ b/api/core/tools/provider/builtin/yahoo/tools/analytics.py @@ -9,23 +9,23 @@ 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: diff --git a/api/core/tools/provider/builtin/yahoo/tools/news.py b/api/core/tools/provider/builtin/yahoo/tools/news.py index 1fd1188607e3c..6a8dec99d6ae4 100644 --- a/api/core/tools/provider/builtin/yahoo/tools/news.py +++ b/api/core/tools/provider/builtin/yahoo/tools/news.py @@ -7,13 +7,13 @@ 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') diff --git a/api/core/tools/provider/builtin/yahoo/tools/ticker.py b/api/core/tools/provider/builtin/yahoo/tools/ticker.py index 029cc7b446e40..38436195463e6 100644 --- a/api/core/tools/provider/builtin/yahoo/tools/ticker.py +++ b/api/core/tools/provider/builtin/yahoo/tools/ticker.py @@ -7,12 +7,12 @@ 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') diff --git a/api/core/tools/provider/builtin/yahoo/yahoo.py b/api/core/tools/provider/builtin/yahoo/yahoo.py index 258ee3a6cec00..4cb5d76b8b311 100644 --- a/api/core/tools/provider/builtin/yahoo/yahoo.py +++ b/api/core/tools/provider/builtin/yahoo/yahoo.py @@ -12,7 +12,7 @@ def _validate_credentials(self, credentials: dict) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "ticker": "MSFT", }, ) diff --git a/api/core/tools/provider/builtin/youtube/tools/videos.py b/api/core/tools/provider/builtin/youtube/tools/videos.py index ed48e9446319c..15415f32ce3c4 100644 --- a/api/core/tools/provider/builtin/youtube/tools/videos.py +++ b/api/core/tools/provider/builtin/youtube/tools/videos.py @@ -7,23 +7,23 @@ 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: diff --git a/api/core/tools/provider/builtin/youtube/youtube.py b/api/core/tools/provider/builtin/youtube/youtube.py index 047cfbe0e0d3c..cdca1468e6e28 100644 --- a/api/core/tools/provider/builtin/youtube/youtube.py +++ b/api/core/tools/provider/builtin/youtube/youtube.py @@ -12,7 +12,7 @@ def _validate_credentials(self, credentials: dict) -> None: } ).invoke( user_id='', - tool_paramters={ + tool_parameters={ "channel": "TOKYO GIRLS COLLECTION", "start_date": "2020-01-01", "end_date": "2024-12-31", diff --git a/api/core/tools/provider/builtin_tool_provider.py b/api/core/tools/provider/builtin_tool_provider.py index 5071ac6cf4d99..967ce6bc81cfd 100644 --- a/api/core/tools/provider/builtin_tool_provider.py +++ b/api/core/tools/provider/builtin_tool_provider.py @@ -5,13 +5,13 @@ 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 @@ def get_tool(self, tool_name: str) -> Tool: """ 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 @@ def validate_parameters(self, tool_id: int, tool_name: str, tool_parameters: Dic """ 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 diff --git a/api/core/tools/provider/tool_provider.py b/api/core/tools/provider/tool_provider.py index aa3f6661249e4..155f45d016c4a 100644 --- a/api/core/tools/provider/tool_provider.py +++ b/api/core/tools/provider/tool_provider.py @@ -4,11 +4,11 @@ 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 @@ def get_tool(self, tool_name: str) -> Tool: """ 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 @@ def validate_parameters(self, tool_id: int, tool_name: str, tool_parameters: Dic """ 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 diff --git a/api/core/tools/tool/api_tool.py b/api/core/tools/tool/api_tool.py index 442109437a1e1..4d1973b1c8c0c 100644 --- a/api/core/tools/tool/api_tool.py +++ b/api/core/tools/tool/api_tool.py @@ -223,15 +223,15 @@ def do_http_request(self, url: str, method: str, headers: Dict[str, Any], parame 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) diff --git a/api/core/tools/tool/dataset_retriever_tool.py b/api/core/tools/tool/dataset_retriever_tool.py index bcf0aa2935dae..e092bcdccd299 100644 --- a/api/core/tools/tool/dataset_retriever_tool.py +++ b/api/core/tools/tool/dataset_retriever_tool.py @@ -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 @@ def get_dataset_tools(tenant_id: str, 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') diff --git a/api/core/tools/tool/tool.py b/api/core/tools/tool/tool.py index cce6ffcc728cf..fdb25b86357b4 100644 --- a/api/core/tools/tool/tool.py +++ b/api/core/tools/tool/tool.py @@ -5,13 +5,13 @@ 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 @@ def list_default_image_variables(self) -> List[ToolRuntimeVariable]: 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 @@ def invoke(self, user_id: str, tool_paramters: Dict[str, Any]) -> List[ToolInvok 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 @@ def _convert_tool_response_to_str(self, tool_response: List[ToolInvokeMessage]) 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 @@ def _convert_tool_response_to_str(self, tool_response: List[ToolInvokeMessage]) 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 @@ def validate_credentials(self, credentials: Dict[str, Any], parameters: Dict[str """ pass - def get_runtime_parameters(self) -> List[ToolParamter]: + def get_runtime_parameters(self) -> List[ToolParameter]: """ get the runtime parameters @@ -247,11 +247,11 @@ def get_runtime_parameters(self) -> List[ToolParamter]: """ 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 diff --git a/api/core/tools/tool_manager.py b/api/core/tools/tool_manager.py index 01c79e3dd869a..0002de44782e3 100644 --- a/api/core/tools/tool_manager.py +++ b/api/core/tools/tool_manager.py @@ -12,7 +12,7 @@ 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 api.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 @@ def get_builtin_tool(provider: str, tool_name: str) -> BuiltinTool: 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 @@ def get_tool(provider_type: str, provider_id: str, tool_name: str, tanent_id: st 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 @@ def get_tool(provider_type: str, provider_id: str, tool_name: str, tanent_id: st 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 @@ def get_tool_runtime(provider_type: str, provider_name: str, tool_name: str, tan 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 @@ def get_tool_runtime(provider_type: str, provider_name: str, tool_name: str, tan # 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 @@ def user_list_providers( 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 @@ def user_list_providers( 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 @@ def get_api_provider_controller(tanent_id: str, provider_id: str) -> Tuple[ApiBa """ 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 @@ def user_get_api_provider(provider: str, tenant_id: str) -> dict: ).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 {} diff --git a/api/core/tools/utils/configration.py b/api/core/tools/utils/configuration.py similarity index 96% rename from api/core/tools/utils/configration.py rename to api/core/tools/utils/configuration.py index 29c2a53ff4aa0..47583b7cae736 100644 --- a/api/core/tools/utils/configration.py +++ b/api/core/tools/utils/configuration.py @@ -17,7 +17,7 @@ def _deep_copy(self, credentials: Dict[str, str]) -> Dict[str, str]: 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 @@ def mask_tool_credentials(self, credentials: Dict[str, Any]) -> Dict[str, Any]: 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 """ diff --git a/api/core/tools/utils/parser.py b/api/core/tools/utils/parser.py index b37ea58a42435..ec4f3237ad3d5 100644 --- a/api/core/tools/utils/parser.py +++ b/api/core/tools/utils/parser.py @@ -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 @@ def parse_openapi_to_tool_bundle(openapi: dict, extra_info: dict = None, warning 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 @@ def parse_openapi_to_tool_bundle(openapi: dict, extra_info: dict = None, warning 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 @@ def parse_openapi_to_tool_bundle(openapi: dict, extra_info: dict = None, warning 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 @@ def parse_openapi_to_tool_bundle(openapi: dict, extra_info: dict = None, warning 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, )) diff --git a/api/models/tools.py b/api/models/tools.py index 04bd662c3c800..68668e23436a2 100644 --- a/api/models/tools.py +++ b/api/models/tools.py @@ -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 @@ def user(self) -> Account: 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) diff --git a/api/services/tools_manage_service.py b/api/services/tools_manage_service.py index f541957adff43..6bb65f5fce830 100644 --- a/api/services/tools_manage_service.py +++ b/api/services/tools_manage_service.py @@ -12,7 +12,7 @@ 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 api.core.tools.utils.configuration import ToolConfiguration from core.tools.errors import ToolProviderCredentialValidationError, ToolProviderNotFoundError, ToolNotFoundError from extensions.ext_database import db @@ -24,26 +24,26 @@ 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 @@ def list_api_tool_provider_tools( ).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 @@ def delete_builtin_tool_provider( ).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 @@ def delete_api_tool_provider( ).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() diff --git a/api/tests/integration_tests/model_runtime/localai/test_embedding.py b/api/tests/integration_tests/model_runtime/localai/test_embedding.py index 5b1cdc86b9d18..e05345ee56e67 100644 --- a/api/tests/integration_tests/model_runtime/localai/test_embedding.py +++ b/api/tests/integration_tests/model_runtime/localai/test_embedding.py @@ -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. """ \ No newline at end of file diff --git a/web/i18n/lang/dataset-creation.en.ts b/web/i18n/lang/dataset-creation.en.ts index 3568b8e84e0be..4112a82e2d71b 100644 --- a/web/i18n/lang/dataset-creation.en.ts +++ b/web/i18n/lang/dataset-creation.en.ts @@ -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', From cf350cbb07c83c515507991689a9c4ea7ad74000 Mon Sep 17 00:00:00 2001 From: Ricky Date: Thu, 29 Feb 2024 17:35:50 +0800 Subject: [PATCH 2/4] reformat --- api/core/tools/entities/user_entities.py | 1 + 1 file changed, 1 insertion(+) diff --git a/api/core/tools/entities/user_entities.py b/api/core/tools/entities/user_entities.py index 6377665a3e70c..866f7dc39ab24 100644 --- a/api/core/tools/entities/user_entities.py +++ b/api/core/tools/entities/user_entities.py @@ -7,6 +7,7 @@ from core.tools.entities.tool_entities import ToolProviderCredentials from core.tools.tool.tool import ToolParameter + class UserToolProvider(BaseModel): class ProviderType(Enum): BUILTIN = "builtin" From 8e8001d5a675b4a15455df9d8415bdb18dccd93f Mon Sep 17 00:00:00 2001 From: Ricky Date: Mon, 25 Mar 2024 22:52:21 +0800 Subject: [PATCH 3/4] fix: white screen --- web/app/components/app/chat/index.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/app/components/app/chat/index.tsx b/web/app/components/app/chat/index.tsx index 0abdaab6d59de..f8be6e6e80e9d 100644 --- a/web/app/components/app/chat/index.tsx +++ b/web/app/components/app/chat/index.tsx @@ -212,16 +212,18 @@ const Chat: FC = ({ if (i === index) { return { ...item, - content: answer, annotation: { ...item.annotation, - logAnnotation: undefined, + logAnnotation: { + ...item.annotation?.logAnnotation, + content: answer, + }, } as any, } } return item })) - }, []) + }, [chatList]) const handleAnnotationAdded = useCallback((annotationId: string, authorName: string, query: string, answer: string, index: number) => { onChatListChange?.(chatList.map((item, i) => { if (i === index - 1) { @@ -251,7 +253,7 @@ const Chat: FC = ({ } return item })) - }, []) + }, [chatList]) const handleAnnotationRemoved = useCallback((index: number) => { onChatListChange?.(chatList.map((item, i) => { if (i === index) { @@ -261,12 +263,13 @@ const Chat: FC = ({ annotation: { ...(item.annotation || {}), id: '', + logAnnotation: undefined, // remove log } as Annotation, } } return item })) - }, []) + }, [chatList]) return (
From 769a2f6e2eb282ca711db5bcdd7a15e7c0566f0a Mon Sep 17 00:00:00 2001 From: Ricky Date: Mon, 25 Mar 2024 23:04:17 +0800 Subject: [PATCH 4/4] lint --- api/core/tools/entities/user_entities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/core/tools/entities/user_entities.py b/api/core/tools/entities/user_entities.py index 777b348080f01..8a5589da274f0 100644 --- a/api/core/tools/entities/user_entities.py +++ b/api/core/tools/entities/user_entities.py @@ -48,4 +48,4 @@ class UserTool(BaseModel): name: str # identifier label: I18nObject # label description: I18nObject - parameters: Optional[list[ToolParameter]] + parameters: Optional[list[ToolParameter]] \ No newline at end of file