forked from phoenix/litellm-mirror
Pass litellm proxy specific metadata
This commit is contained in:
parent
4c1ee1e282
commit
a71b60d005
4 changed files with 13 additions and 1 deletions
|
@ -385,6 +385,11 @@ class AnthropicConfig:
|
|||
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(
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue