11import time
2+ import uuid
23
34from pydantic import BaseModel , Field , field_validator
4- from typing import Dict , List , Optional , Union , Literal
5- import uuid
5+ from typing import Any , Dict , List , Optional , Union , Literal
66
77
88class ImageURL (BaseModel ):
@@ -52,6 +52,21 @@ class StreamOptions(BaseModel):
5252 include_usage : Optional [bool ] = False
5353
5454
55+ class JsonSchemaResponseFormat (BaseModel ):
56+ name : str
57+ description : Optional [str ] = None
58+ # schema is the field in openai but that causes conflicts with pydantic so
59+ # instead use json_schema with an alias
60+ json_schema : Optional [dict [str , Any ]] = Field (default = None , alias = "schema" )
61+ strict : Optional [bool ] = None
62+
63+
64+ class ResponseFormat (BaseModel ):
65+ # type must be "json_schema", "json_object", or "text"
66+ type : Literal ["text" , "json_object" , "json_schema" ]
67+ json_schema : Optional [JsonSchemaResponseFormat ] = None
68+
69+
5570class CompletionRequest (BaseModel ):
5671 model : str
5772 # prompt: string or tokens
@@ -71,6 +86,14 @@ class CompletionRequest(BaseModel):
7186 best_of : Optional [int ] = 1
7287 logit_bias : Optional [Dict [str , float ]] = None
7388 user : Optional [str ] = None
89+ response_format : Optional [ResponseFormat ] = Field (
90+ default = None ,
91+ description = (
92+ "Similar to chat completion, this parameter specifies the format "
93+ "of output. Only {'type': 'json_object'}, {'type': 'json_schema'}"
94+ ", or {'type': 'text' } is supported."
95+ ),
96+ )
7497
7598 # Additional parameters supported by LightLLM
7699 do_sample : Optional [bool ] = False
@@ -94,7 +117,14 @@ class ChatCompletionRequest(BaseModel):
94117 frequency_penalty : Optional [float ] = 0.0
95118 logit_bias : Optional [Dict [str , float ]] = None
96119 user : Optional [str ] = None
97- response_format : Optional [Dict ] = None
120+ response_format : Optional [ResponseFormat ] = Field (
121+ default = None ,
122+ description = (
123+ "Similar to chat completion, this parameter specifies the format "
124+ "of output. Only {'type': 'json_object'}, {'type': 'json_schema'}"
125+ ", or {'type': 'text' } is supported."
126+ ),
127+ )
98128
99129 # OpenAI Adaptive parameters for tool call
100130 tools : Optional [List [Tool ]] = Field (default = None , examples = [None ])
0 commit comments