From 034ece0011ece62d905a2b8a163127a365dd6a8c Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Wed, 19 Feb 2025 13:54:04 -0800 Subject: [PATCH] Ensure that deprecations for fields follow through to OpenAPI --- docs/_static/llama-stack-spec.html | 6 ++++-- docs/_static/llama-stack-spec.yaml | 2 ++ llama_stack/strong_typing/schema.py | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/_static/llama-stack-spec.html b/docs/_static/llama-stack-spec.html index 82abc947b..2b6e1d11c 100644 --- a/docs/_static/llama-stack-spec.html +++ b/docs/_static/llama-stack-spec.html @@ -2702,7 +2702,8 @@ "none" ], "title": "ToolChoice", - "description": "Whether tool use is required or automatic. This is a hint to the model which may not be followed. It depends on the Instruction Following capabilities of the model." + "description": "Whether tool use is required or automatic. This is a hint to the model which may not be followed. It depends on the Instruction Following capabilities of the model.", + "deprecated": true }, "tool_prompt_format": { "type": "string", @@ -2712,7 +2713,8 @@ "python_list" ], "title": "ToolPromptFormat", - "description": "Prompt format for calling custom / zero shot tools." + "description": "Prompt format for calling custom / zero shot tools.", + "deprecated": true }, "tool_config": { "$ref": "#/components/schemas/ToolConfig" diff --git a/docs/_static/llama-stack-spec.yaml b/docs/_static/llama-stack-spec.yaml index 4d13ca565..99300fedf 100644 --- a/docs/_static/llama-stack-spec.yaml +++ b/docs/_static/llama-stack-spec.yaml @@ -1644,6 +1644,7 @@ components: Whether tool use is required or automatic. This is a hint to the model which may not be followed. It depends on the Instruction Following capabilities of the model. + deprecated: true tool_prompt_format: type: string enum: @@ -1653,6 +1654,7 @@ components: title: ToolPromptFormat description: >- Prompt format for calling custom / zero shot tools. + deprecated: true tool_config: $ref: '#/components/schemas/ToolConfig' max_infer_iters: diff --git a/llama_stack/strong_typing/schema.py b/llama_stack/strong_typing/schema.py index 45c7130ba..dfc51ea78 100644 --- a/llama_stack/strong_typing/schema.py +++ b/llama_stack/strong_typing/schema.py @@ -313,6 +313,17 @@ class JsonSchemaGenerator: data_type: TypeLike, force_expand: bool = False, json_schema_extra: Optional[dict] = None, + ) -> Schema: + common_info = {} + if json_schema_extra and "deprecated" in json_schema_extra: + common_info["deprecated"] = json_schema_extra["deprecated"] + return self._type_to_schema(data_type, force_expand, json_schema_extra) | common_info + + def _type_to_schema( + self, + data_type: TypeLike, + force_expand: bool = False, + json_schema_extra: Optional[dict] = None, ) -> Schema: """ Returns the JSON schema associated with a type. @@ -489,7 +500,11 @@ class JsonSchemaGenerator: if "model_fields" in members: f = members["model_fields"] defaults = {k: finfo.default for k, finfo in f.items()} - json_schema_extra = f.get(output_name, None).json_schema_extra + if output_name in f: + finfo = f[output_name] + json_schema_extra = finfo.json_schema_extra or {} + if finfo.deprecated: + json_schema_extra["deprecated"] = True if is_type_optional(property_type): optional_type: type = unwrap_optional_type(property_type)