More fixing of types

This commit is contained in:
Brandon Hancock
2025-01-06 10:28:42 -05:00
parent 777448b4b2
commit 0aaa466467
2 changed files with 50 additions and 33 deletions

View File

@@ -231,7 +231,7 @@ class LLM:
:return: Final text response from the LLM or the tool result
"""
with suppress_warnings():
if callbacks:
if callbacks and len(callbacks) > 0:
self.set_callbacks(callbacks)
try:
@@ -259,7 +259,6 @@ class LLM:
"tools": tools, # pass the tool schema
}
# Remove None values
params = {k: v for k, v in params.items() if v is not None}
response = litellm.completion(**params)
@@ -290,8 +289,6 @@ class LLM:
# Call the actual tool function
result = fn(**function_args)
print(f"Result from function '{function_name}': {result}")
# Return the result directly
return result
@@ -368,7 +365,23 @@ class LLM:
def set_env_callbacks(self):
"""
Sets the success and failure callbacks for the LiteLLM library from environment variables.
This method reads the `LITELLM_SUCCESS_CALLBACKS` and `LITELLM_FAILURE_CALLBACKS`
environment variables, which should contain comma-separated lists of callback names.
It then assigns these lists to `litellm.success_callback` and `litellm.failure_callback`,
respectively.
If the environment variables are not set or are empty, the corresponding callback lists
will be set to empty lists.
Example:
LITELLM_SUCCESS_CALLBACKS="langfuse,langsmith"
LITELLM_FAILURE_CALLBACKS="langfuse"
This will set `litellm.success_callback` to ["langfuse", "langsmith"] and
`litellm.failure_callback` to ["langfuse"].
"""
with suppress_warnings():
success_callbacks_str = os.environ.get("LITELLM_SUCCESS_CALLBACKS", "")
success_callbacks = []
if success_callbacks_str:

View File

@@ -171,7 +171,9 @@ def _llm_via_environment_or_fallback() -> Optional[LLM]:
set_provider = model_name.split("/")[0] if "/" in model_name else "openai"
if set_provider in ENV_VARS:
for env_var in ENV_VARS[set_provider]:
env_vars_for_provider = ENV_VARS[set_provider]
if isinstance(env_vars_for_provider, (list, tuple)):
for env_var in env_vars_for_provider:
key_name = env_var.get("key_name")
if key_name and key_name not in UNACCEPTED_ATTRIBUTES:
env_value = os.environ.get(key_name)
@@ -185,7 +187,9 @@ def _llm_via_environment_or_fallback() -> Optional[LLM]:
if key not in ["prompt", "key_name", "default"]:
llm_params[key.lower()] = value
else:
print(f"Expected env_var to be a dictionary, but got {type(env_var)}")
print(
f"Expected env_var to be a dictionary, but got {type(env_var)}"
)
# Remove None values
llm_params = {k: v for k, v in llm_params.items() if v is not None}