[AttributeError]: Create with completion on list[Model] does not work #1078
Replies: 2 comments
-
I think this is a known issues for the core devs. Comments in the In your case def process_response(...) -> T_Model | ChatCompletion:
...
# ? This really hints at the fact that we need a better way of
# ? attaching usage data and the raw response to the model we return.
if isinstance(model, IterableBase):
logger.debug(f"Returning takes from IterableBase")
return [task for task in model.tasks]
if isinstance(response_model, ParallelBase):
logger.debug(f"Returning model from ParallelBase")
return model
if isinstance(model, AdapterBase):
logger.debug(f"Returning model from AdapterBase")
return model.content
model._raw_response = response The error you are pointing out is not just reflecting the need for better way of attaching usage data, but showing that this function is broken, i.e. returned objects are dependents on model type. I lack knowledge of the entire design of this project, but judging by the function's return statement def create_with_completion(...):
...
return model, model._raw_response and others alike, they will probably benefit from a wrapper that enables As a hacky solution for now I would suggest compounding your desired list return type, with another class UserInfo(BaseModel):
name: str
age: int
class UserInfoList(BaseModel):
user_infos: list[UserInfo]
user_info = client.chat.completions.create_with_completion(
model="gpt-3.5-turbo",
response_model=UserInfoList,
messages=[{"role": "user", "content": "John Doe is 30 years old.t"}],
) |
Beta Was this translation helpful? Give feedback.
-
Proposed SolutionI just created a very general solution for this known problem. I failed to find documentation for testing locally. Did I miss it in the docs @ivanleomk? For the sake of replication, I tested everything locally as is it is in the release workflow (except cohere)
The idea is to wrap create calls inside a very basic T = TypeVar("T", bound=Union[BaseModel, "Iterable[Any]", "Partial[Any]"])
class Creation(Generic[T]):
raw: Any # should be uniform completion type
processed: T
def __init__(self, raw: Any, processed: T) -> None:
self.raw, self.processed = raw, processed Then just altering |
Beta Was this translation helpful? Give feedback.
-
What Model are you using?
Describe the bug
create_with_completion
doesn't work with list[Model]. AttributeErrorTo Reproduce
Errors in
Expected behavior
Getting completion responses like when using normal create with list[Model] which runs fine.
Use create_iterable? I want with completion, and there is no documentation on it.
I would be expecting the returned pydantic objects to have _raw_response but they dont
Beta Was this translation helpful? Give feedback.
All reactions