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

[Ellipsis] check that base_url exists before checking it in the client.py constructor. #609

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion instructor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ class Instructor:
mode: instructor.Mode
default_model: str | None = None
provider: Provider
base_url: str | None

def __init__(
self,
client: Any | None,
create: Callable,
mode: instructor.Mode = instructor.Mode.TOOLS,
provider: Provider = Provider.OPENAI,
base_url: str = None,
**kwargs,
):
if base_url is None:
raise ValueError('base_url is required')
self.client = client
self.create_fn = create
self.mode = mode
self.kwargs = kwargs
self.provider = provider
self.base_url = base_url

@property
def chat(self) -> Self:
Expand Down Expand Up @@ -162,13 +167,17 @@ def __init__(
create: Callable,
mode: instructor.Mode = instructor.Mode.TOOLS,
provider: Provider = Provider.OPENAI,
base_url: str = None,
**kwargs,
):
if base_url is None:
raise ValueError('base_url is required')
self.client = client
self.create_fn = create
self.mode = mode
self.kwargs = kwargs
self.provider = provider
self.base_url = base_url

async def create(
self,
Expand Down Expand Up @@ -297,6 +306,7 @@ def from_openai(
create=instructor.patch(create=client.chat.completions.create, mode=mode),
mode=mode,
provider=provider,
base_url=client.base_url,
**kwargs,
)

Expand All @@ -306,6 +316,7 @@ def from_openai(
create=instructor.patch(create=client.chat.completions.create, mode=mode),
mode=mode,
provider=provider,
base_url=client.base_url,
**kwargs,
)

Expand Down Expand Up @@ -347,4 +358,4 @@ def from_litellm(
create=instructor.patch(create=completion, mode=mode),
mode=mode,
**kwargs,
)
)