Skip to content

Raw response is not present when the response model is an Iterable #361

@chrishiste

Description

@chrishiste

Describe the bug
When using the instructor library, there seems to be an issue with the raw response not being available when the response model is an Iterable.

To Reproduce

from typing import Iterable

import instructor
from openai import OpenAI
from pydantic import BaseModel


client = instructor.patch(OpenAI())


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


users = client.chat.completions.create(
    model="gpt-3.5-turbo",
    response_model=Iterable[UserDetail],
    messages=[
        {"role": "user", "content": "Give me 3 users"},
    ],
)

print(users) # [UserDetail(name='Alice', age=25), UserDetail(name='Bob', age=30), UserDetail(name='Charlie', age=35)]
assert users._raw_response is not None # AttributeError: 'list' object has no attribute '_raw_response'

Expected behavior
The expected behavior is that the raw response should be available and accessible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions