Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using create_iterable -- Error: 'Completions' object has no attribute 'create_iterable' #1110

Open
2 tasks done
andytriboletti opened this issue Oct 23, 2024 · 1 comment

Comments

@andytriboletti
Copy link

andytriboletti commented Oct 23, 2024

  • This is actually a bug report.
  • I have tried searching the documentation and have not found an answer.

What Model are you using?
Ollama 3.2

Describe the bug
When I use this code I get back an error:

 files = client.chat.completions.create_iterable(
            model="llama3.2",
            messages=[
                {"role": "system", "content": "You are a Python code generator. Generate multiple Python files."},
                {"role": "user", "content": "Generate a fibonacci generator with tests"}
            ],
            response_model=CodeFile,
        )
Error: 'Completions' object has no attribute 'create_iterable'

To Reproduce
Steps to reproduce the behavior, including code snippets of the model and the input data and openai response.
Save this to test.py

import instructor
from pydantic import BaseModel
from openai import OpenAI

class CodeFile(BaseModel):
    filename: str
    content: str

def main():
    client = instructor.patch(OpenAI(
        base_url="http://localhost:11434/v1",
        api_key="ollama"
    ))
    
    try:
        files = client.chat.completions.create_iterable(
            model="llama3.2",
            messages=[
                {"role": "system", "content": "You are a Python code generator. Generate multiple Python files."},
                {"role": "user", "content": "Generate a fibonacci generator with tests"}
            ],
            response_model=CodeFile,
        )

        print("\nGenerating files:")
        for file in files:
            # Save each file as it's generated
            with open(file.filename, 'w') as f:
                f.write(file.content)
            print(f"Created: {file.filename}")
            
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()

run

python test.py'

Get back error:

Error: 'Completions' object has no attribute 'create_iterable'

Expected behavior

It saves 2 files.

@ivanbelenky
Copy link
Contributor

ivanbelenky commented Oct 23, 2024

Hey @andytriboletti you are using instructor patch instead of building your client via instructor.from_openai for instance. Your traceback is quite descriptive of your problem. If you check

>>> ...
>>> type(client)
openai.OpenAI
>>> 'create_iterable' in dir(client)
False

Overall everything you need is present here. I suggest trying to make sense of your traceback before submitting an issue.

Hope this clarifies the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants