from typing import List, Optional, Literal, Union
from pydantic import BaseModel, EmailStr
class Rating(BaseModel):
type: Literal["rating"]
name: str
class Options(TypedDict):
color: Literal["yellowBright", "orangeBright", "redBright", "pinkBright",
"purpleBright", "blueBright", "cyanBright", "tealBright",
"greenBright", "grayBright"]
max: int
options: Options
I assumed that this code indicated to OpenAI API that color was required. However, in the generated output, color is absent. What is wrong here please?
From what I understand, if I name it “NotOptional”, the AI will make it required. Is that correct? That’s superb.
I have a related issue with the Literal definition. In the following, AI returns the type as longText even though the type is required to be multilineText. In other words, it picks up the value for type from the class name rather than the specified value. Can you explain how this works?
class LongText(BaseModel):
type: Literal["multilineText"]
name: str
The name of the subclass can be whatever, in CamelCase for clarity.
The key used is a title given to the AI, so has value for determining the purpose of the object. The AI cannot deviate from a strict structured output, so the name doesn’t matter for getting a complete structured response - only for understanding of how to fill it in.
I can run it: my python 3.11 good
U can’t run: ur python bad
Here’s upgrading and downgrading all libraries on an install or venv to that which is in OpenAI requirements. If you do a manual install or upgrade after openai of a module like Pydantic, or your distro has newer versions, you could introduce problems.