diff --git a/docs/openapi_generator/strong_typing/classdef.py b/docs/openapi_generator/strong_typing/classdef.py index 788ecc7e0..b86940420 100644 --- a/docs/openapi_generator/strong_typing/classdef.py +++ b/docs/openapi_generator/strong_typing/classdef.py @@ -122,10 +122,16 @@ class JsonSchemaAnyOf(JsonSchemaNode): anyOf: List["JsonSchemaAny"] +@dataclass +class Discriminator: + propertyName: str + mapping: Dict[str, str] + + @dataclass class JsonSchemaOneOf(JsonSchemaNode): oneOf: List["JsonSchemaAny"] - discriminator: Optional[str] + discriminator: Optional[Discriminator] JsonSchemaAny = Union[ diff --git a/docs/openapi_generator/strong_typing/schema.py b/docs/openapi_generator/strong_typing/schema.py index 5aa41b63f..826efdb4a 100644 --- a/docs/openapi_generator/strong_typing/schema.py +++ b/docs/openapi_generator/strong_typing/schema.py @@ -456,8 +456,19 @@ class JsonSchemaGenerator: ] } if discriminator: + # for each union type, we need to read the value of the discriminator + mapping = {} + for union_type in typing.get_args(typ): + props = self.type_to_schema(union_type, force_expand=True)[ + "properties" + ] + mapping[props[discriminator]["default"]] = self.type_to_schema( + union_type + )["$ref"] + ret["discriminator"] = { "propertyName": discriminator, + "mapping": mapping, } return ret elif origin_type is Literal: diff --git a/docs/resources/llama-stack-spec.html b/docs/resources/llama-stack-spec.html index f6024c586..c8c5ebae8 100644 --- a/docs/resources/llama-stack-spec.html +++ b/docs/resources/llama-stack-spec.html @@ -3812,7 +3812,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "image": "#/components/schemas/ImageContentItem", + "text": "#/components/schemas/TextContentItem" + } } }, "Message": { @@ -3831,7 +3835,13 @@ } ], "discriminator": { - "propertyName": "role" + "propertyName": "role", + "mapping": { + "user": "#/components/schemas/UserMessage", + "system": "#/components/schemas/SystemMessage", + "tool": "#/components/schemas/ToolResponseMessage", + "assistant": "#/components/schemas/CompletionMessage" + } } }, "SamplingParams": { @@ -3850,7 +3860,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "greedy": "#/components/schemas/GreedySamplingStrategy", + "top_p": "#/components/schemas/TopPSamplingStrategy", + "top_k": "#/components/schemas/TopKSamplingStrategy" + } } }, "max_tokens": { @@ -4313,91 +4328,101 @@ "job_uuid" ] }, + "GrammarResponseFormat": { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "grammar", + "default": "grammar" + }, + "bnf": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "array" + }, + { + "type": "object" + } + ] + } + } + }, + "additionalProperties": false, + "required": [ + "type", + "bnf" + ] + }, + "JsonSchemaResponseFormat": { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "json_schema", + "default": "json_schema" + }, + "json_schema": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "array" + }, + { + "type": "object" + } + ] + } + } + }, + "additionalProperties": false, + "required": [ + "type", + "json_schema" + ] + }, "ResponseFormat": { "oneOf": [ { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "json_schema", - "default": "json_schema" - }, - "json_schema": { - "type": "object", - "additionalProperties": { - "oneOf": [ - { - "type": "null" - }, - { - "type": "boolean" - }, - { - "type": "number" - }, - { - "type": "string" - }, - { - "type": "array" - }, - { - "type": "object" - } - ] - } - } - }, - "additionalProperties": false, - "required": [ - "type", - "json_schema" - ] + "$ref": "#/components/schemas/JsonSchemaResponseFormat" }, { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "grammar", - "default": "grammar" - }, - "bnf": { - "type": "object", - "additionalProperties": { - "oneOf": [ - { - "type": "null" - }, - { - "type": "boolean" - }, - { - "type": "number" - }, - { - "type": "string" - }, - { - "type": "array" - }, - { - "type": "object" - } - ] - } - } - }, - "additionalProperties": false, - "required": [ - "type", - "bnf" - ] + "$ref": "#/components/schemas/GrammarResponseFormat" } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "json_schema": "#/components/schemas/JsonSchemaResponseFormat", + "grammar": "#/components/schemas/GrammarResponseFormat" + } } }, "ChatCompletionRequest": { @@ -4529,7 +4554,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "text": "#/components/schemas/TextDelta", + "image": "#/components/schemas/ImageDelta", + "tool_call": "#/components/schemas/ToolCallDelta" + } } }, "ImageDelta": { @@ -4737,8 +4767,7 @@ "default": "auto" }, "tool_prompt_format": { - "$ref": "#/components/schemas/ToolPromptFormat", - "default": "json" + "$ref": "#/components/schemas/ToolPromptFormat" }, "max_infer_iters": { "type": "integer", @@ -5036,7 +5065,14 @@ } ], "discriminator": { - "propertyName": "event_type" + "propertyName": "event_type", + "mapping": { + "step_start": "#/components/schemas/AgentTurnResponseStepStartPayload", + "step_progress": "#/components/schemas/AgentTurnResponseStepProgressPayload", + "step_complete": "#/components/schemas/AgentTurnResponseStepCompletePayload", + "turn_start": "#/components/schemas/AgentTurnResponseTurnStartPayload", + "turn_complete": "#/components/schemas/AgentTurnResponseTurnCompletePayload" + } } } }, @@ -5082,7 +5118,13 @@ } ], "discriminator": { - "propertyName": "step_type" + "propertyName": "step_type", + "mapping": { + "inference": "#/components/schemas/InferenceStep", + "tool_execution": "#/components/schemas/ToolExecutionStep", + "shield_call": "#/components/schemas/ShieldCallStep", + "memory_retrieval": "#/components/schemas/MemoryRetrievalStep" + } } } }, @@ -5485,7 +5527,13 @@ } ], "discriminator": { - "propertyName": "step_type" + "propertyName": "step_type", + "mapping": { + "inference": "#/components/schemas/InferenceStep", + "tool_execution": "#/components/schemas/ToolExecutionStep", + "shield_call": "#/components/schemas/ShieldCallStep", + "memory_retrieval": "#/components/schemas/MemoryRetrievalStep" + } } } }, @@ -5638,7 +5686,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "model": "#/components/schemas/ModelCandidate", + "agent": "#/components/schemas/AgentCandidate" + } } }, "scoring_params": { @@ -5656,7 +5708,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "llm_as_judge": "#/components/schemas/LLMAsJudgeScoringFnParams", + "regex_parser": "#/components/schemas/RegexParserScoringFnParams", + "basic": "#/components/schemas/BasicScoringFnParams" + } } } }, @@ -5709,7 +5766,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "model": "#/components/schemas/ModelCandidate", + "agent": "#/components/schemas/AgentCandidate" + } } }, "num_examples": { @@ -5853,7 +5914,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "benchmark": "#/components/schemas/BenchmarkEvalTaskConfig", + "app": "#/components/schemas/AppEvalTaskConfig" + } } } }, @@ -6019,7 +6084,13 @@ } ], "discriminator": { - "propertyName": "step_type" + "propertyName": "step_type", + "mapping": { + "inference": "#/components/schemas/InferenceStep", + "tool_execution": "#/components/schemas/ToolExecutionStep", + "shield_call": "#/components/schemas/ShieldCallStep", + "memory_retrieval": "#/components/schemas/MemoryRetrievalStep" + } } } }, @@ -6237,7 +6308,19 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "string": "#/components/schemas/StringType", + "number": "#/components/schemas/NumberType", + "boolean": "#/components/schemas/BooleanType", + "array": "#/components/schemas/ArrayType", + "object": "#/components/schemas/ObjectType", + "json": "#/components/schemas/JsonType", + "union": "#/components/schemas/UnionType", + "chat_completion_input": "#/components/schemas/ChatCompletionInputType", + "completion_input": "#/components/schemas/CompletionInputType", + "agent_turn_input": "#/components/schemas/AgentTurnInputType" + } } }, "StringType": { @@ -6500,7 +6583,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "llm_as_judge": "#/components/schemas/LLMAsJudgeScoringFnParams", + "regex_parser": "#/components/schemas/RegexParserScoringFnParams", + "basic": "#/components/schemas/BasicScoringFnParams" + } } } }, @@ -7589,7 +7677,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "span_start": "#/components/schemas/SpanStartPayload", + "span_end": "#/components/schemas/SpanEndPayload" + } } } }, @@ -7678,7 +7770,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "unstructured_log": "#/components/schemas/UnstructuredLogEvent", + "metric": "#/components/schemas/MetricEvent", + "structured_log": "#/components/schemas/StructuredLogEvent" + } } }, "ttl_seconds": { @@ -8011,7 +8108,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "default": "#/components/schemas/DefaultRAGQueryGeneratorConfig", + "llm": "#/components/schemas/LLMRAGQueryGeneratorConfig" + } } }, "QueryRequest": { @@ -8406,7 +8507,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "llm_as_judge": "#/components/schemas/LLMAsJudgeScoringFnParams", + "regex_parser": "#/components/schemas/RegexParserScoringFnParams", + "basic": "#/components/schemas/BasicScoringFnParams" + } } } }, @@ -8542,7 +8648,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "benchmark": "#/components/schemas/BenchmarkEvalTaskConfig", + "app": "#/components/schemas/AppEvalTaskConfig" + } } } }, @@ -8694,7 +8804,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "llm_as_judge": "#/components/schemas/LLMAsJudgeScoringFnParams", + "regex_parser": "#/components/schemas/RegexParserScoringFnParams", + "basic": "#/components/schemas/BasicScoringFnParams" + } } }, { @@ -8748,7 +8863,12 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "llm_as_judge": "#/components/schemas/LLMAsJudgeScoringFnParams", + "regex_parser": "#/components/schemas/RegexParserScoringFnParams", + "basic": "#/components/schemas/BasicScoringFnParams" + } } }, { @@ -8928,7 +9048,11 @@ } ], "discriminator": { - "propertyName": "type" + "propertyName": "type", + "mapping": { + "LoRA": "#/components/schemas/LoraFinetuningConfig", + "QAT": "#/components/schemas/QATFinetuningConfig" + } } } }, @@ -9290,6 +9414,10 @@ "name": "EvaluateRowsRequest", "description": "" }, + { + "name": "GrammarResponseFormat", + "description": "" + }, { "name": "GreedySamplingStrategy", "description": "" @@ -9344,6 +9472,10 @@ "name": "JobStatus", "description": "" }, + { + "name": "JsonSchemaResponseFormat", + "description": "" + }, { "name": "JsonType", "description": "" @@ -9924,6 +10056,7 @@ "EvalTask", "EvaluateResponse", "EvaluateRowsRequest", + "GrammarResponseFormat", "GreedySamplingStrategy", "HealthInfo", "ImageContentItem", @@ -9936,6 +10069,7 @@ "InvokeToolRequest", "Job", "JobStatus", + "JsonSchemaResponseFormat", "JsonType", "LLMAsJudgeScoringFnParams", "LLMRAGQueryGeneratorConfig", diff --git a/docs/resources/llama-stack-spec.yaml b/docs/resources/llama-stack-spec.yaml index 21df2d96f..b53a02c46 100644 --- a/docs/resources/llama-stack-spec.yaml +++ b/docs/resources/llama-stack-spec.yaml @@ -45,7 +45,6 @@ components: default: auto tool_prompt_format: $ref: '#/components/schemas/ToolPromptFormat' - default: json toolgroups: items: $ref: '#/components/schemas/AgentTool' @@ -77,6 +76,11 @@ components: properties: step: discriminator: + mapping: + inference: '#/components/schemas/InferenceStep' + memory_retrieval: '#/components/schemas/MemoryRetrievalStep' + shield_call: '#/components/schemas/ShieldCallStep' + tool_execution: '#/components/schemas/ToolExecutionStep' propertyName: step_type oneOf: - $ref: '#/components/schemas/InferenceStep' @@ -122,6 +126,12 @@ components: properties: payload: discriminator: + mapping: + step_complete: '#/components/schemas/AgentTurnResponseStepCompletePayload' + step_progress: '#/components/schemas/AgentTurnResponseStepProgressPayload' + step_start: '#/components/schemas/AgentTurnResponseStepStartPayload' + turn_complete: '#/components/schemas/AgentTurnResponseTurnCompletePayload' + turn_start: '#/components/schemas/AgentTurnResponseTurnStartPayload' propertyName: event_type oneOf: - $ref: '#/components/schemas/AgentTurnResponseStepStartPayload' @@ -142,6 +152,11 @@ components: type: string step_details: discriminator: + mapping: + inference: '#/components/schemas/InferenceStep' + memory_retrieval: '#/components/schemas/MemoryRetrievalStep' + shield_call: '#/components/schemas/ShieldCallStep' + tool_execution: '#/components/schemas/ToolExecutionStep' propertyName: step_type oneOf: - $ref: '#/components/schemas/InferenceStep' @@ -265,6 +280,9 @@ components: properties: eval_candidate: discriminator: + mapping: + agent: '#/components/schemas/AgentCandidate' + model: '#/components/schemas/ModelCandidate' propertyName: type oneOf: - $ref: '#/components/schemas/ModelCandidate' @@ -274,6 +292,10 @@ components: scoring_params: additionalProperties: discriminator: + mapping: + basic: '#/components/schemas/BasicScoringFnParams' + llm_as_judge: '#/components/schemas/LLMAsJudgeScoringFnParams' + regex_parser: '#/components/schemas/RegexParserScoringFnParams' propertyName: type oneOf: - $ref: '#/components/schemas/LLMAsJudgeScoringFnParams' @@ -413,6 +435,9 @@ components: properties: eval_candidate: discriminator: + mapping: + agent: '#/components/schemas/AgentCandidate' + model: '#/components/schemas/ModelCandidate' propertyName: type oneOf: - $ref: '#/components/schemas/ModelCandidate' @@ -632,6 +657,10 @@ components: type: object ContentDelta: discriminator: + mapping: + image: '#/components/schemas/ImageDelta' + text: '#/components/schemas/TextDelta' + tool_call: '#/components/schemas/ToolCallDelta' propertyName: type oneOf: - $ref: '#/components/schemas/TextDelta' @@ -912,6 +941,9 @@ components: type: array task_config: discriminator: + mapping: + app: '#/components/schemas/AppEvalTaskConfig' + benchmark: '#/components/schemas/BenchmarkEvalTaskConfig' propertyName: type oneOf: - $ref: '#/components/schemas/BenchmarkEvalTaskConfig' @@ -921,6 +953,27 @@ components: - scoring_functions - task_config type: object + GrammarResponseFormat: + additionalProperties: false + properties: + bnf: + additionalProperties: + oneOf: + - type: 'null' + - type: boolean + - type: number + - type: string + - type: array + - type: object + type: object + type: + const: grammar + default: grammar + type: string + required: + - type + - bnf + type: object GreedySamplingStrategy: additionalProperties: false properties: @@ -1055,6 +1108,9 @@ components: type: array InterleavedContentItem: discriminator: + mapping: + image: '#/components/schemas/ImageContentItem' + text: '#/components/schemas/TextContentItem' propertyName: type oneOf: - $ref: '#/components/schemas/ImageContentItem' @@ -1093,6 +1149,27 @@ components: - failed - scheduled type: string + JsonSchemaResponseFormat: + additionalProperties: false + properties: + json_schema: + additionalProperties: + oneOf: + - type: 'null' + - type: boolean + - type: number + - type: string + - type: array + - type: object + type: object + type: + const: json_schema + default: json_schema + type: string + required: + - type + - json_schema + type: object JsonType: additionalProperties: false properties: @@ -1263,6 +1340,10 @@ components: properties: event: discriminator: + mapping: + metric: '#/components/schemas/MetricEvent' + structured_log: '#/components/schemas/StructuredLogEvent' + unstructured_log: '#/components/schemas/UnstructuredLogEvent' propertyName: type oneOf: - $ref: '#/components/schemas/UnstructuredLogEvent' @@ -1346,6 +1427,11 @@ components: type: object Message: discriminator: + mapping: + assistant: '#/components/schemas/CompletionMessage' + system: '#/components/schemas/SystemMessage' + tool: '#/components/schemas/ToolResponseMessage' + user: '#/components/schemas/UserMessage' propertyName: role oneOf: - $ref: '#/components/schemas/UserMessage' @@ -1518,6 +1604,17 @@ components: type: object ParamType: discriminator: + mapping: + agent_turn_input: '#/components/schemas/AgentTurnInputType' + array: '#/components/schemas/ArrayType' + boolean: '#/components/schemas/BooleanType' + chat_completion_input: '#/components/schemas/ChatCompletionInputType' + completion_input: '#/components/schemas/CompletionInputType' + json: '#/components/schemas/JsonType' + number: '#/components/schemas/NumberType' + object: '#/components/schemas/ObjectType' + string: '#/components/schemas/StringType' + union: '#/components/schemas/UnionType' propertyName: type oneOf: - $ref: '#/components/schemas/StringType' @@ -1830,6 +1927,9 @@ components: type: object RAGQueryGeneratorConfig: discriminator: + mapping: + default: '#/components/schemas/DefaultRAGQueryGeneratorConfig' + llm: '#/components/schemas/LLMRAGQueryGeneratorConfig' propertyName: type oneOf: - $ref: '#/components/schemas/DefaultRAGQueryGeneratorConfig' @@ -1949,6 +2049,10 @@ components: type: string params: discriminator: + mapping: + basic: '#/components/schemas/BasicScoringFnParams' + llm_as_judge: '#/components/schemas/LLMAsJudgeScoringFnParams' + regex_parser: '#/components/schemas/RegexParserScoringFnParams' propertyName: type oneOf: - $ref: '#/components/schemas/LLMAsJudgeScoringFnParams' @@ -2031,48 +2135,13 @@ components: type: object ResponseFormat: discriminator: + mapping: + grammar: '#/components/schemas/GrammarResponseFormat' + json_schema: '#/components/schemas/JsonSchemaResponseFormat' propertyName: type oneOf: - - additionalProperties: false - properties: - json_schema: - additionalProperties: - oneOf: - - type: 'null' - - type: boolean - - type: number - - type: string - - type: array - - type: object - type: object - type: - const: json_schema - default: json_schema - type: string - required: - - type - - json_schema - type: object - - additionalProperties: false - properties: - bnf: - additionalProperties: - oneOf: - - type: 'null' - - type: boolean - - type: number - - type: string - - type: array - - type: object - type: object - type: - const: grammar - default: grammar - type: string - required: - - type - - bnf - type: object + - $ref: '#/components/schemas/JsonSchemaResponseFormat' + - $ref: '#/components/schemas/GrammarResponseFormat' RouteInfo: additionalProperties: false properties: @@ -2094,6 +2163,9 @@ components: properties: task_config: discriminator: + mapping: + app: '#/components/schemas/AppEvalTaskConfig' + benchmark: '#/components/schemas/BenchmarkEvalTaskConfig' propertyName: type oneOf: - $ref: '#/components/schemas/BenchmarkEvalTaskConfig' @@ -2163,6 +2235,10 @@ components: type: number strategy: discriminator: + mapping: + greedy: '#/components/schemas/GreedySamplingStrategy' + top_k: '#/components/schemas/TopKSamplingStrategy' + top_p: '#/components/schemas/TopPSamplingStrategy' propertyName: type oneOf: - $ref: '#/components/schemas/GreedySamplingStrategy' @@ -2202,6 +2278,10 @@ components: additionalProperties: oneOf: - discriminator: + mapping: + basic: '#/components/schemas/BasicScoringFnParams' + llm_as_judge: '#/components/schemas/LLMAsJudgeScoringFnParams' + regex_parser: '#/components/schemas/RegexParserScoringFnParams' propertyName: type oneOf: - $ref: '#/components/schemas/LLMAsJudgeScoringFnParams' @@ -2245,6 +2325,10 @@ components: additionalProperties: oneOf: - discriminator: + mapping: + basic: '#/components/schemas/BasicScoringFnParams' + llm_as_judge: '#/components/schemas/LLMAsJudgeScoringFnParams' + regex_parser: '#/components/schemas/RegexParserScoringFnParams' propertyName: type oneOf: - $ref: '#/components/schemas/LLMAsJudgeScoringFnParams' @@ -2285,6 +2369,10 @@ components: type: object params: discriminator: + mapping: + basic: '#/components/schemas/BasicScoringFnParams' + llm_as_judge: '#/components/schemas/LLMAsJudgeScoringFnParams' + regex_parser: '#/components/schemas/RegexParserScoringFnParams' propertyName: type oneOf: - $ref: '#/components/schemas/LLMAsJudgeScoringFnParams' @@ -2544,6 +2632,9 @@ components: type: object payload: discriminator: + mapping: + span_end: '#/components/schemas/SpanEndPayload' + span_start: '#/components/schemas/SpanStartPayload' propertyName: type oneOf: - $ref: '#/components/schemas/SpanStartPayload' @@ -2571,6 +2662,9 @@ components: properties: algorithm_config: discriminator: + mapping: + LoRA: '#/components/schemas/LoraFinetuningConfig' + QAT: '#/components/schemas/QATFinetuningConfig' propertyName: type oneOf: - $ref: '#/components/schemas/LoraFinetuningConfig' @@ -3160,6 +3254,11 @@ components: steps: items: discriminator: + mapping: + inference: '#/components/schemas/InferenceStep' + memory_retrieval: '#/components/schemas/MemoryRetrievalStep' + shield_call: '#/components/schemas/ShieldCallStep' + tool_execution: '#/components/schemas/ToolExecutionStep' propertyName: step_type oneOf: - $ref: '#/components/schemas/InferenceStep' @@ -5846,6 +5945,9 @@ tags: - description: name: EvaluateRowsRequest +- description: + name: GrammarResponseFormat - description: name: GreedySamplingStrategy @@ -5878,6 +5980,9 @@ tags: name: Job - description: name: JobStatus +- description: + name: JsonSchemaResponseFormat - description: name: JsonType - description: