Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extra_options parameter to OpenAI and Anthropic plugins #1210

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/green-phones-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"livekit-plugins-anthropic": patch
"livekit-plugins-openai": patch
---

Added extra_options parameter to OpenAI and Anthropic plugins
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class LLMOptions:
temperature: float | None
parallel_tool_calls: bool | None
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] | None
extra_options: dict[str, Any] = {}


class LLM(llm.LLM):
Expand All @@ -71,6 +72,7 @@ def __init__(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> None:
"""
Create a new instance of Anthropic LLM.
Expand All @@ -91,6 +93,7 @@ def __init__(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)
self._client = client or anthropic.AsyncClient(
api_key=api_key,
Expand Down Expand Up @@ -160,6 +163,7 @@ def chat(
top_k=n or anthropic.NOT_GIVEN,
stream=True,
**opts,
**self._opts.extra_options,
)

return LLMStream(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class LLMOptions:
temperature: float | None
parallel_tool_calls: bool | None
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto"
extra_options: dict[str, Any] = {}


class LLM(llm.LLM):
Expand All @@ -77,6 +78,7 @@ def __init__(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> None:
"""
Create a new instance of OpenAI LLM.
Expand All @@ -93,6 +95,7 @@ def __init__(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)
self._client = client or openai.AsyncClient(
api_key=api_key,
Expand Down Expand Up @@ -127,6 +130,7 @@ def with_azure(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
Expand Down Expand Up @@ -158,6 +162,7 @@ def with_azure(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -171,6 +176,7 @@ def with_cerebras(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of Cerebras LLM.
Expand All @@ -194,6 +200,7 @@ def with_cerebras(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -206,6 +213,7 @@ def with_vertex(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of VertexAI LLM.
Expand Down Expand Up @@ -276,6 +284,7 @@ async def _refresh_credentials(self) -> None:
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)
vertex_llm._capabilities = llm.LLMCapabilities(supports_choices_on_int=False)
return vertex_llm
Expand All @@ -291,6 +300,7 @@ def with_fireworks(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of Fireworks LLM.
Expand All @@ -314,6 +324,7 @@ def with_fireworks(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -327,6 +338,7 @@ def with_x_ai(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
):
"""
Create a new instance of XAI LLM.
Expand All @@ -349,6 +361,7 @@ def with_x_ai(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -362,6 +375,7 @@ def with_groq(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of Groq LLM.
Expand All @@ -385,6 +399,7 @@ def with_groq(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -398,6 +413,7 @@ def with_deepseek(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of DeepSeek LLM.
Expand All @@ -421,6 +437,7 @@ def with_deepseek(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -434,6 +451,7 @@ def with_octo(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of OctoAI LLM.
Expand All @@ -457,6 +475,7 @@ def with_octo(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -468,6 +487,7 @@ def with_ollama(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of Ollama LLM.
Expand All @@ -481,6 +501,7 @@ def with_ollama(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -494,6 +515,7 @@ def with_perplexity(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of PerplexityAI LLM.
Expand All @@ -517,6 +539,7 @@ def with_perplexity(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -530,6 +553,7 @@ def with_together(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of TogetherAI LLM.
Expand All @@ -553,6 +577,7 @@ def with_together(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -566,6 +591,7 @@ def with_telnyx(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
"""
Create a new instance of Telnyx LLM.
Expand All @@ -589,6 +615,7 @@ def with_telnyx(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

@staticmethod
Expand All @@ -608,6 +635,7 @@ def create_azure_client(
temperature: float | None = None,
parallel_tool_calls: bool | None = None,
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
extra_options: dict[str, Any] = {},
) -> LLM:
logger.warning("This alias is deprecated. Use LLM.with_azure() instead")
return LLM.with_azure(
Expand All @@ -624,6 +652,7 @@ def create_azure_client(
temperature=temperature,
parallel_tool_calls=parallel_tool_calls,
tool_choice=tool_choice,
extra_options=extra_options,
)

def chat(
Expand Down Expand Up @@ -676,6 +705,7 @@ def chat(
stream=True,
user=user,
**opts,
**self._opts.extra_options,
)

return LLMStream(
Expand Down