Spaces:
Running
Running
Download patch_auth_test36.py from Leon4gr45/llama-gemma: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/Leon4gr45/llama-gemma/resolve/main/patch_auth_test36.py
- Command line
-
hf download hf://spaces/Leon4gr45/llama-gemma/patch_auth_test36.py
-
curl -L -o patch_auth_test36.py https://huggingface.co/spaces/Leon4gr45/llama-gemma/resolve/main/patch_auth_test36.py
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`! | |