From fc66131fea8c7fc5dc766522cab0d9ddddc7b1aa Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Wed, 30 Oct 2024 17:52:31 -0700 Subject: [PATCH] fix openapi generator --- .../openapi_generator/pyopenapi/operations.py | 15 +- docs/resources/llama-stack-spec.html | 305 ++---------------- docs/resources/llama-stack-spec.yaml | 191 +---------- llama_stack/distribution/client.py | 8 +- 4 files changed, 67 insertions(+), 452 deletions(-) diff --git a/docs/openapi_generator/pyopenapi/operations.py b/docs/openapi_generator/pyopenapi/operations.py index ad8f2952e..f4238f6f8 100644 --- a/docs/openapi_generator/pyopenapi/operations.py +++ b/docs/openapi_generator/pyopenapi/operations.py @@ -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: diff --git a/docs/resources/llama-stack-spec.html b/docs/resources/llama-stack-spec.html index e790dcff1..de52131b5 100644 --- a/docs/resources/llama-stack-spec.html +++ b/docs/resources/llama-stack-spec.html @@ -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": "" }, - { - "name": "AgentTurnResponseEvent", - "description": "Streamed agent execution response.\n\n" - }, - { - "name": "AgentTurnResponseStepCompletePayload", - "description": "" - }, - { - "name": "AgentTurnResponseStepProgressPayload", - "description": "" - }, - { - "name": "AgentTurnResponseStepStartPayload", - "description": "" - }, - { - "name": "AgentTurnResponseStreamChunk", - "description": "" - }, - { - "name": "AgentTurnResponseTurnCompletePayload", - "description": "" - }, - { - "name": "AgentTurnResponseTurnStartPayload", - "description": "" - }, { "name": "InferenceStep", "description": "" @@ -7665,13 +7429,6 @@ "AgentCreateResponse", "AgentSessionCreateResponse", "AgentStepResponse", - "AgentTurnResponseEvent", - "AgentTurnResponseStepCompletePayload", - "AgentTurnResponseStepProgressPayload", - "AgentTurnResponseStepStartPayload", - "AgentTurnResponseStreamChunk", - "AgentTurnResponseTurnCompletePayload", - "AgentTurnResponseTurnStartPayload", "Attachment", "BatchChatCompletionRequest", "BatchChatCompletionResponse", diff --git a/docs/resources/llama-stack-spec.yaml b/docs/resources/llama-stack-spec.yaml index 67181ab42..0cf378168 100644 --- a/docs/resources/llama-stack-spec.yaml +++ b/docs/resources/llama-stack-spec.yaml @@ -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: name: BuiltinTool - description: name: CreateAgentTurnRequest -- description: 'Streamed agent execution response. - - - ' - name: AgentTurnResponseEvent -- description: - name: AgentTurnResponseStepCompletePayload -- description: - name: AgentTurnResponseStepProgressPayload -- description: - name: AgentTurnResponseStepStartPayload -- description: - name: AgentTurnResponseStreamChunk -- description: - name: AgentTurnResponseTurnCompletePayload -- description: - name: AgentTurnResponseTurnStartPayload - description: name: InferenceStep - description: 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