Fix: Remove core/tools from pyrightconfig.json and fix type errors (#26413)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
parent
b6cea71023
commit
b2bcb6d21a
4 changed files with 43 additions and 36 deletions
|
|
@ -18,6 +18,10 @@ class DatasetRetrieverBaseTool(BaseModel, ABC):
|
||||||
retriever_from: str
|
retriever_from: str
|
||||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|
||||||
|
def run(self, query: str) -> str:
|
||||||
|
"""Use the tool."""
|
||||||
|
return self._run(query)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _run(self, query: str) -> str:
|
def _run(self, query: str) -> str:
|
||||||
"""Use the tool.
|
"""Use the tool.
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ class DatasetRetrieverTool(Tool):
|
||||||
yield self.create_text_message(text="please input query")
|
yield self.create_text_message(text="please input query")
|
||||||
else:
|
else:
|
||||||
# invoke dataset retriever tool
|
# invoke dataset retriever tool
|
||||||
result = self.retrieval_tool._run(query=query)
|
result = self.retrieval_tool.run(query=query)
|
||||||
yield self.create_text_message(text=result)
|
yield self.create_text_message(text=result)
|
||||||
|
|
||||||
def validate_credentials(
|
def validate_credentials(
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import re
|
||||||
from json import dumps as json_dumps
|
from json import dumps as json_dumps
|
||||||
from json import loads as json_loads
|
from json import loads as json_loads
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from requests import get
|
from requests import get
|
||||||
|
|
@ -127,34 +128,34 @@ class ApiBasedToolSchemaParser:
|
||||||
if "allOf" in prop_dict:
|
if "allOf" in prop_dict:
|
||||||
del prop_dict["allOf"]
|
del prop_dict["allOf"]
|
||||||
|
|
||||||
# parse body parameters
|
# parse body parameters
|
||||||
if "schema" in interface["operation"]["requestBody"]["content"][content_type]:
|
if "schema" in interface["operation"]["requestBody"]["content"][content_type]:
|
||||||
body_schema = interface["operation"]["requestBody"]["content"][content_type]["schema"]
|
body_schema = interface["operation"]["requestBody"]["content"][content_type]["schema"]
|
||||||
required = body_schema.get("required", [])
|
required = body_schema.get("required", [])
|
||||||
properties = body_schema.get("properties", {})
|
properties = body_schema.get("properties", {})
|
||||||
for name, property in properties.items():
|
for name, property in properties.items():
|
||||||
tool = ToolParameter(
|
tool = ToolParameter(
|
||||||
name=name,
|
name=name,
|
||||||
label=I18nObject(en_US=name, zh_Hans=name),
|
label=I18nObject(en_US=name, zh_Hans=name),
|
||||||
human_description=I18nObject(
|
human_description=I18nObject(
|
||||||
en_US=property.get("description", ""), zh_Hans=property.get("description", "")
|
en_US=property.get("description", ""), zh_Hans=property.get("description", "")
|
||||||
),
|
),
|
||||||
type=ToolParameter.ToolParameterType.STRING,
|
type=ToolParameter.ToolParameterType.STRING,
|
||||||
required=name in required,
|
required=name in required,
|
||||||
form=ToolParameter.ToolParameterForm.LLM,
|
form=ToolParameter.ToolParameterForm.LLM,
|
||||||
llm_description=property.get("description", ""),
|
llm_description=property.get("description", ""),
|
||||||
default=property.get("default", None),
|
default=property.get("default", None),
|
||||||
placeholder=I18nObject(
|
placeholder=I18nObject(
|
||||||
en_US=property.get("description", ""), zh_Hans=property.get("description", "")
|
en_US=property.get("description", ""), zh_Hans=property.get("description", "")
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# check if there is a type
|
# check if there is a type
|
||||||
typ = ApiBasedToolSchemaParser._get_tool_parameter_type(property)
|
typ = ApiBasedToolSchemaParser._get_tool_parameter_type(property)
|
||||||
if typ:
|
if typ:
|
||||||
tool.type = typ
|
tool.type = typ
|
||||||
|
|
||||||
parameters.append(tool)
|
parameters.append(tool)
|
||||||
|
|
||||||
# check if parameters is duplicated
|
# check if parameters is duplicated
|
||||||
parameters_count = {}
|
parameters_count = {}
|
||||||
|
|
@ -241,7 +242,9 @@ class ApiBasedToolSchemaParser:
|
||||||
return ApiBasedToolSchemaParser.parse_openapi_to_tool_bundle(openapi, extra_info=extra_info, warning=warning)
|
return ApiBasedToolSchemaParser.parse_openapi_to_tool_bundle(openapi, extra_info=extra_info, warning=warning)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_swagger_to_openapi(swagger: dict, extra_info: dict | None = None, warning: dict | None = None):
|
def parse_swagger_to_openapi(
|
||||||
|
swagger: dict, extra_info: dict | None = None, warning: dict | None = None
|
||||||
|
) -> dict[str, Any]:
|
||||||
warning = warning or {}
|
warning = warning or {}
|
||||||
"""
|
"""
|
||||||
parse swagger to openapi
|
parse swagger to openapi
|
||||||
|
|
@ -257,7 +260,7 @@ class ApiBasedToolSchemaParser:
|
||||||
if len(servers) == 0:
|
if len(servers) == 0:
|
||||||
raise ToolApiSchemaError("No server found in the swagger yaml.")
|
raise ToolApiSchemaError("No server found in the swagger yaml.")
|
||||||
|
|
||||||
openapi = {
|
converted_openapi: dict[str, Any] = {
|
||||||
"openapi": "3.0.0",
|
"openapi": "3.0.0",
|
||||||
"info": {
|
"info": {
|
||||||
"title": info.get("title", "Swagger"),
|
"title": info.get("title", "Swagger"),
|
||||||
|
|
@ -275,7 +278,7 @@ class ApiBasedToolSchemaParser:
|
||||||
|
|
||||||
# convert paths
|
# convert paths
|
||||||
for path, path_item in swagger["paths"].items():
|
for path, path_item in swagger["paths"].items():
|
||||||
openapi["paths"][path] = {}
|
converted_openapi["paths"][path] = {}
|
||||||
for method, operation in path_item.items():
|
for method, operation in path_item.items():
|
||||||
if "operationId" not in operation:
|
if "operationId" not in operation:
|
||||||
raise ToolApiSchemaError(f"No operationId found in operation {method} {path}.")
|
raise ToolApiSchemaError(f"No operationId found in operation {method} {path}.")
|
||||||
|
|
@ -286,7 +289,7 @@ class ApiBasedToolSchemaParser:
|
||||||
if warning is not None:
|
if warning is not None:
|
||||||
warning["missing_summary"] = f"No summary or description found in operation {method} {path}."
|
warning["missing_summary"] = f"No summary or description found in operation {method} {path}."
|
||||||
|
|
||||||
openapi["paths"][path][method] = {
|
converted_openapi["paths"][path][method] = {
|
||||||
"operationId": operation["operationId"],
|
"operationId": operation["operationId"],
|
||||||
"summary": operation.get("summary", ""),
|
"summary": operation.get("summary", ""),
|
||||||
"description": operation.get("description", ""),
|
"description": operation.get("description", ""),
|
||||||
|
|
@ -295,13 +298,14 @@ class ApiBasedToolSchemaParser:
|
||||||
}
|
}
|
||||||
|
|
||||||
if "requestBody" in operation:
|
if "requestBody" in operation:
|
||||||
openapi["paths"][path][method]["requestBody"] = operation["requestBody"]
|
converted_openapi["paths"][path][method]["requestBody"] = operation["requestBody"]
|
||||||
|
|
||||||
# convert definitions
|
# convert definitions
|
||||||
for name, definition in swagger["definitions"].items():
|
if "definitions" in swagger:
|
||||||
openapi["components"]["schemas"][name] = definition
|
for name, definition in swagger["definitions"].items():
|
||||||
|
converted_openapi["components"]["schemas"][name] = definition
|
||||||
|
|
||||||
return openapi
|
return converted_openapi
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_openai_plugin_json_to_tool_bundle(
|
def parse_openai_plugin_json_to_tool_bundle(
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
"libs",
|
"libs",
|
||||||
"controllers/console/datasets",
|
"controllers/console/datasets",
|
||||||
"core/ops",
|
"core/ops",
|
||||||
"core/tools",
|
|
||||||
"core/model_runtime",
|
"core/model_runtime",
|
||||||
"core/workflow/nodes",
|
"core/workflow/nodes",
|
||||||
"core/app/app_config/easy_ui_based_app/dataset"
|
"core/app/app_config/easy_ui_based_app/dataset"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue