llama-gemma / patch_auth_test36.py
Leon4gr45's picture
Upload folder using huggingface_hub
dd9af43 verified
Raw History Blame Contribute Delete
1.12 kB
import re
with open("gateway.py", "r") as f:
code = f.read()
# When we send requests from the backend (gateway.py -> llama-swap)
# What if we pass the *user's* authorization header?
# No, we want an API key to not be required for users when INFERENCE_AUTH_MODE is optional!
# The user doesn't pass an API key, so we need to pass an API key for them if llama-swap requires it.
# BUT wait! If `llama-swap` requires `sk-gemini` (because `API_KEY` in environment is `sk-gemini`), then `llama_auth_headers()` should return `{"Authorization": f"Bearer {API_KEY}"}`.
# I had already done this and it worked (`patch_auth_test31.py` did `"Authorization": f"Bearer sk-gemini"`).
# Wait, in the current `gateway.py` the `llama_auth_headers()` is STILL `{"Authorization": f"Bearer sk-gemini"}`!
# Yet the curl WITHOUT authorization header returned `Invalid API Key`.
# Why? Because the `curl` without Authorization header hits `gateway.py`'s `chat_completions` endpoint.
# `chat_completions` checks `get_is_authenticated`.
# Is it possible that `get_is_authenticated` raises the 401?
# Let's check `get_is_authenticated`!