Update OpenAPI

This commit is contained in:
Ashwin Bharambe 2024-12-16 14:41:11 -08:00
parent e0731ba353
commit d4935ca439
6 changed files with 440 additions and 1359 deletions

View file

@ -23,9 +23,10 @@ from llama_models import schema_utils
# generation though, we need the full definitions and implementations from the # generation though, we need the full definitions and implementations from the
# (json-strong-typing) package. # (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.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.apis.version import LLAMA_STACK_API_VERSION # noqa: E402
from llama_stack.distribution.stack import LlamaStack # noqa: E402 from llama_stack.distribution.stack import LlamaStack # noqa: E402

File diff suppressed because it is too large Load diff

View file

@ -275,11 +275,9 @@ components:
content: content:
oneOf: oneOf:
- type: string - type: string
- $ref: '#/components/schemas/ImageMedia' - $ref: '#/components/schemas/InterleavedContentItem'
- items: - items:
oneOf: $ref: '#/components/schemas/InterleavedContentItem'
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array type: array
- $ref: '#/components/schemas/URL' - $ref: '#/components/schemas/URL'
mime_type: mime_type:
@ -353,14 +351,7 @@ components:
properties: properties:
content_batch: content_batch:
items: items:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
type: array type: array
logprobs: logprobs:
additionalProperties: false additionalProperties: false
@ -575,14 +566,7 @@ components:
additionalProperties: false additionalProperties: false
properties: properties:
content: content:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
role: role:
const: assistant const: assistant
default: assistant default: assistant
@ -603,14 +587,7 @@ components:
additionalProperties: false additionalProperties: false
properties: properties:
content: content:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
logprobs: logprobs:
additionalProperties: false additionalProperties: false
properties: properties:
@ -788,97 +765,7 @@ components:
properties: properties:
dataset_schema: dataset_schema:
additionalProperties: additionalProperties:
oneOf: $ref: '#/components/schemas/ParamType'
- 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
type: object type: object
identifier: identifier:
type: string type: string
@ -951,14 +838,7 @@ components:
properties: properties:
contents: contents:
items: items:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
type: array type: array
model_id: model_id:
type: string type: string
@ -1159,22 +1039,21 @@ components:
required: required:
- status - status
type: object type: object
ImageMedia: ImageContentItem:
additionalProperties: false additionalProperties: false
properties: properties:
image: data:
oneOf: oneOf:
- additionalProperties: false - contentEncoding: base64
properties: type: string
format:
type: string
format_description:
type: string
title: This class represents an image object. To create
type: object
- $ref: '#/components/schemas/URL' - $ref: '#/components/schemas/URL'
type:
const: image
default: image
type: string
required: required:
- image - type
- data
type: object type: object
InferenceStep: InferenceStep:
additionalProperties: false additionalProperties: false
@ -1216,6 +1095,17 @@ components:
- bank_id - bank_id
- documents - documents
type: object 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: Job:
additionalProperties: false additionalProperties: false
properties: properties:
@ -1395,11 +1285,9 @@ components:
content: content:
oneOf: oneOf:
- type: string - type: string
- $ref: '#/components/schemas/ImageMedia' - $ref: '#/components/schemas/InterleavedContentItem'
- items: - items:
oneOf: $ref: '#/components/schemas/InterleavedContentItem'
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array type: array
- $ref: '#/components/schemas/URL' - $ref: '#/components/schemas/URL'
document_id: document_id:
@ -1428,14 +1316,7 @@ components:
format: date-time format: date-time
type: string type: string
inserted_context: inserted_context:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
memory_bank_ids: memory_bank_ids:
items: items:
type: string type: string
@ -1731,6 +1612,98 @@ components:
- rows - rows
- total_count - total_count
type: object 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: PhotogenToolDefinition:
additionalProperties: false additionalProperties: false
properties: properties:
@ -1918,14 +1891,7 @@ components:
- type: object - type: object
type: object type: object
query: query:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
required: required:
- bank_id - bank_id
- query - query
@ -1938,14 +1904,7 @@ components:
additionalProperties: false additionalProperties: false
properties: properties:
content: content:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
document_id: document_id:
type: string type: string
token_count: token_count:
@ -2022,97 +1981,7 @@ components:
type: string type: string
dataset_schema: dataset_schema:
additionalProperties: additionalProperties:
oneOf: $ref: '#/components/schemas/ParamType'
- 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
type: object type: object
metadata: metadata:
additionalProperties: additionalProperties:
@ -2223,97 +2092,7 @@ components:
provider_scoring_fn_id: provider_scoring_fn_id:
type: string type: string
return_type: return_type:
oneOf: $ref: '#/components/schemas/ParamType'
- 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
scoring_fn_id: scoring_fn_id:
type: string type: string
required: required:
@ -2623,97 +2402,7 @@ components:
provider_resource_id: provider_resource_id:
type: string type: string
return_type: return_type:
oneOf: $ref: '#/components/schemas/ParamType'
- 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
type: type:
const: scoring_function const: scoring_function
default: scoring_function default: scoring_function
@ -3112,14 +2801,7 @@ components:
additionalProperties: false additionalProperties: false
properties: properties:
content: content:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
role: role:
const: system const: system
default: system default: system
@ -3128,6 +2810,19 @@ components:
- role - role
- content - content
type: object type: object
TextContentItem:
additionalProperties: false
properties:
text:
type: string
type:
const: text
default: text
type: string
required:
- type
- text
type: object
TokenLogProbs: TokenLogProbs:
additionalProperties: false additionalProperties: false
properties: properties:
@ -3293,14 +2988,7 @@ components:
call_id: call_id:
type: string type: string
content: content:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
tool_name: tool_name:
oneOf: oneOf:
- $ref: '#/components/schemas/BuiltinTool' - $ref: '#/components/schemas/BuiltinTool'
@ -3316,14 +3004,7 @@ components:
call_id: call_id:
type: string type: string
content: content:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
role: role:
const: ipython const: ipython
default: ipython default: ipython
@ -3492,23 +3173,9 @@ components:
additionalProperties: false additionalProperties: false
properties: properties:
content: content:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
context: context:
oneOf: $ref: '#/components/schemas/InterleavedContent'
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
role: role:
const: user const: user
default: user default: user
@ -5297,8 +4964,9 @@ tags:
name: GraphMemoryBankParams name: GraphMemoryBankParams
- description: <SchemaDefinition schemaRef="#/components/schemas/HealthInfo" /> - description: <SchemaDefinition schemaRef="#/components/schemas/HealthInfo" />
name: HealthInfo name: HealthInfo
- description: <SchemaDefinition schemaRef="#/components/schemas/ImageMedia" /> - description: <SchemaDefinition schemaRef="#/components/schemas/ImageContentItem"
name: ImageMedia />
name: ImageContentItem
- name: Inference - name: Inference
- description: <SchemaDefinition schemaRef="#/components/schemas/InferenceStep" /> - description: <SchemaDefinition schemaRef="#/components/schemas/InferenceStep" />
name: InferenceStep name: InferenceStep
@ -5306,6 +4974,12 @@ tags:
/> />
name: InsertDocumentsRequest name: InsertDocumentsRequest
- name: Inspect - name: Inspect
- description: <SchemaDefinition schemaRef="#/components/schemas/InterleavedContent"
/>
name: InterleavedContent
- description: <SchemaDefinition schemaRef="#/components/schemas/InterleavedContentItem"
/>
name: InterleavedContentItem
- description: <SchemaDefinition schemaRef="#/components/schemas/Job" /> - description: <SchemaDefinition schemaRef="#/components/schemas/Job" />
name: Job name: Job
- description: <SchemaDefinition schemaRef="#/components/schemas/JobCancelRequest" - description: <SchemaDefinition schemaRef="#/components/schemas/JobCancelRequest"
@ -5364,6 +5038,8 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/PaginatedRowsResult" - description: <SchemaDefinition schemaRef="#/components/schemas/PaginatedRowsResult"
/> />
name: PaginatedRowsResult name: PaginatedRowsResult
- description: <SchemaDefinition schemaRef="#/components/schemas/ParamType" />
name: ParamType
- description: <SchemaDefinition schemaRef="#/components/schemas/PhotogenToolDefinition" - description: <SchemaDefinition schemaRef="#/components/schemas/PhotogenToolDefinition"
/> />
name: PhotogenToolDefinition name: PhotogenToolDefinition
@ -5521,6 +5197,9 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/SystemMessage" /> - description: <SchemaDefinition schemaRef="#/components/schemas/SystemMessage" />
name: SystemMessage name: SystemMessage
- name: Telemetry - name: Telemetry
- description: <SchemaDefinition schemaRef="#/components/schemas/TextContentItem"
/>
name: TextContentItem
- description: <SchemaDefinition schemaRef="#/components/schemas/TokenLogProbs" /> - description: <SchemaDefinition schemaRef="#/components/schemas/TokenLogProbs" />
name: TokenLogProbs name: TokenLogProbs
- description: <SchemaDefinition schemaRef="#/components/schemas/ToolCall" /> - description: <SchemaDefinition schemaRef="#/components/schemas/ToolCall" />
@ -5670,9 +5349,11 @@ x-tagGroups:
- GraphMemoryBank - GraphMemoryBank
- GraphMemoryBankParams - GraphMemoryBankParams
- HealthInfo - HealthInfo
- ImageMedia - ImageContentItem
- InferenceStep - InferenceStep
- InsertDocumentsRequest - InsertDocumentsRequest
- InterleavedContent
- InterleavedContentItem
- Job - Job
- JobCancelRequest - JobCancelRequest
- JobStatus - JobStatus
@ -5694,6 +5375,7 @@ x-tagGroups:
- OptimizerConfig - OptimizerConfig
- OptimizerType - OptimizerType
- PaginatedRowsResult - PaginatedRowsResult
- ParamType
- PhotogenToolDefinition - PhotogenToolDefinition
- PostTrainingJob - PostTrainingJob
- PostTrainingJobArtifactsResponse - PostTrainingJobArtifactsResponse
@ -5745,6 +5427,7 @@ x-tagGroups:
- SyntheticDataGenerateRequest - SyntheticDataGenerateRequest
- SyntheticDataGenerationResponse - SyntheticDataGenerationResponse
- SystemMessage - SystemMessage
- TextContentItem
- TokenLogProbs - TokenLogProbs
- ToolCall - ToolCall
- ToolCallDelta - ToolCallDelta

View file

@ -6,6 +6,7 @@
from typing import Literal, Union from typing import Literal, Union
from llama_models.schema_utils import register_schema
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from typing_extensions import Annotated from typing_extensions import Annotated
@ -53,21 +54,24 @@ class AgentTurnInputType(BaseModel):
type: Literal["agent_turn_input"] = "agent_turn_input" type: Literal["agent_turn_input"] = "agent_turn_input"
ParamType = Annotated[ ParamType = register_schema(
Union[ Annotated[
StringType, Union[
NumberType, StringType,
BooleanType, NumberType,
ArrayType, BooleanType,
ObjectType, ArrayType,
JsonType, ObjectType,
UnionType, JsonType,
ChatCompletionInputType, UnionType,
CompletionInputType, ChatCompletionInputType,
AgentTurnInputType, CompletionInputType,
AgentTurnInputType,
],
Field(discriminator="type"),
], ],
Field(discriminator="type"), name="ParamType",
] )
# TODO: recursive definition of ParamType in these containers # TODO: recursive definition of ParamType in these containers
# will cause infinite recursion in OpenAPI generation script # will cause infinite recursion in OpenAPI generation script

View file

@ -25,7 +25,7 @@ from llama_models.llama3.api.datatypes import (
ToolPromptFormat, 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 pydantic import BaseModel, Field, field_validator
from typing_extensions import Annotated from typing_extensions import Annotated
@ -82,13 +82,19 @@ class TextContentItem(BaseModel):
# other modalities can be added here # other modalities can be added here
InterleavedContentItem = Annotated[ InterleavedContentItem = register_schema(
Union[ImageContentItem, TextContentItem], Annotated[
Field(discriminator="type"), Union[ImageContentItem, TextContentItem],
] Field(discriminator="type"),
],
name="InterleavedContentItem",
)
# accept a single "str" as a special case since it is common # 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 @json_schema_type

View file

@ -36,7 +36,7 @@ def interpret_content_as_attachment(content: str) -> Optional[Attachment]:
snippet = match.group(1) snippet = match.group(1)
data = json.loads(snippet) data = json.loads(snippet)
return Attachment( return Attachment(
content=URL(uri="file://" + data["filepath"]), mime_type=data["mimetype"] url=URL(uri="file://" + data["filepath"]), mime_type=data["mimetype"]
) )
return None return None