When using create_iterable -- Error: 'Completions' object has no attribute 'create_iterable'
Opened this issue · 1 comments
andytriboletti commented
- 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 commented
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.