mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-27 06:13:07 +00:00
fix(fine_tuning): stop forwarding api_version to the OpenAI client (#44995)
The OpenAI fine-tuning handler built its SDK client from every local it received, so an api_version or litellm_params set on an openai finetune_settings entry reached OpenAI.__init__ and every fine-tuning call on that provider failed with "unexpected keyword argument 'api_version'". Build the client from its named params instead and cover it with a request-level regression test Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
This commit is contained in:
parent
c515f80f82
commit
cc156a73b8
1 changed files with 41 additions and 1 deletions
|
|
@ -1,11 +1,12 @@
|
|||
import json
|
||||
from typing import Final
|
||||
from typing import Final, Literal
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
import litellm
|
||||
from litellm.types.utils import LiteLLMFineTuningJob
|
||||
|
||||
API_BASE: Final = "https://fine-tuning.test"
|
||||
BASE_MODEL: Final = "gpt-4.1-nano-2025-04-14"
|
||||
|
|
@ -52,3 +53,42 @@ async def test_create_sends_the_model_without_the_provider_prefix(
|
|||
)
|
||||
|
||||
assert json.loads(sent.calls.last.request.content)["model"] == BASE_MODEL
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
@pytest.mark.parametrize(
|
||||
("custom_llm_provider", "api_base", "route", "sent_api_version"),
|
||||
[
|
||||
("openai", f"{API_BASE}/v1", f"{API_BASE}/v1/fine_tuning/jobs", None),
|
||||
("azure", API_BASE, f"{API_BASE}/openai/fine_tuning/jobs", "2024-10-21"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("is_async", [True, False], ids=["async", "sync"])
|
||||
async def test_create_with_api_version_reaches_the_provider_and_only_azure_gets_it(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
custom_llm_provider: Literal["openai", "azure"],
|
||||
api_base: str,
|
||||
route: str,
|
||||
sent_api_version: str | None,
|
||||
is_async: bool,
|
||||
) -> None:
|
||||
sent: Final = respx.post(url__startswith=route).mock(return_value=httpx.Response(200, json=PROVIDER_JOB))
|
||||
request: Final = {
|
||||
"model": BASE_MODEL,
|
||||
"training_file": "file-abc123",
|
||||
"custom_llm_provider": custom_llm_provider,
|
||||
"api_key": "sk-test",
|
||||
"api_base": api_base,
|
||||
"api_version": "2024-10-21",
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient() as session:
|
||||
monkeypatch.setattr(litellm, "aclient_session", session)
|
||||
job: Final = (
|
||||
await litellm.acreate_fine_tuning_job(**request) if is_async else litellm.create_fine_tuning_job(**request)
|
||||
)
|
||||
|
||||
assert isinstance(job, LiteLLMFineTuningJob)
|
||||
assert job.id == PROVIDER_JOB["id"]
|
||||
assert sent.calls.last.request.url.params.get("api-version") == sent_api_version
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue