mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(chatgpt): resolve gateway URLs without touching token storage
This commit is contained in:
parent
96594e7b0e
commit
6e87b4b985
4 changed files with 10 additions and 6 deletions
|
|
@ -49,7 +49,8 @@ class Authenticator:
|
|||
self.auth_file = os.path.join(self.token_dir, os.getenv("CHATGPT_AUTH_FILE", "auth.json"))
|
||||
self._ensure_token_dir()
|
||||
|
||||
def get_api_base(self, default_base: str = CHATGPT_API_BASE) -> str:
|
||||
@staticmethod
|
||||
def get_api_base(default_base: str = CHATGPT_API_BASE) -> str:
|
||||
return os.getenv("CHATGPT_API_BASE") or os.getenv("OPENAI_CHATGPT_API_BASE") or default_base
|
||||
|
||||
def get_access_token(self) -> str:
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class ChatGPTImageGenerationConfig(GPTImageGenerationConfig):
|
|||
litellm_params: Mapping[str, object],
|
||||
stream: bool | None = None,
|
||||
) -> str:
|
||||
return f"{(api_base or Authenticator().get_api_base()).rstrip('/')}/images/generations"
|
||||
return f"{(api_base or Authenticator.get_api_base()).rstrip('/')}/images/generations"
|
||||
|
||||
def transform_image_generation_request(
|
||||
self,
|
||||
|
|
@ -107,7 +107,7 @@ class ChatGPTImageEditConfig(OpenAIImageEditConfig):
|
|||
return image_headers(headers, model, litellm_params or MappingProxyType({}))
|
||||
|
||||
def get_complete_url(self, model: str, api_base: str | None, litellm_params: Mapping[str, object]) -> str:
|
||||
return f"{(api_base or Authenticator().get_api_base()).rstrip('/')}/images/edits"
|
||||
return f"{(api_base or Authenticator.get_api_base()).rstrip('/')}/images/edits"
|
||||
|
||||
def use_multipart_form_data(self) -> bool:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ def realtime_endpoint(model: str) -> str:
|
|||
class ChatGPTRealtime(OpenAIRealtime):
|
||||
@staticmethod
|
||||
def get_api_base(api_base: str | None = None) -> str:
|
||||
return api_base or Authenticator().get_api_base(default_base="https://api.openai.com/v1")
|
||||
return api_base or Authenticator.get_api_base(default_base="https://api.openai.com/v1")
|
||||
|
||||
def __init__(self, params: GenericLiteLLMParams, headers: Mapping[str, str]) -> None:
|
||||
super().__init__()
|
||||
|
|
@ -94,7 +94,7 @@ class ChatGPTRealtimeHTTPConfig(OpenAIRealtimeHTTPConfig):
|
|||
api_base: str | None,
|
||||
**kwargs: object, # kwargs-ok: provider interface accepts optional credentials
|
||||
) -> str:
|
||||
return api_base or Authenticator().get_api_base()
|
||||
return api_base or Authenticator.get_api_base()
|
||||
|
||||
def get_api_key(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -120,7 +120,10 @@ def test_edit_accepts_filesystem_path(tmp_path, as_tuple):
|
|||
|
||||
@pytest.mark.parametrize("env_name", ["CHATGPT_API_BASE", "OPENAI_CHATGPT_API_BASE"])
|
||||
@pytest.mark.parametrize("api_base", [None, "https://deployment.example/codex"])
|
||||
def test_image_routes_use_configured_gateway(monkeypatch, env_name, api_base):
|
||||
def test_image_routes_use_configured_gateway(monkeypatch, env_name, api_base, tmp_path):
|
||||
token_path = tmp_path / "unavailable-token-directory"
|
||||
token_path.write_text("not a directory")
|
||||
monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(token_path))
|
||||
monkeypatch.delenv("CHATGPT_API_BASE", raising=False)
|
||||
monkeypatch.delenv("OPENAI_CHATGPT_API_BASE", raising=False)
|
||||
monkeypatch.setenv(env_name, "https://gateway.example/codex/")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue