add safety to openapi spec (#62)

This commit is contained in:
Xi Yan 2024-09-10 17:47:13 -07:00 committed by GitHub
parent a11d92601b
commit 58def874a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 365 additions and 94 deletions

View file

@ -15,6 +15,7 @@ from llama_toolchain.telemetry.api import * # noqa: F403
from llama_toolchain.post_training.api import * # noqa: F403 from llama_toolchain.post_training.api import * # noqa: F403
from llama_toolchain.reward_scoring.api import * # noqa: F403 from llama_toolchain.reward_scoring.api import * # noqa: F403
from llama_toolchain.synthetic_data_generation.api import * # noqa: F403 from llama_toolchain.synthetic_data_generation.api import * # noqa: F403
from llama_toolchain.safety.api import * # noqa: F403
class LlamaStack( class LlamaStack(
@ -22,6 +23,7 @@ class LlamaStack(
BatchInference, BatchInference,
AgenticSystem, AgenticSystem,
RewardScoring, RewardScoring,
Safety,
SyntheticDataGeneration, SyntheticDataGeneration,
Datasets, Datasets,
Telemetry, Telemetry,

View file

@ -21,7 +21,7 @@
"info": { "info": {
"title": "[DRAFT] Llama Stack Specification", "title": "[DRAFT] Llama Stack Specification",
"version": "0.0.1", "version": "0.0.1",
"description": "This is the specification of the llama stack that provides\n a set of endpoints and their corresponding interfaces that are tailored to\n best leverage Llama Models. The specification is still in draft and subject to change.\n Generated at 2024-09-10 01:13:08.531639" "description": "This is the specification of the llama stack that provides\n a set of endpoints and their corresponding interfaces that are tailored to\n best leverage Llama Models. The specification is still in draft and subject to change.\n Generated at 2024-09-10 16:42:15.870336"
}, },
"servers": [ "servers": [
{ {
@ -1433,6 +1433,36 @@
} }
} }
}, },
"/safety/run_shields": {
"post": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunShieldResponse"
}
}
}
}
},
"tags": [
"Safety"
],
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RunShieldRequestWrapper"
}
}
},
"required": true
}
}
},
"/post_training/supervised_fine_tune": { "/post_training/supervised_fine_tune": {
"post": { "post": {
"responses": { "responses": {
@ -2409,7 +2439,7 @@
"items": { "items": {
"oneOf": [ "oneOf": [
{ {
"$ref": "#/components/schemas/BraveSearchToolDefinition" "$ref": "#/components/schemas/SearchToolDefinition"
}, },
{ {
"$ref": "#/components/schemas/WolframAlphaToolDefinition" "$ref": "#/components/schemas/WolframAlphaToolDefinition"
@ -2624,34 +2654,6 @@
"instructions" "instructions"
] ]
}, },
"BraveSearchToolDefinition": {
"type": "object",
"properties": {
"input_shields": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ShieldDefinition"
}
},
"output_shields": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ShieldDefinition"
}
},
"type": {
"type": "string",
"const": "brave_search"
},
"remote_execution": {
"$ref": "#/components/schemas/RestAPIExecutionConfig"
}
},
"additionalProperties": false,
"required": [
"type"
]
},
"BuiltinShield": { "BuiltinShield": {
"type": "string", "type": "string",
"enum": [ "enum": [
@ -2785,19 +2787,76 @@
"params": { "params": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"type": "string" "oneOf": [
{
"type": "null"
},
{
"type": "boolean"
},
{
"type": "number"
},
{
"type": "string"
},
{
"type": "array"
},
{
"type": "object"
}
]
} }
}, },
"headers": { "headers": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"type": "string" "oneOf": [
{
"type": "null"
},
{
"type": "boolean"
},
{
"type": "number"
},
{
"type": "string"
},
{
"type": "array"
},
{
"type": "object"
}
]
} }
}, },
"body": { "body": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"type": "string" "oneOf": [
{
"type": "null"
},
{
"type": "boolean"
},
{
"type": "number"
},
{
"type": "string"
},
{
"type": "array"
},
{
"type": "object"
}
]
} }
} }
}, },
@ -2816,6 +2875,42 @@
"DELETE" "DELETE"
] ]
}, },
"SearchToolDefinition": {
"type": "object",
"properties": {
"input_shields": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ShieldDefinition"
}
},
"output_shields": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ShieldDefinition"
}
},
"type": {
"type": "string",
"const": "brave_search"
},
"engine": {
"type": "string",
"enum": [
"bing",
"brave"
]
},
"remote_execution": {
"$ref": "#/components/schemas/RestAPIExecutionConfig"
}
},
"additionalProperties": false,
"required": [
"type",
"engine"
]
},
"ShieldDefinition": { "ShieldDefinition": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -2959,7 +3054,7 @@
"items": { "items": {
"oneOf": [ "oneOf": [
{ {
"$ref": "#/components/schemas/BraveSearchToolDefinition" "$ref": "#/components/schemas/SearchToolDefinition"
}, },
{ {
"$ref": "#/components/schemas/WolframAlphaToolDefinition" "$ref": "#/components/schemas/WolframAlphaToolDefinition"
@ -5549,6 +5644,68 @@
"score" "score"
] ]
}, },
"RunShieldRequest": {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/UserMessage"
},
{
"$ref": "#/components/schemas/SystemMessage"
},
{
"$ref": "#/components/schemas/ToolResponseMessage"
},
{
"$ref": "#/components/schemas/CompletionMessage"
}
]
}
},
"shields": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ShieldDefinition"
}
}
},
"additionalProperties": false,
"required": [
"messages",
"shields"
]
},
"RunShieldRequestWrapper": {
"type": "object",
"properties": {
"request": {
"$ref": "#/components/schemas/RunShieldRequest"
}
},
"additionalProperties": false,
"required": [
"request"
]
},
"RunShieldResponse": {
"type": "object",
"properties": {
"responses": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ShieldResponse"
}
}
},
"additionalProperties": false,
"required": [
"responses"
]
},
"DoraFinetuningConfig": { "DoraFinetuningConfig": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -6062,36 +6219,39 @@
} }
], ],
"tags": [ "tags": [
{
"name": "SyntheticDataGeneration"
},
{
"name": "RewardScoring"
},
{
"name": "Datasets"
},
{
"name": "Memory"
},
{
"name": "AgenticSystem"
},
{ {
"name": "BatchInference" "name": "BatchInference"
}, },
{ {
"name": "PostTraining" "name": "Safety"
},
{
"name": "Evaluations"
}, },
{ {
"name": "Telemetry" "name": "Telemetry"
}, },
{
"name": "RewardScoring"
},
{
"name": "Memory"
},
{
"name": "SyntheticDataGeneration"
},
{ {
"name": "Inference" "name": "Inference"
}, },
{
"name": "Evaluations"
},
{
"name": "PostTraining"
},
{
"name": "Datasets"
},
{
"name": "AgenticSystem"
},
{ {
"name": "BatchChatCompletionRequest", "name": "BatchChatCompletionRequest",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/BatchChatCompletionRequest\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/BatchChatCompletionRequest\" />"
@ -6224,10 +6384,6 @@
"name": "AgentConfig", "name": "AgentConfig",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentConfig\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/AgentConfig\" />"
}, },
{
"name": "BraveSearchToolDefinition",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/BraveSearchToolDefinition\" />"
},
{ {
"name": "BuiltinShield", "name": "BuiltinShield",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/BuiltinShield\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/BuiltinShield\" />"
@ -6256,6 +6412,10 @@
"name": "RestAPIMethod", "name": "RestAPIMethod",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/RestAPIMethod\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/RestAPIMethod\" />"
}, },
{
"name": "SearchToolDefinition",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/SearchToolDefinition\" />"
},
{ {
"name": "ShieldDefinition", "name": "ShieldDefinition",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/ShieldDefinition\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/ShieldDefinition\" />"
@ -6620,6 +6780,18 @@
"name": "ScoredMessage", "name": "ScoredMessage",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/ScoredMessage\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/ScoredMessage\" />"
}, },
{
"name": "RunShieldRequest",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/RunShieldRequest\" />"
},
{
"name": "RunShieldRequestWrapper",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/RunShieldRequestWrapper\" />"
},
{
"name": "RunShieldResponse",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/RunShieldResponse\" />"
},
{ {
"name": "DoraFinetuningConfig", "name": "DoraFinetuningConfig",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/DoraFinetuningConfig\" />" "description": "<SchemaDefinition schemaRef=\"#/components/schemas/DoraFinetuningConfig\" />"
@ -6697,6 +6869,7 @@
"Memory", "Memory",
"PostTraining", "PostTraining",
"RewardScoring", "RewardScoring",
"Safety",
"SyntheticDataGeneration", "SyntheticDataGeneration",
"Telemetry" "Telemetry"
] ]
@ -6726,7 +6899,6 @@
"BatchCompletionRequest", "BatchCompletionRequest",
"BatchCompletionRequestWrapper", "BatchCompletionRequestWrapper",
"BatchCompletionResponse", "BatchCompletionResponse",
"BraveSearchToolDefinition",
"BuiltinShield", "BuiltinShield",
"BuiltinTool", "BuiltinTool",
"CancelEvaluationJobRequest", "CancelEvaluationJobRequest",
@ -6814,10 +6986,14 @@
"RewardScoringRequestWrapper", "RewardScoringRequestWrapper",
"RewardScoringResponse", "RewardScoringResponse",
"Run", "Run",
"RunShieldRequest",
"RunShieldRequestWrapper",
"RunShieldResponse",
"SamplingParams", "SamplingParams",
"SamplingStrategy", "SamplingStrategy",
"ScoredDialogGenerations", "ScoredDialogGenerations",
"ScoredMessage", "ScoredMessage",
"SearchToolDefinition",
"Session", "Session",
"ShieldCallStep", "ShieldCallStep",
"ShieldDefinition", "ShieldDefinition",

View file

@ -25,7 +25,7 @@ components:
tools: tools:
items: items:
oneOf: oneOf:
- $ref: '#/components/schemas/BraveSearchToolDefinition' - $ref: '#/components/schemas/SearchToolDefinition'
- $ref: '#/components/schemas/WolframAlphaToolDefinition' - $ref: '#/components/schemas/WolframAlphaToolDefinition'
- $ref: '#/components/schemas/PhotogenToolDefinition' - $ref: '#/components/schemas/PhotogenToolDefinition'
- $ref: '#/components/schemas/CodeInterpreterToolDefinition' - $ref: '#/components/schemas/CodeInterpreterToolDefinition'
@ -218,7 +218,7 @@ components:
tools: tools:
items: items:
oneOf: oneOf:
- $ref: '#/components/schemas/BraveSearchToolDefinition' - $ref: '#/components/schemas/SearchToolDefinition'
- $ref: '#/components/schemas/WolframAlphaToolDefinition' - $ref: '#/components/schemas/WolframAlphaToolDefinition'
- $ref: '#/components/schemas/PhotogenToolDefinition' - $ref: '#/components/schemas/PhotogenToolDefinition'
- $ref: '#/components/schemas/CodeInterpreterToolDefinition' - $ref: '#/components/schemas/CodeInterpreterToolDefinition'
@ -635,25 +635,6 @@ components:
required: required:
- completion_message_batch - completion_message_batch
type: object type: object
BraveSearchToolDefinition:
additionalProperties: false
properties:
input_shields:
items:
$ref: '#/components/schemas/ShieldDefinition'
type: array
output_shields:
items:
$ref: '#/components/schemas/ShieldDefinition'
type: array
remote_execution:
$ref: '#/components/schemas/RestAPIExecutionConfig'
type:
const: brave_search
type: string
required:
- type
type: object
BuiltinShield: BuiltinShield:
enum: enum:
- llama_guard - llama_guard
@ -2011,17 +1992,35 @@ components:
properties: properties:
body: body:
additionalProperties: additionalProperties:
type: string oneOf:
- type: 'null'
- type: boolean
- type: number
- type: string
- type: array
- type: object
type: object type: object
headers: headers:
additionalProperties: additionalProperties:
type: string oneOf:
- type: 'null'
- type: boolean
- type: number
- type: string
- type: array
- type: object
type: object type: object
method: method:
$ref: '#/components/schemas/RestAPIMethod' $ref: '#/components/schemas/RestAPIMethod'
params: params:
additionalProperties: additionalProperties:
type: string oneOf:
- type: 'null'
- type: boolean
- type: number
- type: string
- type: array
- type: object
type: object type: object
url: url:
$ref: '#/components/schemas/URL' $ref: '#/components/schemas/URL'
@ -2103,6 +2102,43 @@ components:
- started_at - started_at
- metadata - metadata
type: object type: object
RunShieldRequest:
additionalProperties: false
properties:
messages:
items:
oneOf:
- $ref: '#/components/schemas/UserMessage'
- $ref: '#/components/schemas/SystemMessage'
- $ref: '#/components/schemas/ToolResponseMessage'
- $ref: '#/components/schemas/CompletionMessage'
type: array
shields:
items:
$ref: '#/components/schemas/ShieldDefinition'
type: array
required:
- messages
- shields
type: object
RunShieldRequestWrapper:
additionalProperties: false
properties:
request:
$ref: '#/components/schemas/RunShieldRequest'
required:
- request
type: object
RunShieldResponse:
additionalProperties: false
properties:
responses:
items:
$ref: '#/components/schemas/ShieldResponse'
type: array
required:
- responses
type: object
SamplingParams: SamplingParams:
additionalProperties: false additionalProperties: false
properties: properties:
@ -2161,6 +2197,31 @@ components:
- message - message
- score - score
type: object type: object
SearchToolDefinition:
additionalProperties: false
properties:
engine:
enum:
- bing
- brave
type: string
input_shields:
items:
$ref: '#/components/schemas/ShieldDefinition'
type: array
output_shields:
items:
$ref: '#/components/schemas/ShieldDefinition'
type: array
remote_execution:
$ref: '#/components/schemas/RestAPIExecutionConfig'
type:
const: brave_search
type: string
required:
- type
- engine
type: object
Session: Session:
additionalProperties: false additionalProperties: false
properties: properties:
@ -2777,7 +2838,7 @@ info:
description: "This is the specification of the llama stack that provides\n \ description: "This is the specification of the llama stack that provides\n \
\ a set of endpoints and their corresponding interfaces that are tailored\ \ a set of endpoints and their corresponding interfaces that are tailored\
\ to\n best leverage Llama Models. The specification is still in\ \ to\n best leverage Llama Models. The specification is still in\
\ draft and subject to change.\n Generated at 2024-09-10 01:13:08.531639" \ draft and subject to change.\n Generated at 2024-09-10 16:42:15.870336"
title: '[DRAFT] Llama Stack Specification' title: '[DRAFT] Llama Stack Specification'
version: 0.0.1 version: 0.0.1
jsonSchemaDialect: https://json-schema.org/draft/2020-12/schema jsonSchemaDialect: https://json-schema.org/draft/2020-12/schema
@ -3706,6 +3767,24 @@ paths:
description: OK description: OK
tags: tags:
- Telemetry - Telemetry
/safety/run_shields:
post:
parameters: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/RunShieldRequestWrapper'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/RunShieldResponse'
description: OK
tags:
- Safety
/synthetic_data_generation/generate: /synthetic_data_generation/generate:
post: post:
parameters: [] parameters: []
@ -3729,16 +3808,17 @@ security:
servers: servers:
- url: http://any-hosted-llama-stack.com - url: http://any-hosted-llama-stack.com
tags: tags:
- name: SyntheticDataGeneration
- name: RewardScoring
- name: Datasets
- name: Memory
- name: AgenticSystem
- name: BatchInference - name: BatchInference
- name: PostTraining - name: Safety
- name: Evaluations
- name: Telemetry - name: Telemetry
- name: RewardScoring
- name: Memory
- name: SyntheticDataGeneration
- name: Inference - name: Inference
- name: Evaluations
- name: PostTraining
- name: Datasets
- name: AgenticSystem
- description: <SchemaDefinition schemaRef="#/components/schemas/BatchChatCompletionRequest" - description: <SchemaDefinition schemaRef="#/components/schemas/BatchChatCompletionRequest"
/> />
name: BatchChatCompletionRequest name: BatchChatCompletionRequest
@ -3844,9 +3924,6 @@ tags:
name: CompletionResponseStreamChunk name: CompletionResponseStreamChunk
- description: <SchemaDefinition schemaRef="#/components/schemas/AgentConfig" /> - description: <SchemaDefinition schemaRef="#/components/schemas/AgentConfig" />
name: AgentConfig name: AgentConfig
- description: <SchemaDefinition schemaRef="#/components/schemas/BraveSearchToolDefinition"
/>
name: BraveSearchToolDefinition
- description: <SchemaDefinition schemaRef="#/components/schemas/BuiltinShield" /> - description: <SchemaDefinition schemaRef="#/components/schemas/BuiltinShield" />
name: BuiltinShield name: BuiltinShield
- description: <SchemaDefinition schemaRef="#/components/schemas/CodeInterpreterToolDefinition" - description: <SchemaDefinition schemaRef="#/components/schemas/CodeInterpreterToolDefinition"
@ -3866,6 +3943,9 @@ tags:
name: RestAPIExecutionConfig name: RestAPIExecutionConfig
- description: <SchemaDefinition schemaRef="#/components/schemas/RestAPIMethod" /> - description: <SchemaDefinition schemaRef="#/components/schemas/RestAPIMethod" />
name: RestAPIMethod name: RestAPIMethod
- description: <SchemaDefinition schemaRef="#/components/schemas/SearchToolDefinition"
/>
name: SearchToolDefinition
- description: <SchemaDefinition schemaRef="#/components/schemas/ShieldDefinition" - description: <SchemaDefinition schemaRef="#/components/schemas/ShieldDefinition"
/> />
name: ShieldDefinition name: ShieldDefinition
@ -4163,6 +4243,15 @@ tags:
name: ScoredDialogGenerations name: ScoredDialogGenerations
- description: <SchemaDefinition schemaRef="#/components/schemas/ScoredMessage" /> - description: <SchemaDefinition schemaRef="#/components/schemas/ScoredMessage" />
name: ScoredMessage name: ScoredMessage
- description: <SchemaDefinition schemaRef="#/components/schemas/RunShieldRequest"
/>
name: RunShieldRequest
- description: <SchemaDefinition schemaRef="#/components/schemas/RunShieldRequestWrapper"
/>
name: RunShieldRequestWrapper
- description: <SchemaDefinition schemaRef="#/components/schemas/RunShieldResponse"
/>
name: RunShieldResponse
- description: <SchemaDefinition schemaRef="#/components/schemas/DoraFinetuningConfig" - description: <SchemaDefinition schemaRef="#/components/schemas/DoraFinetuningConfig"
/> />
name: DoraFinetuningConfig name: DoraFinetuningConfig
@ -4232,6 +4321,7 @@ x-tagGroups:
- Memory - Memory
- PostTraining - PostTraining
- RewardScoring - RewardScoring
- Safety
- SyntheticDataGeneration - SyntheticDataGeneration
- Telemetry - Telemetry
- name: Types - name: Types
@ -4258,7 +4348,6 @@ x-tagGroups:
- BatchCompletionRequest - BatchCompletionRequest
- BatchCompletionRequestWrapper - BatchCompletionRequestWrapper
- BatchCompletionResponse - BatchCompletionResponse
- BraveSearchToolDefinition
- BuiltinShield - BuiltinShield
- BuiltinTool - BuiltinTool
- CancelEvaluationJobRequest - CancelEvaluationJobRequest
@ -4346,10 +4435,14 @@ x-tagGroups:
- RewardScoringRequestWrapper - RewardScoringRequestWrapper
- RewardScoringResponse - RewardScoringResponse
- Run - Run
- RunShieldRequest
- RunShieldRequestWrapper
- RunShieldResponse
- SamplingParams - SamplingParams
- SamplingStrategy - SamplingStrategy
- ScoredDialogGenerations - ScoredDialogGenerations
- ScoredMessage - ScoredMessage
- SearchToolDefinition
- Session - Session
- ShieldCallStep - ShieldCallStep
- ShieldDefinition - ShieldDefinition