Skip to content

Commit

Permalink
Pass litellm proxy specific metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-jaff committed Jul 23, 2024
1 parent 4c1ee1e commit a71b60d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions litellm/llms/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ def translate_anthropic_to_openai(
if "user_id" in anthropic_message_request["metadata"]:
new_kwargs["user"] = anthropic_message_request["metadata"]["user_id"]

# Pass litellm proxy specific metadata
if "litellm_metadata" in anthropic_message_request:
# metadata will be passed to litellm.acompletion(), it's a litellm_param
new_kwargs["metadata"] = anthropic_message_request.pop("litellm_metadata")

## CONVERT TOOL CHOICE
if "tool_choice" in anthropic_message_request:
new_kwargs["tool_choice"] = self.translate_anthropic_tool_choice_to_openai(
Expand Down
3 changes: 3 additions & 0 deletions litellm/proxy/litellm_pre_call_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def _get_metadata_variable_name(request: Request) -> str:
"""
if "thread" in request.url.path or "assistant" in request.url.path:
return "litellm_metadata"
if "/v1/messages" in request.url.path:
# anthropic API has a field called metadata
return "litellm_metadata"
else:
return "metadata"

Expand Down
5 changes: 4 additions & 1 deletion litellm/types/llms/anthropic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable, List, Optional, Union
from typing import Any, Dict, Iterable, List, Optional, Union

from pydantic import BaseModel, validator
from typing_extensions import Literal, Required, TypedDict
Expand Down Expand Up @@ -113,6 +113,9 @@ class AnthropicMessagesRequest(TypedDict, total=False):
top_k: int
top_p: float

# litellm param - used for tracking litellm proxy metadata in the request
litellm_metadata: dict


class ContentTextBlockDelta(TypedDict):
"""
Expand Down
1 change: 1 addition & 0 deletions litellm/types/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ class ChatCompletionRequest(TypedDict, total=False):
function_call: Union[str, dict]
functions: List
user: str
metadata: dict # litellm specific param


class ChatCompletionDeltaChunk(TypedDict, total=False):
Expand Down

0 comments on commit a71b60d

Please sign in to comment.