-
Notifications
You must be signed in to change notification settings - Fork 9
fix: X litellm safer variable injection #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,12 +29,14 @@ def patched_completion(*args, **kwargs): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for key, value in os.environ.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
key.startswith("LITELLM_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and not key.startswith("LITELLM_EMBEDDINGS_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and key != "LITELLM_LOG" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and key != "LITELLM_LOCAL_MODEL_COST_MAP" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
key.startswith("X_LITELLM_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and not key.startswith("X_LITELLM_EMBEDDINGS_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
kwargs[key.replace("LITELLM_", "")] = value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
replaced_key = key.replace("X_LITELLM_", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# check if key is all uppercase, likely not a litellm key and got here by accident | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if replaced_key.isupper(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
kwargs[replaced_key] = value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return _original_completion(*args, **kwargs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -49,8 +51,12 @@ def patched_embedding(*args, **kwargs): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
# if os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# kwargs["vertex_credentials"] = os.environ["GOOGLE_APPLICATION_CREDENTIALS"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for key, value in os.environ.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if key.startswith("LITELLM_EMBEDDINGS_"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
kwargs[key.replace("LITELLM_EMBEDDINGS_", "")] = value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if key.startswith("X_LITELLM_EMBEDDINGS_"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
replaced_key = key.replace("X_LITELLM_EMBEDDINGS_", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# check if key is all uppercase, likely not a litellm key and got here by accident | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if replaced_key.isupper(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
kwargs[replaced_key] = value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return _original_embedding(*args, **kwargs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+54
to
60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Apply the same hardening for embeddings env mapping. Mirror the reserved/empty/override guards. Apply this diff: for key, value in os.environ.items():
- if key.startswith("X_LITELLM_EMBEDDINGS_"):
- replaced_key = key.replace("X_LITELLM_EMBEDDINGS_", "")
- # check if key is all uppercase, likely not a litellm key and got here by accident
- if replaced_key.isupper():
- continue
- kwargs[replaced_key] = value
+ if key.startswith("X_LITELLM_EMBEDDINGS_"):
+ replaced_key = key.replace("X_LITELLM_EMBEDDINGS_", "")
+ # check if key is all uppercase, likely not a litellm key and got here by accident
+ if replaced_key.isupper():
+ continue
+ # don't let env override reserved or caller-provided args; ignore empty values
+ if replaced_key in {"drop_params", "model"}:
+ continue
+ if replaced_key in kwargs:
+ continue
+ if value in ("", None):
+ continue
+ kwargs[replaced_key] = value 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
litellm.embedding = patched_embedding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||||||
[tool.poetry] | ||||||||||
name = "langevals-core" | ||||||||||
version = "0.1.14" | ||||||||||
version = "0.1.15" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainPatch bump OK; verify that the env-var prefix change isn’t a breaking release. Given the switch to X_LITELLM_* in core logic, confirm no consumers depend on LITELLM_* from process env. If that was externally observable, consider a minor (0.1.x -> 0.2.0) instead of patch. Run to surface leftover LITELLM_* usage and align deps: 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Leftover LITELLM_* references (should be empty):"
rg -nP -C2 '\bLITELLM_' -g '!**/dist/**' -g '!**/build/**' -g '!**/.venv/**' || true
echo
echo "New X_LITELLM_* keys usage (expect hits):"
rg -nP -C1 '\bX_LITELLM_(api_key|api_base|EMBEDDINGS_)'
echo
echo "litellm constraints across packages (ensure consistency):"
rg -nP '^\s*litellm\s*=\s*"[^^][^"]*|^\s*litellm\s*=\s*\^" -g '**/pyproject.toml' || true Length of output: 2436 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "litellm dependency constraints across all pyproject.toml files (ensure consistency):"
rg -nP '^\s*litellm\s*=\s*(".*?"|\{.*?\})' -g '**/pyproject.toml' -g '!**/dist/**' -g '!**/build/**' -g '!**/.venv/**' Length of output: 696 Bump to 0.2.0 to reflect breaking env-var change -version = "0.1.15"
+version = "0.2.0" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||
description = "Core package for LLM evaluation platform, providing base classes and utilities." | ||||||||||
authors = [ | ||||||||||
"Rogerio Chaves <rogerio@langwatch.ai>", | ||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Harden env->kwargs mapping: don’t override reserved/caller args; ignore empty values.
As written, X_LITELLM_* can override reserved keys like drop_params, cache, model, or any caller-provided kwarg, weakening the “safer” intent. Add guards.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents