fix openapi generator

This commit is contained in:
Ashwin Bharambe 2024-10-30 17:52:31 -07:00
parent 4067038f74
commit fc66131fea
4 changed files with 67 additions and 452 deletions

View file

@ -315,7 +315,20 @@ def get_endpoint_operations(
)
else:
event_type = None
response_type = return_type
def process_type(t):
if typing.get_origin(t) is collections.abc.AsyncIterator:
# NOTE(ashwin): this is SSE and there is no way to represent it. either we make it a List
# or the item type. I am choosing it to be the latter
args = typing.get_args(t)
return args[0]
elif typing.get_origin(t) is typing.Union:
types = [process_type(a) for a in typing.get_args(t)]
return typing._UnionGenericAlias(typing.Union, tuple(types))
else:
return t
response_type = process_type(return_type)
# set HTTP request method based on type of request and presence of payload
if not request_params:

View file

@ -21,7 +21,7 @@
"info": {
"title": "[DRAFT] Llama Stack Specification",
"version": "0.0.1",
"description": "This is the specification of the llama stack that provides\n a set of endpoints and their corresponding interfaces that are tailored to\n best leverage Llama Models. The specification is still in draft and subject to change.\n Generated at 2024-10-30 16:17:03.919702"
"description": "This is the specification of the llama stack that provides\n a set of endpoints and their corresponding interfaces that are tailored to\n best leverage Llama Models. The specification is still in draft and subject to change.\n Generated at 2024-10-31 10:35:38.305313"
},
"servers": [
{
@ -320,11 +320,11 @@
"post": {
"responses": {
"200": {
"description": "OK",
"description": "A single turn in an interaction with an Agentic System.",
"content": {
"text/event-stream": {
"schema": {
"$ref": "#/components/schemas/AgentTurnResponseStreamChunk"
"$ref": "#/components/schemas/Turn"
}
}
}
@ -3832,214 +3832,6 @@
"messages"
]
},
"AgentTurnResponseEvent": {
"type": "object",
"properties": {
"payload": {
"oneOf": [
{
"$ref": "#/components/schemas/AgentTurnResponseStepStartPayload"
},
{
"$ref": "#/components/schemas/AgentTurnResponseStepProgressPayload"
},
{
"$ref": "#/components/schemas/AgentTurnResponseStepCompletePayload"
},
{
"$ref": "#/components/schemas/AgentTurnResponseTurnStartPayload"
},
{
"$ref": "#/components/schemas/AgentTurnResponseTurnCompletePayload"
}
]
}
},
"additionalProperties": false,
"required": [
"payload"
],
"title": "Streamed agent execution response."
},
"AgentTurnResponseStepCompletePayload": {
"type": "object",
"properties": {
"event_type": {
"type": "string",
"const": "step_complete",
"default": "step_complete"
},
"step_type": {
"type": "string",
"enum": [
"inference",
"tool_execution",
"shield_call",
"memory_retrieval"
]
},
"step_details": {
"oneOf": [
{
"$ref": "#/components/schemas/InferenceStep"
},
{
"$ref": "#/components/schemas/ToolExecutionStep"
},
{
"$ref": "#/components/schemas/ShieldCallStep"
},
{
"$ref": "#/components/schemas/MemoryRetrievalStep"
}
]
}
},
"additionalProperties": false,
"required": [
"event_type",
"step_type",
"step_details"
]
},
"AgentTurnResponseStepProgressPayload": {
"type": "object",
"properties": {
"event_type": {
"type": "string",
"const": "step_progress",
"default": "step_progress"
},
"step_type": {
"type": "string",
"enum": [
"inference",
"tool_execution",
"shield_call",
"memory_retrieval"
]
},
"step_id": {
"type": "string"
},
"model_response_text_delta": {
"type": "string"
},
"tool_call_delta": {
"$ref": "#/components/schemas/ToolCallDelta"
},
"tool_response_text_delta": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"event_type",
"step_type",
"step_id"
]
},
"AgentTurnResponseStepStartPayload": {
"type": "object",
"properties": {
"event_type": {
"type": "string",
"const": "step_start",
"default": "step_start"
},
"step_type": {
"type": "string",
"enum": [
"inference",
"tool_execution",
"shield_call",
"memory_retrieval"
]
},
"step_id": {
"type": "string"
},
"metadata": {
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "null"
},
{
"type": "boolean"
},
{
"type": "number"
},
{
"type": "string"
},
{
"type": "array"
},
{
"type": "object"
}
]
}
}
},
"additionalProperties": false,
"required": [
"event_type",
"step_type",
"step_id"
]
},
"AgentTurnResponseStreamChunk": {
"type": "object",
"properties": {
"event": {
"$ref": "#/components/schemas/AgentTurnResponseEvent"
}
},
"additionalProperties": false,
"required": [
"event"
]
},
"AgentTurnResponseTurnCompletePayload": {
"type": "object",
"properties": {
"event_type": {
"type": "string",
"const": "turn_complete",
"default": "turn_complete"
},
"turn": {
"$ref": "#/components/schemas/Turn"
}
},
"additionalProperties": false,
"required": [
"event_type",
"turn"
]
},
"AgentTurnResponseTurnStartPayload": {
"type": "object",
"properties": {
"event_type": {
"type": "string",
"const": "turn_start",
"default": "turn_start"
},
"turn_id": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"event_type",
"turn_id"
]
},
"InferenceStep": {
"type": "object",
"properties": {
@ -7055,43 +6847,19 @@
],
"tags": [
{
"name": "Inference"
},
{
"name": "Memory"
},
{
"name": "Inspect"
},
{
"name": "PostTraining"
},
{
"name": "Models"
"name": "Safety"
},
{
"name": "Scoring"
},
{
"name": "DatasetIO"
},
{
"name": "BatchInference"
},
{
"name": "Agents"
"name": "DatasetIO"
},
{
"name": "Shields"
},
{
"name": "MemoryBanks"
},
{
"name": "Datasets"
},
{
"name": "SyntheticDataGeneration"
"name": "Models"
},
{
"name": "Eval"
@ -7099,11 +6867,35 @@
{
"name": "Telemetry"
},
{
"name": "Shields"
},
{
"name": "Datasets"
},
{
"name": "Memory"
},
{
"name": "PostTraining"
},
{
"name": "ScoringFunctions"
},
{
"name": "Safety"
"name": "SyntheticDataGeneration"
},
{
"name": "Inspect"
},
{
"name": "MemoryBanks"
},
{
"name": "Inference"
},
{
"name": "Agents"
},
{
"name": "BuiltinTool",
@ -7289,34 +7081,6 @@
"name": "CreateAgentTurnRequest",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/CreateAgentTurnRequest\" />"
},
{
"name": "AgentTurnResponseEvent",
"description": "Streamed agent execution response.\n\n<SchemaDefinition schemaRef=\"#/components/schemas/AgentTurnResponseEvent\" />"
},
{
"name": "AgentTurnResponseStepCompletePayload",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentTurnResponseStepCompletePayload\" />"
},
{
"name": "AgentTurnResponseStepProgressPayload",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentTurnResponseStepProgressPayload\" />"
},
{
"name": "AgentTurnResponseStepStartPayload",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentTurnResponseStepStartPayload\" />"
},
{
"name": "AgentTurnResponseStreamChunk",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentTurnResponseStreamChunk\" />"
},
{
"name": "AgentTurnResponseTurnCompletePayload",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentTurnResponseTurnCompletePayload\" />"
},
{
"name": "AgentTurnResponseTurnStartPayload",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentTurnResponseTurnStartPayload\" />"
},
{
"name": "InferenceStep",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/InferenceStep\" />"
@ -7665,13 +7429,6 @@
"AgentCreateResponse",
"AgentSessionCreateResponse",
"AgentStepResponse",
"AgentTurnResponseEvent",
"AgentTurnResponseStepCompletePayload",
"AgentTurnResponseStepProgressPayload",
"AgentTurnResponseStepStartPayload",
"AgentTurnResponseStreamChunk",
"AgentTurnResponseTurnCompletePayload",
"AgentTurnResponseTurnStartPayload",
"Attachment",
"BatchChatCompletionRequest",
"BatchChatCompletionResponse",

View file

@ -86,137 +86,6 @@ components:
required:
- step
type: object
AgentTurnResponseEvent:
additionalProperties: false
properties:
payload:
oneOf:
- $ref: '#/components/schemas/AgentTurnResponseStepStartPayload'
- $ref: '#/components/schemas/AgentTurnResponseStepProgressPayload'
- $ref: '#/components/schemas/AgentTurnResponseStepCompletePayload'
- $ref: '#/components/schemas/AgentTurnResponseTurnStartPayload'
- $ref: '#/components/schemas/AgentTurnResponseTurnCompletePayload'
required:
- payload
title: Streamed agent execution response.
type: object
AgentTurnResponseStepCompletePayload:
additionalProperties: false
properties:
event_type:
const: step_complete
default: step_complete
type: string
step_details:
oneOf:
- $ref: '#/components/schemas/InferenceStep'
- $ref: '#/components/schemas/ToolExecutionStep'
- $ref: '#/components/schemas/ShieldCallStep'
- $ref: '#/components/schemas/MemoryRetrievalStep'
step_type:
enum:
- inference
- tool_execution
- shield_call
- memory_retrieval
type: string
required:
- event_type
- step_type
- step_details
type: object
AgentTurnResponseStepProgressPayload:
additionalProperties: false
properties:
event_type:
const: step_progress
default: step_progress
type: string
model_response_text_delta:
type: string
step_id:
type: string
step_type:
enum:
- inference
- tool_execution
- shield_call
- memory_retrieval
type: string
tool_call_delta:
$ref: '#/components/schemas/ToolCallDelta'
tool_response_text_delta:
type: string
required:
- event_type
- step_type
- step_id
type: object
AgentTurnResponseStepStartPayload:
additionalProperties: false
properties:
event_type:
const: step_start
default: step_start
type: string
metadata:
additionalProperties:
oneOf:
- type: 'null'
- type: boolean
- type: number
- type: string
- type: array
- type: object
type: object
step_id:
type: string
step_type:
enum:
- inference
- tool_execution
- shield_call
- memory_retrieval
type: string
required:
- event_type
- step_type
- step_id
type: object
AgentTurnResponseStreamChunk:
additionalProperties: false
properties:
event:
$ref: '#/components/schemas/AgentTurnResponseEvent'
required:
- event
type: object
AgentTurnResponseTurnCompletePayload:
additionalProperties: false
properties:
event_type:
const: turn_complete
default: turn_complete
type: string
turn:
$ref: '#/components/schemas/Turn'
required:
- event_type
- turn
type: object
AgentTurnResponseTurnStartPayload:
additionalProperties: false
properties:
event_type:
const: turn_start
default: turn_start
type: string
turn_id:
type: string
required:
- event_type
- turn_id
type: object
Attachment:
additionalProperties: false
properties:
@ -2997,7 +2866,7 @@ info:
description: "This is the specification of the llama stack that provides\n \
\ a set of endpoints and their corresponding interfaces that are tailored\
\ to\n best leverage Llama Models. The specification is still in\
\ draft and subject to change.\n Generated at 2024-10-30 16:17:03.919702"
\ draft and subject to change.\n Generated at 2024-10-31 10:35:38.305313"
title: '[DRAFT] Llama Stack Specification'
version: 0.0.1
jsonSchemaDialect: https://json-schema.org/draft/2020-12/schema
@ -3190,8 +3059,8 @@ paths:
content:
text/event-stream:
schema:
$ref: '#/components/schemas/AgentTurnResponseStreamChunk'
description: OK
$ref: '#/components/schemas/Turn'
description: A single turn in an interaction with an Agentic System.
tags:
- Agents
/agents/turn/get:
@ -4276,23 +4145,23 @@ security:
servers:
- url: http://any-hosted-llama-stack.com
tags:
- name: Inference
- name: Memory
- name: Inspect
- name: PostTraining
- name: Models
- name: Safety
- name: Scoring
- name: DatasetIO
- name: BatchInference
- name: Agents
- name: Shields
- name: MemoryBanks
- name: Datasets
- name: SyntheticDataGeneration
- name: DatasetIO
- name: Models
- name: Eval
- name: Telemetry
- name: Shields
- name: Datasets
- name: Memory
- name: PostTraining
- name: ScoringFunctions
- name: Safety
- name: SyntheticDataGeneration
- name: Inspect
- name: MemoryBanks
- name: Inference
- name: Agents
- description: <SchemaDefinition schemaRef="#/components/schemas/BuiltinTool" />
name: BuiltinTool
- description: <SchemaDefinition schemaRef="#/components/schemas/CompletionMessage"
@ -4437,29 +4306,6 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/CreateAgentTurnRequest"
/>
name: CreateAgentTurnRequest
- description: 'Streamed agent execution response.
<SchemaDefinition schemaRef="#/components/schemas/AgentTurnResponseEvent" />'
name: AgentTurnResponseEvent
- description: <SchemaDefinition schemaRef="#/components/schemas/AgentTurnResponseStepCompletePayload"
/>
name: AgentTurnResponseStepCompletePayload
- description: <SchemaDefinition schemaRef="#/components/schemas/AgentTurnResponseStepProgressPayload"
/>
name: AgentTurnResponseStepProgressPayload
- description: <SchemaDefinition schemaRef="#/components/schemas/AgentTurnResponseStepStartPayload"
/>
name: AgentTurnResponseStepStartPayload
- description: <SchemaDefinition schemaRef="#/components/schemas/AgentTurnResponseStreamChunk"
/>
name: AgentTurnResponseStreamChunk
- description: <SchemaDefinition schemaRef="#/components/schemas/AgentTurnResponseTurnCompletePayload"
/>
name: AgentTurnResponseTurnCompletePayload
- description: <SchemaDefinition schemaRef="#/components/schemas/AgentTurnResponseTurnStartPayload"
/>
name: AgentTurnResponseTurnStartPayload
- description: <SchemaDefinition schemaRef="#/components/schemas/InferenceStep" />
name: InferenceStep
- description: <SchemaDefinition schemaRef="#/components/schemas/MemoryRetrievalStep"
@ -4720,13 +4566,6 @@ x-tagGroups:
- AgentCreateResponse
- AgentSessionCreateResponse
- AgentStepResponse
- AgentTurnResponseEvent
- AgentTurnResponseStepCompletePayload
- AgentTurnResponseStepProgressPayload
- AgentTurnResponseStepStartPayload
- AgentTurnResponseStreamChunk
- AgentTurnResponseTurnCompletePayload
- AgentTurnResponseTurnStartPayload
- Attachment
- BatchChatCompletionRequest
- BatchChatCompletionResponse

View file

@ -36,7 +36,13 @@ def extract_async_iterator_type(type_hint):
return None
_CLIENT_CLASSES = {}
def create_api_client_class(protocol) -> Type:
if protocol in _CLIENT_CLASSES:
return _CLIENT_CLASSES[protocol]
class APIClient:
def __init__(self, base_url: str):
self.base_url = base_url.rstrip("/")
@ -124,7 +130,6 @@ def create_api_client_class(protocol) -> Type:
else:
data.update(convert(kwargs))
print(f"{data=}")
return dict(
method=webmethod.method or "POST",
url=url,
@ -148,6 +153,7 @@ def create_api_client_class(protocol) -> Type:
# Name the class after the protocol
APIClient.__name__ = f"{protocol.__name__}Client"
_CLIENT_CLASSES[protocol] = APIClient
return APIClient