Open breakstring opened 2 weeks ago
To resolve the issue of importing the Qdrant OpenAPI definition into the Dify tool version 0.6.11, you need to ensure that the schema is valid and correctly parsed. The ApiBasedToolSchemaParser
class provides methods to handle schema parsing and validation.
Here is a step-by-step approach to troubleshoot and resolve the issue:
Validate the Schema: Ensure that the OpenAPI schema is valid. You can use the parse_openapi_yaml_to_tool_bundle
method to validate the schema.
Check for Schema Type: Ensure that the schema type is supported. The auto_parse_to_tool_bundle
method checks if the schema type is valid.
Parse the Schema: Use the parse_openapi_to_tool_bundle
method to parse the schema into tool bundles.
Handle Errors: Catch and handle any exceptions that occur during the parsing process.
Here is a code snippet that demonstrates these steps:
from core.tools.utils.parser import ApiBasedToolSchemaParser
from core.tools.entities.tool_entities import ApiProviderSchemaType
from core.tools.errors import ToolApiSchemaError, ToolNotSupportedError, ToolProviderNotFoundError
def resolve_schema_validation_error(schema: str):
try:
# Step 1: Validate and parse the schema
extra_info = {}
warning = {}
tool_bundles, schema_type = ApiBasedToolSchemaParser.auto_parse_to_tool_bundle(schema, extra_info=extra_info, warning=warning)
# Step 2: Check for schema type (assuming 'openapi' for this example)
if schema_type != ApiProviderSchemaType.OPENAPI.value:
raise ValueError(f'Invalid schema type {schema_type}')
# Step 3: Handle the parsed tool bundles (e.g., create a provider)
# This is an example, adjust according to your actual implementation
provider_name = "Qdrant"
tenant_id = "your_tenant_id"
user_id = "your_user_id"
icon = {} # Your icon data
credentials = {"auth_type": "none"} # Your credentials
privacy_policy = "Your privacy policy"
custom_disclaimer = "Your custom disclaimer"
labels = ["label1", "label2"]
result = ApiToolManageService.create_api_tool_provider(
user_id=user_id,
tenant_id=tenant_id,
provider_name=provider_name,
icon=icon,
credentials=credentials,
schema_type=schema_type,
schema=schema,
privacy_policy=privacy_policy,
custom_disclaimer=custom_disclaimer,
labels=labels
)
return result
except (ToolApiSchemaError, ToolNotSupportedError, ToolProviderNotFoundError) as e:
return {'error': str(e)}
# Example usage
schema = "your_openapi_schema_here"
result = resolve_schema_validation_error(schema)
print(result)
This code will help you validate and parse the OpenAPI schema, and handle any errors that may occur during the process. If the schema is valid and correctly parsed, it will proceed to create the API tool provider [1][2].
To continue talking to Dosu, mention @dosu.
Self Checks
Dify version
0.6.11
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
In the top navigation, select "Tools" -> "Custom" -> "Create Custom Tool".
Click the "+ Import from URL" button, enter the API definition URL for qdrant: https://raw.githubusercontent.com/qdrant/qdrant/master/docs/redoc/master/openapi.json, and click "OK".
An error message is displayed on the interface.
Copying the JSON content into the text box below also results in an error message.
Validating the qdrant OpenAPI URL using the officially recommended Swagger tool at https://petstore.swagger.io/ successfully parses it.
✔️ Expected Behavior
The Qdrant OpenAPI definition should be correctly imported into the tool. If there are any incompatible endpoints, it is recommended to highlight the specific endpoint information in the UI.
❌ Actual Behavior
It only pops up an error message, and the user doesn't know how to fix it.