mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 02:53:30 +00:00
feat: openai files api (#2321)
# What does this PR do? * Adds the OpenAI compatible Files API * Modified doc gen script to support multipart parameter ## Test Plan --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/meta-llama/llama-stack/pull/2321). * #2330 * __->__ #2321
This commit is contained in:
parent
17f4414be9
commit
31a3ae60f4
6 changed files with 881 additions and 946 deletions
|
@ -30,6 +30,9 @@ from llama_stack.strong_typing.schema import (
|
|||
Schema,
|
||||
SchemaOptions,
|
||||
)
|
||||
from typing import get_origin, get_args
|
||||
from typing import Annotated
|
||||
from fastapi import UploadFile
|
||||
from llama_stack.strong_typing.serialization import json_dump_string, object_to_json
|
||||
|
||||
from .operations import (
|
||||
|
@ -618,6 +621,45 @@ class Generator:
|
|||
},
|
||||
required=True,
|
||||
)
|
||||
# data passed in request body as multipart/form-data
|
||||
elif op.multipart_params:
|
||||
builder = ContentBuilder(self.schema_builder)
|
||||
|
||||
# Create schema properties for multipart form fields
|
||||
properties = {}
|
||||
required_fields = []
|
||||
|
||||
for name, param_type in op.multipart_params:
|
||||
if get_origin(param_type) is Annotated:
|
||||
base_type = get_args(param_type)[0]
|
||||
else:
|
||||
base_type = param_type
|
||||
if base_type is UploadFile:
|
||||
# File upload
|
||||
properties[name] = {
|
||||
"type": "string",
|
||||
"format": "binary"
|
||||
}
|
||||
else:
|
||||
# Form field
|
||||
properties[name] = self.schema_builder.classdef_to_ref(base_type)
|
||||
|
||||
required_fields.append(name)
|
||||
|
||||
multipart_schema = {
|
||||
"type": "object",
|
||||
"properties": properties,
|
||||
"required": required_fields
|
||||
}
|
||||
|
||||
requestBody = RequestBody(
|
||||
content={
|
||||
"multipart/form-data": {
|
||||
"schema": multipart_schema
|
||||
}
|
||||
},
|
||||
required=True,
|
||||
)
|
||||
# data passed in payload as JSON and mapped to request parameters
|
||||
elif op.request_params:
|
||||
builder = ContentBuilder(self.schema_builder)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue