mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(chatgpt): pass per-model auth file to early provider detection
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
3d61622c23
commit
003352ff07
3 changed files with 51 additions and 3 deletions
|
|
@ -607,6 +607,7 @@ async def acompletion(
|
|||
model=model,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
api_base=kwargs.get("api_base") or base_url,
|
||||
litellm_params=GenericLiteLLMParams(chatgpt_auth_file=kwargs.get("chatgpt_auth_file")),
|
||||
)
|
||||
|
||||
fallbacks = fallbacks or litellm.model_fallbacks
|
||||
|
|
|
|||
|
|
@ -621,7 +621,9 @@ async def aresponses(
|
|||
# get custom llm provider so we can use this for mapping exceptions
|
||||
if custom_llm_provider is None:
|
||||
_, custom_llm_provider, _, _ = litellm.get_llm_provider(
|
||||
model=model, api_base=local_vars.get("base_url", None)
|
||||
model=model,
|
||||
api_base=local_vars.get("base_url", None),
|
||||
litellm_params=GenericLiteLLMParams(chatgpt_auth_file=kwargs.get("chatgpt_auth_file")),
|
||||
)
|
||||
# Update local_vars with detected provider (fixes #19782)
|
||||
local_vars["custom_llm_provider"] = custom_llm_provider
|
||||
|
|
@ -1197,7 +1199,9 @@ def responses(
|
|||
|
||||
if custom_llm_provider is None:
|
||||
_, custom_llm_provider, _, _ = litellm.get_llm_provider(
|
||||
model=model, api_base=local_vars.get("base_url", None)
|
||||
model=model,
|
||||
api_base=local_vars.get("base_url", None),
|
||||
litellm_params=GenericLiteLLMParams(chatgpt_auth_file=kwargs.get("chatgpt_auth_file")),
|
||||
)
|
||||
local_vars["custom_llm_provider"] = custom_llm_provider
|
||||
|
||||
|
|
@ -2079,7 +2083,9 @@ async def acompact_responses(
|
|||
# get custom llm provider so we can use this for mapping exceptions
|
||||
if custom_llm_provider is None:
|
||||
_, custom_llm_provider, _, _ = litellm.get_llm_provider(
|
||||
model=model, api_base=local_vars.get("base_url", None)
|
||||
model=model,
|
||||
api_base=local_vars.get("base_url", None),
|
||||
litellm_params=GenericLiteLLMParams(chatgpt_auth_file=kwargs.get("chatgpt_auth_file")),
|
||||
)
|
||||
# Update local_vars with detected provider (fixes #19782)
|
||||
local_vars["custom_llm_provider"] = custom_llm_provider
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from unittest.mock import mock_open, patch
|
|||
|
||||
import pytest
|
||||
|
||||
import litellm
|
||||
from litellm.llms.chatgpt.authenticator import (
|
||||
Authenticator,
|
||||
get_cached_authenticator,
|
||||
|
|
@ -145,3 +146,43 @@ class TestChatGPTMultiAccountAuthenticator:
|
|||
assert get_chatgpt_auth_file({"chatgpt_auth_file": "/a/auth.json"}) == "/a/auth.json"
|
||||
assert get_chatgpt_auth_file(GenericLiteLLMParams()) is None
|
||||
assert get_chatgpt_auth_file(GenericLiteLLMParams(chatgpt_auth_file="/b/auth.json")) == "/b/auth.json"
|
||||
|
||||
|
||||
class TestChatGPTAuthFileEarlyProviderDetection:
|
||||
@staticmethod
|
||||
def _no_device_login(self):
|
||||
raise AssertionError("device login must not run")
|
||||
|
||||
async def test_completion_threads_chatgpt_auth_file(self, tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path / "default"))
|
||||
monkeypatch.delenv("CHATGPT_AUTH_FILE", raising=False)
|
||||
auth_file = tmp_path / "account-a" / "auth.json"
|
||||
auth_file.parent.mkdir(parents=True)
|
||||
_write_auth_record(auth_file, "token-a", "acct-a")
|
||||
monkeypatch.setattr(Authenticator, "_login_device_code", self._no_device_login)
|
||||
|
||||
response = await litellm.acompletion(
|
||||
model="chatgpt/gpt-5.4",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
chatgpt_auth_file=str(auth_file),
|
||||
mock_response="ok",
|
||||
)
|
||||
|
||||
assert response is not None
|
||||
|
||||
def test_responses_threads_chatgpt_auth_file(self, tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path / "default"))
|
||||
monkeypatch.delenv("CHATGPT_AUTH_FILE", raising=False)
|
||||
auth_file = tmp_path / "account-a" / "auth.json"
|
||||
auth_file.parent.mkdir(parents=True)
|
||||
_write_auth_record(auth_file, "token-a", "acct-a")
|
||||
monkeypatch.setattr(Authenticator, "_login_device_code", self._no_device_login)
|
||||
|
||||
response = litellm.responses(
|
||||
model="chatgpt/gpt-5.4",
|
||||
input="hi",
|
||||
chatgpt_auth_file=str(auth_file),
|
||||
mock_response="ok",
|
||||
)
|
||||
|
||||
assert response is not None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue