Module livekit.plugins.openai.tools

Classes

class CodeInterpreter (container: str | dict[str, typing.Any] | None = None)
Expand source code
@dataclass
class CodeInterpreter(OpenAITool):
    """Enable the code interpreter tool to write and execute Python code in a sandboxed environment"""

    container: str | dict[str, Any] | None = None

    def __post_init__(self) -> None:
        super().__init__(id="openai_code_interpreter")

    def to_dict(self) -> dict[str, Any]:
        result = {"type": "code_interpreter", "container": self.container}

        return result

Enable the code interpreter tool to write and execute Python code in a sandboxed environment

Ancestors

  • OpenAITool
  • livekit.agents.llm.tool_context.ProviderTool
  • livekit.agents.llm.tool_context.Tool
  • abc.ABC

Instance variables

var container : str | dict[str, typing.Any] | None

Methods

def to_dict(self) ‑> dict[str, typing.Any]
Expand source code
def to_dict(self) -> dict[str, Any]:
    result = {"type": "code_interpreter", "container": self.container}

    return result
class FileSearch (vector_store_ids: list[str] = <factory>,
filters: openai.types.shared.comparison_filter.ComparisonFilter | openai.types.shared.compound_filter.CompoundFilter | None = None,
max_num_results: int | None = None,
ranking_options: openai.types.responses.file_search_tool.RankingOptions | None = None)
Expand source code
@dataclass
class FileSearch(OpenAITool):
    """Enable file search tool to search uploaded document collections"""

    vector_store_ids: list[str] = field(default_factory=list)
    filters: responses.file_search_tool.Filters | None = None
    max_num_results: int | None = None
    ranking_options: responses.file_search_tool.RankingOptions | None = None

    def __post_init__(self) -> None:
        super().__init__(id="openai_file_search")

    def to_dict(self) -> dict[str, Any]:
        result: dict[str, Any] = {
            "type": "file_search",
            "vector_store_ids": self.vector_store_ids,
        }
        if self.filters is not None:
            result["filters"] = self.filters

        if self.max_num_results is not None:
            result["max_num_results"] = self.max_num_results

        if self.ranking_options is not None:
            result["ranking_options"] = self.ranking_options

        return result

Enable file search tool to search uploaded document collections

Ancestors

  • OpenAITool
  • livekit.agents.llm.tool_context.ProviderTool
  • livekit.agents.llm.tool_context.Tool
  • abc.ABC

Instance variables

var filters : openai.types.shared.comparison_filter.ComparisonFilter | openai.types.shared.compound_filter.CompoundFilter | None
var max_num_results : int | None
var ranking_options : openai.types.responses.file_search_tool.RankingOptions | None
var vector_store_ids : list[str]

Methods

def to_dict(self) ‑> dict[str, typing.Any]
Expand source code
def to_dict(self) -> dict[str, Any]:
    result: dict[str, Any] = {
        "type": "file_search",
        "vector_store_ids": self.vector_store_ids,
    }
    if self.filters is not None:
        result["filters"] = self.filters

    if self.max_num_results is not None:
        result["max_num_results"] = self.max_num_results

    if self.ranking_options is not None:
        result["ranking_options"] = self.ranking_options

    return result
class OpenAITool (*, id: str)
Expand source code
class OpenAITool(ProviderTool, ABC):
    @abstractmethod
    def to_dict(self) -> dict[str, Any]: ...

Helper class that provides a standard way to create an ABC using inheritance.

Ancestors

  • livekit.agents.llm.tool_context.ProviderTool
  • livekit.agents.llm.tool_context.Tool
  • abc.ABC

Subclasses

Methods

def to_dict(self) ‑> dict[str, typing.Any]
Expand source code
@abstractmethod
def to_dict(self) -> dict[str, Any]: ...
class WebSearch (filters: openai.types.responses.web_search_tool.Filters | None = None,
search_context_size: Literal['low', 'medium', 'high'] | None = 'medium',
user_location: openai.types.responses.web_search_tool.UserLocation | None = None)
Expand source code
@dataclass
class WebSearch(OpenAITool):
    """Enable web search tool to access up-to-date information from the internet"""

    filters: responses.web_search_tool.Filters | None = None
    search_context_size: Literal["low", "medium", "high"] | None = "medium"
    user_location: responses.web_search_tool.UserLocation | None = None

    def __post_init__(self) -> None:
        super().__init__(id="openai_web_search")

    def to_dict(self) -> dict[str, Any]:
        result: dict[str, Any] = {
            "type": "web_search",
            "search_context_size": self.search_context_size,
        }
        if self.user_location is not None:
            result["user_location"] = self.user_location
        if self.filters is not None:
            result["filters"] = self.filters

        return result

Enable web search tool to access up-to-date information from the internet

Ancestors

  • OpenAITool
  • livekit.agents.llm.tool_context.ProviderTool
  • livekit.agents.llm.tool_context.Tool
  • abc.ABC

Instance variables

var filters : openai.types.responses.web_search_tool.Filters | None
var search_context_size : Literal['low', 'medium', 'high'] | None
var user_location : openai.types.responses.web_search_tool.UserLocation | None

Methods

def to_dict(self) ‑> dict[str, typing.Any]
Expand source code
def to_dict(self) -> dict[str, Any]:
    result: dict[str, Any] = {
        "type": "web_search",
        "search_context_size": self.search_context_size,
    }
    if self.user_location is not None:
        result["user_location"] = self.user_location
    if self.filters is not None:
        result["filters"] = self.filters

    return result