Register Message and ResponseFormat

This commit is contained in:
Ashwin Bharambe 2024-12-18 10:32:25 -08:00
parent ceadaf1840
commit 12cbed1617
3 changed files with 195 additions and 335 deletions

View file

@ -2598,6 +2598,22 @@
} }
] ]
}, },
"Message": {
"oneOf": [
{
"$ref": "#/components/schemas/UserMessage"
},
{
"$ref": "#/components/schemas/SystemMessage"
},
{
"$ref": "#/components/schemas/ToolResponseMessage"
},
{
"$ref": "#/components/schemas/CompletionMessage"
}
]
},
"SamplingParams": { "SamplingParams": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -2936,20 +2952,7 @@
"items": { "items": {
"type": "array", "type": "array",
"items": { "items": {
"oneOf": [ "$ref": "#/components/schemas/Message"
{
"$ref": "#/components/schemas/UserMessage"
},
{
"$ref": "#/components/schemas/SystemMessage"
},
{
"$ref": "#/components/schemas/ToolResponseMessage"
},
{
"$ref": "#/components/schemas/CompletionMessage"
}
]
} }
} }
}, },
@ -3059,6 +3062,90 @@
"job_uuid" "job_uuid"
] ]
}, },
"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"
]
},
{
"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"
]
}
]
},
"ChatCompletionRequest": { "ChatCompletionRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3068,20 +3155,7 @@
"messages": { "messages": {
"type": "array", "type": "array",
"items": { "items": {
"oneOf": [ "$ref": "#/components/schemas/Message"
{
"$ref": "#/components/schemas/UserMessage"
},
{
"$ref": "#/components/schemas/SystemMessage"
},
{
"$ref": "#/components/schemas/ToolResponseMessage"
},
{
"$ref": "#/components/schemas/CompletionMessage"
}
]
} }
}, },
"sampling_params": { "sampling_params": {
@ -3100,88 +3174,7 @@
"$ref": "#/components/schemas/ToolPromptFormat" "$ref": "#/components/schemas/ToolPromptFormat"
}, },
"response_format": { "response_format": {
"oneOf": [ "$ref": "#/components/schemas/ResponseFormat"
{
"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"
]
},
{
"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"
]
}
]
}, },
"stream": { "stream": {
"type": "boolean" "type": "boolean"
@ -3336,88 +3329,7 @@
"$ref": "#/components/schemas/SamplingParams" "$ref": "#/components/schemas/SamplingParams"
}, },
"response_format": { "response_format": {
"oneOf": [ "$ref": "#/components/schemas/ResponseFormat"
{
"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"
]
},
{
"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"
]
}
]
}, },
"stream": { "stream": {
"type": "boolean" "type": "boolean"
@ -7285,20 +7197,7 @@
"messages": { "messages": {
"type": "array", "type": "array",
"items": { "items": {
"oneOf": [ "$ref": "#/components/schemas/Message"
{
"$ref": "#/components/schemas/UserMessage"
},
{
"$ref": "#/components/schemas/SystemMessage"
},
{
"$ref": "#/components/schemas/ToolResponseMessage"
},
{
"$ref": "#/components/schemas/CompletionMessage"
}
]
} }
}, },
"params": { "params": {
@ -7664,20 +7563,7 @@
"dialogs": { "dialogs": {
"type": "array", "type": "array",
"items": { "items": {
"oneOf": [ "$ref": "#/components/schemas/Message"
{
"$ref": "#/components/schemas/UserMessage"
},
{
"$ref": "#/components/schemas/SystemMessage"
},
{
"$ref": "#/components/schemas/ToolResponseMessage"
},
{
"$ref": "#/components/schemas/CompletionMessage"
}
]
} }
}, },
"filtering_function": { "filtering_function": {
@ -8136,6 +8022,10 @@
"name": "MemoryToolDefinition", "name": "MemoryToolDefinition",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/MemoryToolDefinition\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/MemoryToolDefinition\" />"
}, },
{
"name": "Message",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/Message\" />"
},
{ {
"name": "MetricEvent", "name": "MetricEvent",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/MetricEvent\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/MetricEvent\" />"
@ -8254,6 +8144,10 @@
"name": "RegisterShieldRequest", "name": "RegisterShieldRequest",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/RegisterShieldRequest\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/RegisterShieldRequest\" />"
}, },
{
"name": "ResponseFormat",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/ResponseFormat\" />"
},
{ {
"name": "RestAPIExecutionConfig", "name": "RestAPIExecutionConfig",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/RestAPIExecutionConfig\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/RestAPIExecutionConfig\" />"
@ -8598,6 +8492,7 @@
"MemoryBankDocument", "MemoryBankDocument",
"MemoryRetrievalStep", "MemoryRetrievalStep",
"MemoryToolDefinition", "MemoryToolDefinition",
"Message",
"MetricEvent", "MetricEvent",
"Model", "Model",
"ModelCandidate", "ModelCandidate",
@ -8626,6 +8521,7 @@
"RegisterModelRequest", "RegisterModelRequest",
"RegisterScoringFunctionRequest", "RegisterScoringFunctionRequest",
"RegisterShieldRequest", "RegisterShieldRequest",
"ResponseFormat",
"RestAPIExecutionConfig", "RestAPIExecutionConfig",
"RestAPIMethod", "RestAPIMethod",
"RouteInfo", "RouteInfo",

View file

@ -313,11 +313,7 @@ components:
messages_batch: messages_batch:
items: items:
items: items:
oneOf: $ref: '#/components/schemas/Message'
- $ref: '#/components/schemas/UserMessage'
- $ref: '#/components/schemas/SystemMessage'
- $ref: '#/components/schemas/ToolResponseMessage'
- $ref: '#/components/schemas/CompletionMessage'
type: array type: array
type: array type: array
model: model:
@ -422,56 +418,12 @@ components:
type: object type: object
messages: messages:
items: items:
oneOf: $ref: '#/components/schemas/Message'
- $ref: '#/components/schemas/UserMessage'
- $ref: '#/components/schemas/SystemMessage'
- $ref: '#/components/schemas/ToolResponseMessage'
- $ref: '#/components/schemas/CompletionMessage'
type: array type: array
model_id: model_id:
type: string type: string
response_format: response_format:
oneOf: $ref: '#/components/schemas/ResponseFormat'
- 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
sampling_params: sampling_params:
$ref: '#/components/schemas/SamplingParams' $ref: '#/components/schemas/SamplingParams'
stream: stream:
@ -598,47 +550,7 @@ components:
model_id: model_id:
type: string type: string
response_format: response_format:
oneOf: $ref: '#/components/schemas/ResponseFormat'
- 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
sampling_params: sampling_params:
$ref: '#/components/schemas/SamplingParams' $ref: '#/components/schemas/SamplingParams'
stream: stream:
@ -1467,6 +1379,12 @@ components:
- max_tokens_in_context - max_tokens_in_context
- max_chunks - max_chunks
type: object type: object
Message:
oneOf:
- $ref: '#/components/schemas/UserMessage'
- $ref: '#/components/schemas/SystemMessage'
- $ref: '#/components/schemas/ToolResponseMessage'
- $ref: '#/components/schemas/CompletionMessage'
MetricEvent: MetricEvent:
additionalProperties: false additionalProperties: false
properties: properties:
@ -2121,6 +2039,48 @@ components:
required: required:
- shield_id - shield_id
type: object type: object
ResponseFormat:
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
RestAPIExecutionConfig: RestAPIExecutionConfig:
additionalProperties: false additionalProperties: false
properties: properties:
@ -2203,11 +2163,7 @@ components:
properties: properties:
messages: messages:
items: items:
oneOf: $ref: '#/components/schemas/Message'
- $ref: '#/components/schemas/UserMessage'
- $ref: '#/components/schemas/SystemMessage'
- $ref: '#/components/schemas/ToolResponseMessage'
- $ref: '#/components/schemas/CompletionMessage'
type: array type: array
params: params:
additionalProperties: additionalProperties:
@ -2744,11 +2700,7 @@ components:
properties: properties:
dialogs: dialogs:
items: items:
oneOf: $ref: '#/components/schemas/Message'
- $ref: '#/components/schemas/UserMessage'
- $ref: '#/components/schemas/SystemMessage'
- $ref: '#/components/schemas/ToolResponseMessage'
- $ref: '#/components/schemas/CompletionMessage'
type: array type: array
filtering_function: filtering_function:
enum: enum:
@ -5024,6 +4976,8 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/MemoryToolDefinition" - description: <SchemaDefinition schemaRef="#/components/schemas/MemoryToolDefinition"
/> />
name: MemoryToolDefinition name: MemoryToolDefinition
- description: <SchemaDefinition schemaRef="#/components/schemas/Message" />
name: Message
- description: <SchemaDefinition schemaRef="#/components/schemas/MetricEvent" /> - description: <SchemaDefinition schemaRef="#/components/schemas/MetricEvent" />
name: MetricEvent name: MetricEvent
- description: <SchemaDefinition schemaRef="#/components/schemas/Model" /> - description: <SchemaDefinition schemaRef="#/components/schemas/Model" />
@ -5108,6 +5062,8 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/RegisterShieldRequest" - description: <SchemaDefinition schemaRef="#/components/schemas/RegisterShieldRequest"
/> />
name: RegisterShieldRequest name: RegisterShieldRequest
- description: <SchemaDefinition schemaRef="#/components/schemas/ResponseFormat" />
name: ResponseFormat
- description: <SchemaDefinition schemaRef="#/components/schemas/RestAPIExecutionConfig" - description: <SchemaDefinition schemaRef="#/components/schemas/RestAPIExecutionConfig"
/> />
name: RestAPIExecutionConfig name: RestAPIExecutionConfig
@ -5371,6 +5327,7 @@ x-tagGroups:
- MemoryBankDocument - MemoryBankDocument
- MemoryRetrievalStep - MemoryRetrievalStep
- MemoryToolDefinition - MemoryToolDefinition
- Message
- MetricEvent - MetricEvent
- Model - Model
- ModelCandidate - ModelCandidate
@ -5399,6 +5356,7 @@ x-tagGroups:
- RegisterModelRequest - RegisterModelRequest
- RegisterScoringFunctionRequest - RegisterScoringFunctionRequest
- RegisterShieldRequest - RegisterShieldRequest
- ResponseFormat
- RestAPIExecutionConfig - RestAPIExecutionConfig
- RestAPIMethod - RestAPIMethod
- RouteInfo - RouteInfo

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
@ -100,15 +100,18 @@ class CompletionMessage(BaseModel):
tool_calls: List[ToolCall] = Field(default_factory=list) tool_calls: List[ToolCall] = Field(default_factory=list)
Message = Annotated[ Message = register_schema(
Union[ Annotated[
UserMessage, Union[
SystemMessage, UserMessage,
ToolResponseMessage, SystemMessage,
CompletionMessage, ToolResponseMessage,
CompletionMessage,
],
Field(discriminator="role"),
], ],
Field(discriminator="role"), name="Message",
] )
@json_schema_type @json_schema_type
@ -187,10 +190,13 @@ class GrammarResponseFormat(BaseModel):
bnf: Dict[str, Any] bnf: Dict[str, Any]
ResponseFormat = Annotated[ ResponseFormat = register_schema(
Union[JsonSchemaResponseFormat, GrammarResponseFormat], Annotated[
Field(discriminator="type"), Union[JsonSchemaResponseFormat, GrammarResponseFormat],
] Field(discriminator="type"),
],
name="ResponseFormat",
)
@json_schema_type @json_schema_type