mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix build from pip tests
This commit is contained in:
parent
ab4523c080
commit
1e0ee22445
3 changed files with 54 additions and 23 deletions
|
|
@ -11,13 +11,9 @@ from litellm.types.llms.openai import (
|
|||
ResponseInputParam,
|
||||
)
|
||||
from litellm.types.utils import ChatCompletionMessageToolCall
|
||||
|
||||
from litellm.types.responses.main import ChatCompletionSession
|
||||
from litellm.responses.utils import ResponsesAPIRequestUtils
|
||||
from typing import TypedDict
|
||||
|
||||
class ChatCompletionSession(TypedDict, total=False):
|
||||
messages: List[Union[AllMessageValues, GenericChatCompletionMessage, ChatCompletionMessageToolCall, ChatCompletionResponseMessage, Message]]
|
||||
litellm_session_id: Optional[str]
|
||||
|
||||
class _ENTERPRISE_ResponsesSessionHandler:
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -6,10 +6,17 @@ from typing import Any, Dict, List, Optional, Union
|
|||
|
||||
from openai.types.responses.tool_param import FunctionToolParam
|
||||
|
||||
from enterprise.enterprise_hooks.session_handler import (
|
||||
ChatCompletionSession,
|
||||
_ENTERPRISE_ResponsesSessionHandler,
|
||||
)
|
||||
from litellm.types.responses.main import ChatCompletionSession
|
||||
|
||||
try:
|
||||
import enterprise
|
||||
from enterprise.enterprise_hooks.session_handler import (
|
||||
_ENTERPRISE_ResponsesSessionHandler,
|
||||
)
|
||||
except ImportError:
|
||||
enterprise = None
|
||||
_ENTERPRISE_ResponsesSessionHandler = None
|
||||
|
||||
from litellm.caching import InMemoryCache
|
||||
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
||||
from litellm.types.llms.openai import (
|
||||
|
|
@ -174,19 +181,20 @@ class LiteLLMCompletionResponsesConfig:
|
|||
"""
|
||||
Async hook to get the chain of previous input and output pairs and return a list of Chat Completion messages
|
||||
"""
|
||||
chat_completion_session: ChatCompletionSession = ChatCompletionSession(
|
||||
messages=[], litellm_session_id=None
|
||||
)
|
||||
if previous_response_id:
|
||||
chat_completion_session = await _ENTERPRISE_ResponsesSessionHandler.get_chat_completion_message_history_for_previous_response_id(
|
||||
previous_response_id=previous_response_id
|
||||
if _ENTERPRISE_ResponsesSessionHandler and ChatCompletionSession:
|
||||
chat_completion_session = ChatCompletionSession(
|
||||
messages=[], litellm_session_id=None
|
||||
)
|
||||
if previous_response_id:
|
||||
chat_completion_session = await _ENTERPRISE_ResponsesSessionHandler.get_chat_completion_message_history_for_previous_response_id(
|
||||
previous_response_id=previous_response_id
|
||||
)
|
||||
_messages = litellm_completion_request.get("messages") or []
|
||||
session_messages = chat_completion_session.get("messages") or []
|
||||
litellm_completion_request["messages"] = session_messages + _messages
|
||||
litellm_completion_request["litellm_trace_id"] = (
|
||||
chat_completion_session.get("litellm_session_id")
|
||||
)
|
||||
_messages = litellm_completion_request.get("messages") or []
|
||||
session_messages = chat_completion_session.get("messages") or []
|
||||
litellm_completion_request["messages"] = session_messages + _messages
|
||||
litellm_completion_request["litellm_trace_id"] = chat_completion_session.get(
|
||||
"litellm_session_id"
|
||||
)
|
||||
return litellm_completion_request
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -1,10 +1,24 @@
|
|||
from typing import Literal
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
from pydantic import PrivateAttr
|
||||
from typing_extensions import Any, List, Optional, TypedDict
|
||||
from typing_extensions import TYPE_CHECKING, Any, List, Optional, TypedDict
|
||||
|
||||
from litellm.types.llms.base import BaseLiteLLMOpenAIResponseObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from litellm.types.llms.openai import (
|
||||
AllMessageValues,
|
||||
ChatCompletionResponseMessage,
|
||||
GenericChatCompletionMessage,
|
||||
)
|
||||
from litellm.types.utils import ChatCompletionMessageToolCall, Message
|
||||
else:
|
||||
Message = Any
|
||||
ChatCompletionMessageToolCall = Any
|
||||
AllMessageValues = Any
|
||||
ChatCompletionResponseMessage = Any
|
||||
GenericChatCompletionMessage = Any
|
||||
|
||||
|
||||
class GenericResponseOutputItemContentAnnotation(BaseLiteLLMOpenAIResponseObject):
|
||||
"""Annotation for content in a message"""
|
||||
|
|
@ -74,3 +88,16 @@ class DecodedResponseId(TypedDict, total=False):
|
|||
custom_llm_provider: Optional[str]
|
||||
model_id: Optional[str]
|
||||
response_id: str
|
||||
|
||||
|
||||
class ChatCompletionSession(TypedDict, total=False):
|
||||
messages: List[
|
||||
Union[
|
||||
AllMessageValues,
|
||||
GenericChatCompletionMessage,
|
||||
ChatCompletionMessageToolCall,
|
||||
ChatCompletionResponseMessage,
|
||||
Message,
|
||||
]
|
||||
]
|
||||
litellm_session_id: Optional[str]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue