mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
feat - add openai web search
This commit is contained in:
parent
e9c6f5b2df
commit
69da0ed3b5
3 changed files with 30 additions and 0 deletions
|
@ -494,6 +494,7 @@ def convert_to_model_response_object( # noqa: PLR0915
|
||||||
provider_specific_fields=provider_specific_fields,
|
provider_specific_fields=provider_specific_fields,
|
||||||
reasoning_content=reasoning_content,
|
reasoning_content=reasoning_content,
|
||||||
thinking_blocks=thinking_blocks,
|
thinking_blocks=thinking_blocks,
|
||||||
|
annotations=choice["message"].get("annotations", None),
|
||||||
)
|
)
|
||||||
finish_reason = choice.get("finish_reason", None)
|
finish_reason = choice.get("finish_reason", None)
|
||||||
if finish_reason is None:
|
if finish_reason is None:
|
||||||
|
|
|
@ -382,6 +382,28 @@ class ChatCompletionThinkingBlock(TypedDict, total=False):
|
||||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||||
|
|
||||||
|
|
||||||
|
class ChatCompletionAnnotationURLCitation(TypedDict, total=False):
|
||||||
|
end_index: int
|
||||||
|
"""The index of the last character of the URL citation in the message."""
|
||||||
|
|
||||||
|
start_index: int
|
||||||
|
"""The index of the first character of the URL citation in the message."""
|
||||||
|
|
||||||
|
title: str
|
||||||
|
"""The title of the web resource."""
|
||||||
|
|
||||||
|
url: str
|
||||||
|
"""The URL of the web resource."""
|
||||||
|
|
||||||
|
|
||||||
|
class ChatCompletionAnnotation(TypedDict, total=False):
|
||||||
|
type: Literal["url_citation"]
|
||||||
|
"""The type of the URL citation. Always `url_citation`."""
|
||||||
|
|
||||||
|
url_citation: ChatCompletionAnnotationURLCitation
|
||||||
|
"""A URL citation when using web search."""
|
||||||
|
|
||||||
|
|
||||||
class OpenAIChatCompletionTextObject(TypedDict):
|
class OpenAIChatCompletionTextObject(TypedDict):
|
||||||
type: Literal["text"]
|
type: Literal["text"]
|
||||||
text: str
|
text: str
|
||||||
|
|
|
@ -7,6 +7,7 @@ from typing import Any, Dict, List, Literal, Optional, Tuple, Union
|
||||||
from aiohttp import FormData
|
from aiohttp import FormData
|
||||||
from openai._models import BaseModel as OpenAIObject
|
from openai._models import BaseModel as OpenAIObject
|
||||||
from openai.types.audio.transcription_create_params import FileTypes # type: ignore
|
from openai.types.audio.transcription_create_params import FileTypes # type: ignore
|
||||||
|
from openai.types.chat.chat_completion import ChatCompletion
|
||||||
from openai.types.completion_usage import (
|
from openai.types.completion_usage import (
|
||||||
CompletionTokensDetails,
|
CompletionTokensDetails,
|
||||||
CompletionUsage,
|
CompletionUsage,
|
||||||
|
@ -27,6 +28,7 @@ from ..litellm_core_utils.core_helpers import map_finish_reason
|
||||||
from .guardrails import GuardrailEventHooks
|
from .guardrails import GuardrailEventHooks
|
||||||
from .llms.openai import (
|
from .llms.openai import (
|
||||||
Batch,
|
Batch,
|
||||||
|
ChatCompletionAnnotation,
|
||||||
ChatCompletionThinkingBlock,
|
ChatCompletionThinkingBlock,
|
||||||
ChatCompletionToolCallChunk,
|
ChatCompletionToolCallChunk,
|
||||||
ChatCompletionUsageBlock,
|
ChatCompletionUsageBlock,
|
||||||
|
@ -527,6 +529,7 @@ class Message(OpenAIObject):
|
||||||
provider_specific_fields: Optional[Dict[str, Any]] = Field(
|
provider_specific_fields: Optional[Dict[str, Any]] = Field(
|
||||||
default=None, exclude=True
|
default=None, exclude=True
|
||||||
)
|
)
|
||||||
|
annotations: Optional[List[ChatCompletionAnnotation]] = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -538,6 +541,7 @@ class Message(OpenAIObject):
|
||||||
provider_specific_fields: Optional[Dict[str, Any]] = None,
|
provider_specific_fields: Optional[Dict[str, Any]] = None,
|
||||||
reasoning_content: Optional[str] = None,
|
reasoning_content: Optional[str] = None,
|
||||||
thinking_blocks: Optional[List[ChatCompletionThinkingBlock]] = None,
|
thinking_blocks: Optional[List[ChatCompletionThinkingBlock]] = None,
|
||||||
|
annotations: Optional[List[ChatCompletionAnnotation]] = None,
|
||||||
**params,
|
**params,
|
||||||
):
|
):
|
||||||
init_values: Dict[str, Any] = {
|
init_values: Dict[str, Any] = {
|
||||||
|
@ -566,6 +570,9 @@ class Message(OpenAIObject):
|
||||||
if thinking_blocks is not None:
|
if thinking_blocks is not None:
|
||||||
init_values["thinking_blocks"] = thinking_blocks
|
init_values["thinking_blocks"] = thinking_blocks
|
||||||
|
|
||||||
|
if annotations is not None:
|
||||||
|
init_values["annotations"] = annotations
|
||||||
|
|
||||||
if reasoning_content is not None:
|
if reasoning_content is not None:
|
||||||
init_values["reasoning_content"] = reasoning_content
|
init_values["reasoning_content"] = reasoning_content
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue