llama-gemma / patch_auth_test37.py
Leon4gr45's picture
Upload folder using huggingface_hub
dd9af43 verified
Raw History Blame Contribute Delete
1.67 kB
with open("gateway.py", "r") as f:
code = f.read()
# Wait, `get_is_authenticated` has missing `elif INFERENCE_AUTH_MODE == "optional":`!
# The `Cleanup patches` commit reverted my fix for optional auth rejecting invalid keys!
# Ah! But wait, `get_is_authenticated` doesn't raise 401 for "optional" mode in the current code...
# Wait, if `INFERENCE_AUTH_MODE` is "optional", and the user sends no key, `is_authenticated` is False.
# It skips `required` and `disabled` blocks.
# Then it does:
# `if is_authenticated:` -> False
# `else:` -> rate limit check.
# `return is_authenticated` -> False.
# Where is the 401 coming from?
# If `get_is_authenticated` returns `False`, does FastAPI reject it?
# No, `get_is_authenticated` returns a boolean, and we use it as `Depends(get_is_authenticated)`.
# FastAPI allows a dependency to return `False`.
# THEN `chat_completions` does:
# `await execute_completion(payload, is_authenticated)`
# `execute_completion` sends `{"Authorization": f"Bearer sk-gemini"}` to `llama-swap`.
# THEN `execute_completion` gets the response and returns it.
# AND the response from `execute_completion` is `{"error":{"message":"Invalid API Key","type":"authentication_error","code":401}}`?!
# NO, if `llama-swap` returns 401, `execute_completion` does `response.raise_for_status()`.
# Which raises `httpx.HTTPStatusError`!
# And `chat_completions` catches it:
# `except httpx.HTTPStatusError as exc:`
# `raise HTTPException(exc.response.status_code, exc.response.text)`
# So the 401 IS coming from `llama-swap`!
# BUT WE HARDCODED `Authorization: Bearer sk-gemini`!
# Why would `llama-swap` reject `sk-gemini` if the API key is `sk-gemini`?