-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow custom provider factory to be passed into infer_model
#3341
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
79780d8
Allow custom provider to be passed into infer_model
slkoo-cc 4cb1a86
lint
slkoo-cc 7aee96e
lint
slkoo-cc a905a13
lint
slkoo-cc 703c9b4
Apply suggestions from code review
slkoo-cc f78d2b0
test custom provider
slkoo-cc e8d40d4
Add docstring
slkoo-cc e076c4f
fix lint
slkoo-cc 60912aa
Merge branch 'main' into patch-2/infer-provider-func
DouweM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| import base64 | ||
| import warnings | ||
| from abc import ABC, abstractmethod | ||
| from collections.abc import AsyncIterator, Iterator | ||
| from collections.abc import AsyncIterator, Callable, Iterator | ||
| from contextlib import asynccontextmanager, contextmanager | ||
| from dataclasses import dataclass, field, replace | ||
| from datetime import datetime | ||
|
|
@@ -47,7 +47,7 @@ | |
| ) | ||
| from ..output import OutputMode | ||
| from ..profiles import DEFAULT_PROFILE, ModelProfile, ModelProfileSpec | ||
| from ..providers import infer_provider | ||
| from ..providers import Provider, infer_provider | ||
| from ..settings import ModelSettings, merge_model_settings | ||
| from ..tools import ToolDefinition | ||
| from ..usage import RequestUsage | ||
|
|
@@ -677,8 +677,10 @@ def override_allow_model_requests(allow_model_requests: bool) -> Iterator[None]: | |
| ALLOW_MODEL_REQUESTS = old_value # pyright: ignore[reportConstantRedefinition] | ||
|
|
||
|
|
||
| def infer_model(model: Model | KnownModelName | str) -> Model: # noqa: C901 | ||
| """Infer the model from the name.""" | ||
| def infer_model( # noqa: C901 | ||
| model: Model | KnownModelName | str, provider_generator: Callable[[str], Provider[Any]] | None = None | ||
| ) -> Model: | ||
| """Infer the model from the name. May optionally pass a callable that setup a custom provider for the model.""" | ||
|
||
| if isinstance(model, Model): | ||
| return model | ||
| elif model == 'test': | ||
|
|
@@ -713,7 +715,9 @@ def infer_model(model: Model | KnownModelName | str) -> Model: # noqa: C901 | |
| ) | ||
| provider_name = 'google-vertex' | ||
|
|
||
| provider = infer_provider(provider_name) | ||
| if provider_generator is None: | ||
| provider_generator = infer_provider | ||
| provider = provider_generator(provider_name) | ||
slkoo-cc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| model_kind = provider_name | ||
| if model_kind.startswith('gateway/'): | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.