Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Array as completions.parse's response_format #1734

Unanswered
CodyBontecou asked this question in Q&A
Discussion options

class UserDetail(BaseModel):
    age: int
    name: str

response = client.beta.chat.completions.parse(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "user",
            "content": "Provide synthetic data of 10 users.",
        }
    ],
    response_format=UserDetail,
)

I'd like to adjust the response_format to instead be an Iterable[UserDetail] and have the response return an array of UserDetail's rather than a single.

Explicitly setting response_format=Iterable[UserDetail] gives me the error: TypeError: issubclass() arg 1 must be a class.

I was able to get this to work using Instructor's implementation, so it's possible. But I'm not sure how they're making it work.

client = instructor.from_openai(OpenAI())

response = client.chat.completions.create(
    model="gpt-4o-mini",
    response_model=Iterable[UserDetail],
    messages=[
        {
            "role": "user",
            "content": "Provide synthetic data of 10 users.",
        }
    ],
)
You must be logged in to vote

Replies: 1 comment · 1 reply

Comment options

class UserDetail(BaseModel):

    age: int

    name: str



response = client.beta.chat.completions.parse(

    model="gpt-4o-mini",

    messages=[

        {

            "role": "user",

            "content": "Provide synthetic data of 10 users.",

        }

    ],

    response_format=UserDetail,

)

I'd like to adjust the response_format to instead be an Iterable[UserDetail] and have the response return an array of UserDetail's rather than a single.

Explicitly setting response_format=Iterable[UserDetail] gives me the error: TypeError: issubclass() arg 1 must be a class.

I was able to get this to work using Instructor's implementation, so it's possible. But I'm not sure how they're making it work.

client = instructor.from_openai(OpenAI())



response = client.chat.completions.create(

    model="gpt-4o-mini",

    response_model=Iterable[UserDetail],

    messages=[

        {

            "role": "user",

            "content": "Provide synthetic data of 10 users.",

        }

    ],

)
You must be logged in to vote
1 reply
@CodyBontecou
Comment options

Am I missing something? I believe this is just a quote with no changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.