swagger.py
Source: sunholo/agents/swagger.py
Functions
config_to_swagger()
Load configuration files and generate a Swagger specification.
This function loads the 'vacConfig' and 'agentConfig' configuration files, validates their presence, and then generates a Swagger specification based on these configurations.
Returns: str: The generated Swagger specification in YAML format.
Raises: ValueError: If 'vacConfig' or 'agentConfig' is not loaded.
Example:
swagger_yaml = config_to_swagger()
print(swagger_yaml)
validate_api_key(api_key: str, service_name: str) -> bool
Validate an API key against the service name e.g. 'endpoints-xxxx.a.run.app'
generate_swagger(vac_config, agent_config)
Generate a Swagger specification based on the provided configurations.
This function creates a Swagger specification using the provided 'vacConfig' and 'agentConfig'. It dynamically builds paths and responses based on the configurations.
Args: vac_config (dict): The VAC configuration. agent_config (dict): The agent configuration.
Returns: str: The generated Swagger specification in YAML format.
Example:
vac_config = {
'vac': {
'service1': {
'llm': 'vertex',
'model': 'gemini-1.5-flash-001',
'agent': 'langserve'
},
'service2': {
'llm': 'openai',
'agent': 'crewai',
'secrets': ['OPENAI_API_KEY']
}
}
}
agent_config = {
'agents': {
'default': {
'stream': "{stem}/vac/streaming/{vector_name}",
'invoke': "{stem}/vac/{vector_name}",
'post': {
'stream': "{stem}/vac/streaming/{vector_name}",
'invoke': "{stem}/vac/{vector_name}",
'openai': "{stem}/openai/v1/chat/completions",
'openai-vac': "{stem}/openai/v1/chat/completions/{vector_name}"
},
'get': {
'home': "{stem}/",
'health': "{stem}/health"
},
'response': {
'invoke': {
'200': {
'description': 'Successful invocation response',
'schema': {
'type': 'object',
'properties': {
'answer': {'type': 'string'},
'source_documents': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'page_content': {'type': 'string'},
'metadata': {'type': 'string'}
}
}
}
}
}
}
}
}
}
}
}
swagger_yaml = generate_swagger(vac_config, agent_config)
print(swagger_yaml)