fix(vertex_ai/gemini/transformation.py): handle 'http://' in gemini p… (#7660)

* fix(vertex_ai/gemini/transformation.py): handle 'http://' in gemini process url

* refactor(router.py): refactor '_prompt_management_factory' to use logging obj get_chat_completion logic

deduplicates code

* fix(litellm_logging.py): update 'get_chat_completion_prompt' to update logging object messages

* docs(prompt_management.md): update prompt management to be in beta

given feedback - this still needs to be revised (e.g. passing in user message, not ignoring)

* refactor(prompt_management_base.py): introduce base class for prompt management

allows consistent behaviour across prompt management integrations

* feat(prompt_management_base.py): support adding client message to template message + refactor langfuse prompt management to use prompt management base

* fix(litellm_logging.py): log prompt id + prompt variables to langfuse if set

allows tracking what prompt was used for what purpose

* feat(litellm_logging.py): log prompt management metadata in standard logging payload + use in langfuse

allows logging prompt id / prompt variables to langfuse

* test: fix test

* fix(router.py): cleanup unused imports

* fix: fix linting error

* fix: fix trace param typing

* fix: fix linting errors

* fix: fix code qa check
This commit is contained in:
Krish Dholakia 2025-01-10 07:31:59 -08:00 committed by GitHub
parent 865e6d5bda
commit c10ae8879e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 340 additions and 76 deletions

View file

@ -47,9 +47,6 @@ from litellm.caching.caching import DualCache, InMemoryCache, RedisCache
from litellm.integrations.custom_logger import CustomLogger
from litellm.litellm_core_utils.core_helpers import _get_parent_otel_span_from_kwargs
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
from litellm.litellm_core_utils.litellm_logging import (
_init_custom_logger_compatible_class,
)
from litellm.router_strategy.budget_limiter import RouterBudgetLimiting
from litellm.router_strategy.least_busy import LeastBusyLoggingHandler
from litellm.router_strategy.lowest_cost import LowestCostLoggingHandler
@ -120,6 +117,8 @@ from litellm.utils import (
CustomStreamWrapper,
EmbeddingResponse,
ModelResponse,
Rules,
function_setup,
get_llm_provider,
get_non_default_completion_params,
get_secret,
@ -1457,6 +1456,17 @@ class Router:
messages: List[AllMessageValues],
kwargs: Dict[str, Any],
):
litellm_logging_object = kwargs.get("litellm_logging_obj", None)
if litellm_logging_object is None:
litellm_logging_object, kwargs = function_setup(
**{
"original_function": "acompletion",
"rules_obj": Rules(),
"start_time": get_utc_datetime(),
**kwargs,
}
)
litellm_logging_object = cast(LiteLLMLogging, litellm_logging_object)
prompt_management_deployment = self.get_available_deployment(
model=model,
messages=[{"role": "user", "content": "prompt"}],
@ -1475,38 +1485,31 @@ class Router:
"prompt_variables", None
)
if litellm_model is None or "/" not in litellm_model:
if prompt_id is None or not isinstance(prompt_id, str):
raise ValueError(
f"Model is not a custom logger compatible callback. Got={litellm_model}"
f"Prompt ID is not set or not a string. Got={prompt_id}, type={type(prompt_id)}"
)
if prompt_variables is not None and not isinstance(prompt_variables, dict):
raise ValueError(
f"Prompt variables is set but not a dictionary. Got={prompt_variables}, type={type(prompt_variables)}"
)
custom_logger_compatible_callback = litellm_model.split("/", 1)[0]
split_litellm_model = litellm_model.split("/", 1)[1]
custom_logger = _init_custom_logger_compatible_class(
logging_integration=custom_logger_compatible_callback,
internal_usage_cache=None,
llm_router=None,
)
if custom_logger is None:
raise ValueError(
f"Custom logger is not initialized. Got={custom_logger_compatible_callback}"
)
model, messages, optional_params = (
await custom_logger.async_get_chat_completion_prompt(
model=split_litellm_model,
litellm_logging_object.get_chat_completion_prompt(
model=litellm_model,
messages=messages,
non_default_params=get_non_default_completion_params(kwargs=kwargs),
prompt_id=prompt_id,
prompt_variables=prompt_variables,
dynamic_callback_params={},
)
)
kwargs = {**kwargs, **optional_params}
kwargs["model"] = model
kwargs["messages"] = messages
kwargs["litellm_logging_obj"] = litellm_logging_object
kwargs["prompt_id"] = prompt_id
kwargs["prompt_variables"] = prompt_variables
_model_list = self.get_model_list(model_name=model)
if _model_list is None or len(_model_list) == 0: # if direct call to model