Skip to content

Commit

Permalink
Apply filters during spec parsing stage
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje committed Jul 20, 2024
1 parent 97120e2 commit 328afca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,15 @@ def _openapi_to_functions(
if path_key.lower() in VALID_HTTP_METHODS:
if "operationId" not in operation_spec:
operation_spec["operationId"] = path_to_operation_id(path, path_key)

# Apply the filter based on operationId before parsing the endpoint (operation)
if operation_filter and not operation_filter(operation_spec):
continue

# parse (and register) this operation as it passed the filter
function_dict = parse_endpoint_fn(operation_spec, parameters_name)
if function_dict:
operations.append(function_dict)

# Filter operations to register with LLMs
if operation_filter:
len_prior = len(operations)
operations = [f for f in operations if operation_filter(f)]
logger.info(
"Registering {op_count} operations out of {len_prior} found in OpenAPI spec.",
op_count=len(operations),
len_prior=len_prior,
)
if len(operations) == 0 and len_prior > 0:
logger.warning(
f"Filtered all operations for "
f"LLM registration in {service_openapi_spec['info']['title']}. Relax the filter criteria."
)
return operations


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(
openapi_spec=openapi_spec,
credentials=credentials.resolve_value() if credentials else None,
llm_provider=generator_api,
operations_filter=(lambda f: f["name"] in allowed_operations) if allowed_operations else None,
operations_filter=(lambda f: f["operationId"] in allowed_operations) if allowed_operations else None,
)
self.open_api_service = OpenAPIServiceClient(self.config_openapi)

Expand Down

0 comments on commit 328afca

Please sign in to comment.