instructor icon indicating copy to clipboard operation
instructor copied to clipboard

`create_iterable` is broken

Open bryanhpchiang opened this issue 1 year ago • 1 comments

create_iterable from the docs does not work.

  1. Go here: https://python.useinstructor.com/#streaming-iterables-create_iterable
  2. Copy + paste + run the example
  3. Error
Traceback (most recent call last):
  File "/Users/bryan/work/flow/iterable.py", line 14, in <module>
    users = client.chat.completions.create_iterable(
  File "/Users/bryan/work/flow/.venv/lib/python3.10/site-packages/instructor/client.py", line 184, in create_iterable
    return self.create_fn(
  File "/Users/bryan/work/flow/.venv/lib/python3.10/site-packages/instructor/patch.py", line 140, in new_create_sync
    response_model, new_kwargs = handle_response_model(
  File "/Users/bryan/work/flow/.venv/lib/python3.10/site-packages/instructor/process_response.py", line 191, in handle_response_model
    if is_simple_type(response_model):
  File "/Users/bryan/work/flow/.venv/lib/python3.10/site-packages/instructor/dsl/simple_type.py", line 40, in is_simple_type
    if isclass(response_model) and issubclass(response_model, BaseModel):
  File "/Users/bryan/miniconda3/envs/turbo/lib/python3.10/abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
(turbo) bryan@Bryans-MacBook-Pro-7 flow % python -V
Python 3.10.12
(turbo) bryan@Bryans-MacBook-Pro-7 flow % pip show openai
Name: openai
Version: 1.30.1
Summary: The official Python library for the openai API
Home-page:
Author:
Author-email: OpenAI <[email protected]>
License:
Location: /Users/bryan/miniconda3/envs/turbo/lib/python3.10/site-packages
Requires: anyio, distro, httpx, pydantic, sniffio, tqdm, typing-extensions
Required-by: instructor, litellm, open-interpreter, self-operating-computer
(turbo) bryan@Bryans-MacBook-Pro-7 flow % pip show instructor
Name: instructor
Version: 1.2.6
Summary: structured outputs for llm
Home-page: https://github.com/jxnl/instructor
Author: Jason Liu
Author-email: [email protected]
License: MIT
Location: /Users/bryan/miniconda3/envs/turbo/lib/python3.10/site-packages
Requires: aiohttp, docstring-parser, openai, pydantic, pydantic-core, rich, tenacity, typer
Required-by:
(turbo) bryan@Bryans-MacBook-Pro-7 flow %

bryanhpchiang avatar May 14 '24 23:05 bryanhpchiang

Same for me:

    client = instructor.from_litellm(completion)


   completion_return = client.chat.completions.create_iterable(
        messages=[{"role": "user", "content": prompt}],
        response_model=task_decomp,
        model=model,
      )

Error: issubclass() arg 1 must be a class

class task_decomp(BaseModel):
    index: int
    description: str
    duration: int
    left: int

shaunstoltz avatar May 17 '24 16:05 shaunstoltz

i am facing the same issue, have you figured out how to fix it?

ghost avatar May 23 '24 09:05 ghost

will explore more!

jxnl avatar May 23 '24 19:05 jxnl

This issue was fixed in #710, with the relevant changes found here:

https://github.com/jxnl/instructor/blob/081418d59a397b38a1b66fe58a64ef94f9124a6b/instructor/dsl/simple_type.py#L40-L48 I’ve verified that the example now runs without any problems. It’s safe to close this issue.

jlondonobo avatar Jun 04 '24 02:06 jlondonobo

I still face the same problem and the error happens like below in version 1.3.2 (latest).

issubclass() arg 1 must be a class ... TypeError: issubclass() arg 1 must be a class

スクリーンショット 2024-06-07 3 18 43 スクリーンショット 2024-06-07 3 20 17
class GeminiClient:
    def __init__(self):
        genai.configure(api_key=GOOGLE_API_KEY)
        self.model = client_gemini.from_gemini(
            client=genai.GenerativeModel(model_name="models/gemini-1.5-flash-latest"),
            mode=Mode.GEMINI_JSON
        )

class ScenarioTelop(BaseModel):
    telop_id: int = Field(description="Order of the telop (starting from 1)")
    overview: str = Field(description="Overview of the telop")
    intention: str = Field(description="Intention of the telop")
    text: str = Field(description="Corrected text of the telop")
    original_text: str = Field(description="Original text of the telop")
    timestamp_start: float = Field(description="Start timestamp of the telop (s)")
    timestamp_end: float = Field(description="End timestamp of the telop (s)")

ig-freetech avatar Jun 06 '24 18:06 ig-freetech

what version of python are you on?

jxnl avatar Jun 07 '24 17:06 jxnl

what version of python are you on?

3.9.18

ig-freetech avatar Jun 08 '24 13:06 ig-freetech

Proposed a potential fix for this https://github.com/jxnl/instructor/pull/737 - can't seem to get the 3.11 coverage step to pass for some reason but the iterable fix is shown to work in 3.9,3.10 and 3.11

ivanleomk avatar Jun 09 '24 13:06 ivanleomk

Fixed in #737

ivanleomk avatar Jun 12 '24 04:06 ivanleomk