From d4935ca439ddcdd822a15cf7a576c43f1723067e Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Mon, 16 Dec 2024 14:41:11 -0800 Subject: [PATCH] Update OpenAPI --- docs/openapi_generator/generate.py | 3 +- docs/resources/llama-stack-spec.html | 1097 ++++------------- docs/resources/llama-stack-spec.yaml | 647 +++------- llama_stack/apis/common/type_system.py | 32 +- llama_stack/apis/inference/inference.py | 18 +- .../agents/meta_reference/tools/builtin.py | 2 +- 6 files changed, 440 insertions(+), 1359 deletions(-) diff --git a/docs/openapi_generator/generate.py b/docs/openapi_generator/generate.py index 3344f462a..3827311de 100644 --- a/docs/openapi_generator/generate.py +++ b/docs/openapi_generator/generate.py @@ -23,9 +23,10 @@ from llama_models import schema_utils # generation though, we need the full definitions and implementations from the # (json-strong-typing) package. -from .strong_typing.schema import json_schema_type +from .strong_typing.schema import json_schema_type, register_schema schema_utils.json_schema_type = json_schema_type +schema_utils.register_schema = register_schema from llama_stack.apis.version import LLAMA_STACK_API_VERSION # noqa: E402 from llama_stack.distribution.stack import LlamaStack # noqa: E402 diff --git a/docs/resources/llama-stack-spec.html b/docs/resources/llama-stack-spec.html index cb7c6c3af..f372257a0 100644 --- a/docs/resources/llama-stack-spec.html +++ b/docs/resources/llama-stack-spec.html @@ -2531,27 +2531,7 @@ "default": "assistant" }, "content": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" }, "stop_reason": { "$ref": "#/components/schemas/StopReason" @@ -2571,23 +2551,19 @@ "tool_calls" ] }, - "ImageMedia": { + "ImageContentItem": { "type": "object", "properties": { - "image": { + "type": { + "type": "string", + "const": "image", + "default": "image" + }, + "data": { "oneOf": [ { - "type": "object", - "properties": { - "format": { - "type": "string" - }, - "format_description": { - "type": "string" - } - }, - "additionalProperties": false, - "title": "This class represents an image object. To create" + "type": "string", + "contentEncoding": "base64" }, { "$ref": "#/components/schemas/URL" @@ -2597,7 +2573,34 @@ }, "additionalProperties": false, "required": [ - "image" + "type", + "data" + ] + }, + "InterleavedContent": { + "oneOf": [ + { + "type": "string" + }, + { + "$ref": "#/components/schemas/InterleavedContentItem" + }, + { + "type": "array", + "items": { + "$ref": "#/components/schemas/InterleavedContentItem" + } + } + ] + }, + "InterleavedContentItem": { + "oneOf": [ + { + "$ref": "#/components/schemas/ImageContentItem" + }, + { + "$ref": "#/components/schemas/TextContentItem" + } ] }, "SamplingParams": { @@ -2658,27 +2661,7 @@ "default": "system" }, "content": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" } }, "additionalProperties": false, @@ -2687,6 +2670,24 @@ "content" ] }, + "TextContentItem": { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "text", + "default": "text" + }, + "text": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "type", + "text" + ] + }, "ToolCall": { "type": "object", "properties": { @@ -2885,27 +2886,7 @@ ] }, "content": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" } }, "additionalProperties": false, @@ -2930,50 +2911,10 @@ "default": "user" }, "content": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" }, "context": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" } }, "additionalProperties": false, @@ -3066,27 +3007,7 @@ "content_batch": { "type": "array", "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" } }, "sampling_params": { @@ -3407,27 +3328,7 @@ "type": "string" }, "content": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" }, "sampling_params": { "$ref": "#/components/schemas/SamplingParams" @@ -4188,19 +4089,12 @@ "type": "string" }, { - "$ref": "#/components/schemas/ImageMedia" + "$ref": "#/components/schemas/InterleavedContentItem" }, { "type": "array", "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] + "$ref": "#/components/schemas/InterleavedContentItem" } }, { @@ -4526,27 +4420,7 @@ } }, "inserted_context": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" } }, "additionalProperties": false, @@ -4693,27 +4567,7 @@ ] }, "content": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" } }, "additionalProperties": false, @@ -4839,27 +4693,7 @@ "contents": { "type": "array", "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" } } }, @@ -5502,148 +5336,7 @@ "dataset_schema": { "type": "object", "additionalProperties": { - "oneOf": [ - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "string", - "default": "string" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "number", - "default": "number" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "boolean", - "default": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "array", - "default": "array" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "object", - "default": "object" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "json", - "default": "json" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "union", - "default": "union" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "chat_completion_input", - "default": "chat_completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "completion_input", - "default": "completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "agent_turn_input", - "default": "agent_turn_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - } - ] + "$ref": "#/components/schemas/ParamType" } }, "url": { @@ -5686,6 +5379,150 @@ "metadata" ] }, + "ParamType": { + "oneOf": [ + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "string", + "default": "string" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "number", + "default": "number" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "boolean", + "default": "boolean" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "array", + "default": "array" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "object", + "default": "object" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "json", + "default": "json" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "union", + "default": "union" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "chat_completion_input", + "default": "chat_completion_input" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "completion_input", + "default": "completion_input" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "agent_turn_input", + "default": "agent_turn_input" + } + }, + "additionalProperties": false, + "required": [ + "type" + ] + } + ] + }, "EvalTask": { "type": "object", "properties": { @@ -5903,148 +5740,7 @@ } }, "return_type": { - "oneOf": [ - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "string", - "default": "string" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "number", - "default": "number" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "boolean", - "default": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "array", - "default": "array" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "object", - "default": "object" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "json", - "default": "json" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "union", - "default": "union" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "chat_completion_input", - "default": "chat_completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "completion_input", - "default": "completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "agent_turn_input", - "default": "agent_turn_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - } - ] + "$ref": "#/components/schemas/ParamType" }, "params": { "oneOf": [ @@ -6330,19 +6026,12 @@ "type": "string" }, { - "$ref": "#/components/schemas/ImageMedia" + "$ref": "#/components/schemas/InterleavedContentItem" }, { "type": "array", "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] + "$ref": "#/components/schemas/InterleavedContentItem" } }, { @@ -6960,27 +6649,7 @@ "type": "string" }, "query": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" }, "params": { "type": "object", @@ -7023,27 +6692,7 @@ "type": "object", "properties": { "content": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ImageMedia" - } - ] - } - } - ] + "$ref": "#/components/schemas/InterleavedContent" }, "token_count": { "type": "integer" @@ -7261,148 +6910,7 @@ "dataset_schema": { "type": "object", "additionalProperties": { - "oneOf": [ - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "string", - "default": "string" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "number", - "default": "number" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "boolean", - "default": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "array", - "default": "array" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "object", - "default": "object" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "json", - "default": "json" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "union", - "default": "union" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "chat_completion_input", - "default": "chat_completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "completion_input", - "default": "completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "agent_turn_input", - "default": "agent_turn_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - } - ] + "$ref": "#/components/schemas/ParamType" } }, "url": { @@ -7659,148 +7167,7 @@ "type": "string" }, "return_type": { - "oneOf": [ - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "string", - "default": "string" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "number", - "default": "number" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "boolean", - "default": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "array", - "default": "array" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "object", - "default": "object" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "json", - "default": "json" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "union", - "default": "union" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "chat_completion_input", - "default": "chat_completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "completion_input", - "default": "completion_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "agent_turn_input", - "default": "agent_turn_input" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - } - ] + "$ref": "#/components/schemas/ParamType" }, "provider_scoring_fn_id": { "type": "string" @@ -8680,8 +8047,8 @@ "description": "" }, { - "name": "ImageMedia", - "description": "" + "name": "ImageContentItem", + "description": "" }, { "name": "Inference" @@ -8697,6 +8064,14 @@ { "name": "Inspect" }, + { + "name": "InterleavedContent", + "description": "" + }, + { + "name": "InterleavedContentItem", + "description": "" + }, { "name": "Job", "description": "" @@ -8790,6 +8165,10 @@ "name": "PaginatedRowsResult", "description": "" }, + { + "name": "ParamType", + "description": "" + }, { "name": "PhotogenToolDefinition", "description": "" @@ -9015,6 +8394,10 @@ { "name": "Telemetry" }, + { + "name": "TextContentItem", + "description": "" + }, { "name": "TokenLogProbs", "description": "" @@ -9194,9 +8577,11 @@ "GraphMemoryBank", "GraphMemoryBankParams", "HealthInfo", - "ImageMedia", + "ImageContentItem", "InferenceStep", "InsertDocumentsRequest", + "InterleavedContent", + "InterleavedContentItem", "Job", "JobCancelRequest", "JobStatus", @@ -9218,6 +8603,7 @@ "OptimizerConfig", "OptimizerType", "PaginatedRowsResult", + "ParamType", "PhotogenToolDefinition", "PostTrainingJob", "PostTrainingJobArtifactsResponse", @@ -9269,6 +8655,7 @@ "SyntheticDataGenerateRequest", "SyntheticDataGenerationResponse", "SystemMessage", + "TextContentItem", "TokenLogProbs", "ToolCall", "ToolCallDelta", diff --git a/docs/resources/llama-stack-spec.yaml b/docs/resources/llama-stack-spec.yaml index d20c623b3..52c3aaac6 100644 --- a/docs/resources/llama-stack-spec.yaml +++ b/docs/resources/llama-stack-spec.yaml @@ -275,11 +275,9 @@ components: content: oneOf: - type: string - - $ref: '#/components/schemas/ImageMedia' + - $ref: '#/components/schemas/InterleavedContentItem' - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' + $ref: '#/components/schemas/InterleavedContentItem' type: array - $ref: '#/components/schemas/URL' mime_type: @@ -353,14 +351,7 @@ components: properties: content_batch: items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' type: array logprobs: additionalProperties: false @@ -575,14 +566,7 @@ components: additionalProperties: false properties: content: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' role: const: assistant default: assistant @@ -603,14 +587,7 @@ components: additionalProperties: false properties: content: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' logprobs: additionalProperties: false properties: @@ -788,97 +765,7 @@ components: properties: dataset_schema: additionalProperties: - oneOf: - - additionalProperties: false - properties: - type: - const: string - default: string - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: number - default: number - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: boolean - default: boolean - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: array - default: array - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: object - default: object - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: json - default: json - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: union - default: union - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: chat_completion_input - default: chat_completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: completion_input - default: completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: agent_turn_input - default: agent_turn_input - type: string - required: - - type - type: object + $ref: '#/components/schemas/ParamType' type: object identifier: type: string @@ -951,14 +838,7 @@ components: properties: contents: items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' type: array model_id: type: string @@ -1159,22 +1039,21 @@ components: required: - status type: object - ImageMedia: + ImageContentItem: additionalProperties: false properties: - image: + data: oneOf: - - additionalProperties: false - properties: - format: - type: string - format_description: - type: string - title: This class represents an image object. To create - type: object + - contentEncoding: base64 + type: string - $ref: '#/components/schemas/URL' + type: + const: image + default: image + type: string required: - - image + - type + - data type: object InferenceStep: additionalProperties: false @@ -1216,6 +1095,17 @@ components: - bank_id - documents type: object + InterleavedContent: + oneOf: + - type: string + - $ref: '#/components/schemas/InterleavedContentItem' + - items: + $ref: '#/components/schemas/InterleavedContentItem' + type: array + InterleavedContentItem: + oneOf: + - $ref: '#/components/schemas/ImageContentItem' + - $ref: '#/components/schemas/TextContentItem' Job: additionalProperties: false properties: @@ -1395,11 +1285,9 @@ components: content: oneOf: - type: string - - $ref: '#/components/schemas/ImageMedia' + - $ref: '#/components/schemas/InterleavedContentItem' - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' + $ref: '#/components/schemas/InterleavedContentItem' type: array - $ref: '#/components/schemas/URL' document_id: @@ -1428,14 +1316,7 @@ components: format: date-time type: string inserted_context: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' memory_bank_ids: items: type: string @@ -1731,6 +1612,98 @@ components: - rows - total_count type: object + ParamType: + oneOf: + - additionalProperties: false + properties: + type: + const: string + default: string + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: number + default: number + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: boolean + default: boolean + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: array + default: array + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: object + default: object + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: json + default: json + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: union + default: union + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: chat_completion_input + default: chat_completion_input + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: completion_input + default: completion_input + type: string + required: + - type + type: object + - additionalProperties: false + properties: + type: + const: agent_turn_input + default: agent_turn_input + type: string + required: + - type + type: object PhotogenToolDefinition: additionalProperties: false properties: @@ -1918,14 +1891,7 @@ components: - type: object type: object query: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' required: - bank_id - query @@ -1938,14 +1904,7 @@ components: additionalProperties: false properties: content: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' document_id: type: string token_count: @@ -2022,97 +1981,7 @@ components: type: string dataset_schema: additionalProperties: - oneOf: - - additionalProperties: false - properties: - type: - const: string - default: string - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: number - default: number - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: boolean - default: boolean - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: array - default: array - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: object - default: object - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: json - default: json - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: union - default: union - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: chat_completion_input - default: chat_completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: completion_input - default: completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: agent_turn_input - default: agent_turn_input - type: string - required: - - type - type: object + $ref: '#/components/schemas/ParamType' type: object metadata: additionalProperties: @@ -2223,97 +2092,7 @@ components: provider_scoring_fn_id: type: string return_type: - oneOf: - - additionalProperties: false - properties: - type: - const: string - default: string - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: number - default: number - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: boolean - default: boolean - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: array - default: array - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: object - default: object - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: json - default: json - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: union - default: union - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: chat_completion_input - default: chat_completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: completion_input - default: completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: agent_turn_input - default: agent_turn_input - type: string - required: - - type - type: object + $ref: '#/components/schemas/ParamType' scoring_fn_id: type: string required: @@ -2623,97 +2402,7 @@ components: provider_resource_id: type: string return_type: - oneOf: - - additionalProperties: false - properties: - type: - const: string - default: string - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: number - default: number - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: boolean - default: boolean - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: array - default: array - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: object - default: object - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: json - default: json - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: union - default: union - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: chat_completion_input - default: chat_completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: completion_input - default: completion_input - type: string - required: - - type - type: object - - additionalProperties: false - properties: - type: - const: agent_turn_input - default: agent_turn_input - type: string - required: - - type - type: object + $ref: '#/components/schemas/ParamType' type: const: scoring_function default: scoring_function @@ -3112,14 +2801,7 @@ components: additionalProperties: false properties: content: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' role: const: system default: system @@ -3128,6 +2810,19 @@ components: - role - content type: object + TextContentItem: + additionalProperties: false + properties: + text: + type: string + type: + const: text + default: text + type: string + required: + - type + - text + type: object TokenLogProbs: additionalProperties: false properties: @@ -3293,14 +2988,7 @@ components: call_id: type: string content: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' tool_name: oneOf: - $ref: '#/components/schemas/BuiltinTool' @@ -3316,14 +3004,7 @@ components: call_id: type: string content: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' role: const: ipython default: ipython @@ -3492,23 +3173,9 @@ components: additionalProperties: false properties: content: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' context: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - - items: - oneOf: - - type: string - - $ref: '#/components/schemas/ImageMedia' - type: array + $ref: '#/components/schemas/InterleavedContent' role: const: user default: user @@ -5297,8 +4964,9 @@ tags: name: GraphMemoryBankParams - description: name: HealthInfo -- description: - name: ImageMedia +- description: + name: ImageContentItem - name: Inference - description: name: InferenceStep @@ -5306,6 +4974,12 @@ tags: /> name: InsertDocumentsRequest - name: Inspect +- description: + name: InterleavedContent +- description: + name: InterleavedContentItem - description: name: Job - description: name: PaginatedRowsResult +- description: + name: ParamType - description: name: PhotogenToolDefinition @@ -5521,6 +5197,9 @@ tags: - description: name: SystemMessage - name: Telemetry +- description: + name: TextContentItem - description: name: TokenLogProbs - description: @@ -5670,9 +5349,11 @@ x-tagGroups: - GraphMemoryBank - GraphMemoryBankParams - HealthInfo - - ImageMedia + - ImageContentItem - InferenceStep - InsertDocumentsRequest + - InterleavedContent + - InterleavedContentItem - Job - JobCancelRequest - JobStatus @@ -5694,6 +5375,7 @@ x-tagGroups: - OptimizerConfig - OptimizerType - PaginatedRowsResult + - ParamType - PhotogenToolDefinition - PostTrainingJob - PostTrainingJobArtifactsResponse @@ -5745,6 +5427,7 @@ x-tagGroups: - SyntheticDataGenerateRequest - SyntheticDataGenerationResponse - SystemMessage + - TextContentItem - TokenLogProbs - ToolCall - ToolCallDelta diff --git a/llama_stack/apis/common/type_system.py b/llama_stack/apis/common/type_system.py index 93a3c0339..a653efef9 100644 --- a/llama_stack/apis/common/type_system.py +++ b/llama_stack/apis/common/type_system.py @@ -6,6 +6,7 @@ from typing import Literal, Union +from llama_models.schema_utils import register_schema from pydantic import BaseModel, Field from typing_extensions import Annotated @@ -53,21 +54,24 @@ class AgentTurnInputType(BaseModel): type: Literal["agent_turn_input"] = "agent_turn_input" -ParamType = Annotated[ - Union[ - StringType, - NumberType, - BooleanType, - ArrayType, - ObjectType, - JsonType, - UnionType, - ChatCompletionInputType, - CompletionInputType, - AgentTurnInputType, +ParamType = register_schema( + Annotated[ + Union[ + StringType, + NumberType, + BooleanType, + ArrayType, + ObjectType, + JsonType, + UnionType, + ChatCompletionInputType, + CompletionInputType, + AgentTurnInputType, + ], + Field(discriminator="type"), ], - Field(discriminator="type"), -] + name="ParamType", +) # TODO: recursive definition of ParamType in these containers # will cause infinite recursion in OpenAPI generation script diff --git a/llama_stack/apis/inference/inference.py b/llama_stack/apis/inference/inference.py index 2d7936cf7..b465d8509 100644 --- a/llama_stack/apis/inference/inference.py +++ b/llama_stack/apis/inference/inference.py @@ -25,7 +25,7 @@ from llama_models.llama3.api.datatypes import ( ToolPromptFormat, ) -from llama_models.schema_utils import json_schema_type, webmethod +from llama_models.schema_utils import json_schema_type, register_schema, webmethod from pydantic import BaseModel, Field, field_validator from typing_extensions import Annotated @@ -82,13 +82,19 @@ class TextContentItem(BaseModel): # other modalities can be added here -InterleavedContentItem = Annotated[ - Union[ImageContentItem, TextContentItem], - Field(discriminator="type"), -] +InterleavedContentItem = register_schema( + Annotated[ + Union[ImageContentItem, TextContentItem], + Field(discriminator="type"), + ], + name="InterleavedContentItem", +) # accept a single "str" as a special case since it is common -InterleavedContent = str | InterleavedContentItem | List[InterleavedContentItem] +InterleavedContent = register_schema( + Union[str, InterleavedContentItem, List[InterleavedContentItem]], + name="InterleavedContent", +) @json_schema_type diff --git a/llama_stack/providers/inline/agents/meta_reference/tools/builtin.py b/llama_stack/providers/inline/agents/meta_reference/tools/builtin.py index 0bbf67ed8..5045bf32d 100644 --- a/llama_stack/providers/inline/agents/meta_reference/tools/builtin.py +++ b/llama_stack/providers/inline/agents/meta_reference/tools/builtin.py @@ -36,7 +36,7 @@ def interpret_content_as_attachment(content: str) -> Optional[Attachment]: snippet = match.group(1) data = json.loads(snippet) return Attachment( - content=URL(uri="file://" + data["filepath"]), mime_type=data["mimetype"] + url=URL(uri="file://" + data["filepath"]), mime_type=data["mimetype"] ) return None