Skip to content

Update internal_instructor.py MISSING API_KEY issue #2786

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/crewai/utilities/internal_instructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ def to_json(self):
return model.model_dump_json(indent=2)

def to_pydantic(self):
"""
Convert the instruction to a Pydantic model using the LLM.

Returns:
Pydantic model: The response model from the LLM.

Raises:
ValueError: If no API key is provided or is invalid.
RuntimeError: If chat completion creation fails.
Comment on lines +45 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not raising it anymore, right?

"""
messages = [{"role": "user", "content": self.content}]
model = self._client.chat.completions.create(
model=self.llm.model, response_model=self.model, messages=messages
model=self.llm.model, response_model=self.model, messages=messages, api_key=self.llm.api_key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also send the api.base here as well.

Issue #2753
what do you think @lucasgomide?

)
return model