[Frontend] add json_schema support from OpenAI protocol (#7654)

This commit is contained in:
Tyler Rockwood
2024-08-24 01:07:24 -05:00
committed by GitHub
parent 8da48e4d95
commit d81abefd2e
4 changed files with 59 additions and 2 deletions

View File

@@ -85,9 +85,19 @@ class UsageInfo(OpenAIBaseModel):
completion_tokens: Optional[int] = 0
class JsonSchemaResponseFormat(OpenAIBaseModel):
name: str
description: Optional[str] = None
# schema is the field in openai but that causes conflicts with pydantic so
# instead use json_schema with an alias
json_schema: Optional[Dict[str, Any]] = Field(default=None, alias='schema')
strict: Optional[bool] = None
class ResponseFormat(OpenAIBaseModel):
# type must be "json_object" or "text"
type: Literal["text", "json_object"]
# type must be "json_schema", "json_object" or "text"
type: Literal["text", "json_object", "json_schema"]
json_schema: Optional[JsonSchemaResponseFormat] = None
class StreamOptions(OpenAIBaseModel):