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
# (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

File diff suppressed because it is too large Load diff

View file

@ -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:
- contentEncoding: base64
type: string
format_description:
type: string
title: This class represents an image object. To create
type: object
- $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: <SchemaDefinition schemaRef="#/components/schemas/HealthInfo" />
name: HealthInfo
- description: <SchemaDefinition schemaRef="#/components/schemas/ImageMedia" />
name: ImageMedia
- description: <SchemaDefinition schemaRef="#/components/schemas/ImageContentItem"
/>
name: ImageContentItem
- name: Inference
- description: <SchemaDefinition schemaRef="#/components/schemas/InferenceStep" />
name: InferenceStep
@ -5306,6 +4974,12 @@ tags:
/>
name: InsertDocumentsRequest
- name: Inspect
- description: <SchemaDefinition schemaRef="#/components/schemas/InterleavedContent"
/>
name: InterleavedContent
- description: <SchemaDefinition schemaRef="#/components/schemas/InterleavedContentItem"
/>
name: InterleavedContentItem
- description: <SchemaDefinition schemaRef="#/components/schemas/Job" />
name: Job
- description: <SchemaDefinition schemaRef="#/components/schemas/JobCancelRequest"
@ -5364,6 +5038,8 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/PaginatedRowsResult"
/>
name: PaginatedRowsResult
- description: <SchemaDefinition schemaRef="#/components/schemas/ParamType" />
name: ParamType
- description: <SchemaDefinition schemaRef="#/components/schemas/PhotogenToolDefinition"
/>
name: PhotogenToolDefinition
@ -5521,6 +5197,9 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/SystemMessage" />
name: SystemMessage
- name: Telemetry
- description: <SchemaDefinition schemaRef="#/components/schemas/TextContentItem"
/>
name: TextContentItem
- description: <SchemaDefinition schemaRef="#/components/schemas/TokenLogProbs" />
name: TokenLogProbs
- description: <SchemaDefinition schemaRef="#/components/schemas/ToolCall" />
@ -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

View file

@ -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,7 +54,8 @@ class AgentTurnInputType(BaseModel):
type: Literal["agent_turn_input"] = "agent_turn_input"
ParamType = Annotated[
ParamType = register_schema(
Annotated[
Union[
StringType,
NumberType,
@ -67,7 +69,9 @@ ParamType = Annotated[
AgentTurnInputType,
],
Field(discriminator="type"),
]
],
name="ParamType",
)
# TODO: recursive definition of ParamType in these containers
# will cause infinite recursion in OpenAPI generation script

View file

@ -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[
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

View file

@ -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