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

Add custom API base argument #184

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions zeno_build/models/lm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class LMConfig:
Hugging Face transformers.
tokenizer_cls: The Python class corresponding to the tokenizer, mostly
for Hugging Face transformers.
api_base: Custom api base.
name_replacements: A dictionary mapping from the names of the roles
(e.g., "system", "assistant", "user") to the names of the
roles in the model.
Expand All @@ -29,6 +30,7 @@ class LMConfig:
model: str
model_cls: type | None = None
tokenizer_cls: type | None = None
api_base: str | None = None
name_replacements: dict[str, str] = dataclasses.field(
default_factory=lambda: dict(
{
Expand Down
4 changes: 4 additions & 0 deletions zeno_build/models/providers/litellm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def _throttled_litellm_completion_acreate(
top_p: float,
n: int,
limiter: aiolimiter.AsyncLimiter,
api_base: str = None,
) -> dict[str, Any]:
try:
from litellm import acompletion, exceptions
Expand All @@ -44,6 +45,7 @@ async def _throttled_litellm_completion_acreate(
max_tokens=max_tokens,
top_p=top_p,
n=n,
api_base=api_base,
)
except tuple(ERROR_ERRORS_TO_MESSAGES.keys()) as e:
if isinstance(
Expand Down Expand Up @@ -90,6 +92,7 @@ async def generate_from_litellm_completion(
top_p: Top p to use.
context_length: Length of context to use.
requests_per_minute: Number of requests per minute to allow.
api_base: Custom API endpoint

Returns:
List of generated responses.
Expand All @@ -106,6 +109,7 @@ async def generate_from_litellm_completion(
top_p=top_p,
n=n,
limiter=limiter,
api_base=model_config.api_base,
)
for full_context in full_contexts
]
Expand Down