-
Notifications
You must be signed in to change notification settings - Fork 502
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
feat: support for custom toolchoice in LLMs #1102
Conversation
🦋 Changeset detectedLatest commit: 7490a95 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I think we should introduce |
@theomonnom Shouldn't these parameters be in the |
It should be on the |
…ropic-toolchoice
@@ -40,11 +50,18 @@ | |||
) | |||
|
|||
|
|||
class ToolChoice(TypedDict, total=False): | |||
type: Literal["auto", "any", "tool", "none", "required"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference between tool
and required
?
What is any
used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required
(OpenAI specific param) - the model must call one or more tools.
any
(Anthropic specific param) - the model must call one or more tools.
tool
(Anthropic specific param) - the model must call specific tool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we merge any
and required
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can, but I think we may need to document this otherwise, it might confuse users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated code accordingly
@@ -578,6 +680,14 @@ def chat( | |||
|
|||
if fnc_ctx and parallel_tool_calls is not None: | |||
opts["parallel_tool_calls"] = parallel_tool_calls | |||
if tool_choice is not None: | |||
if isinstance(tool_choice, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinstance(tool_choice, dict): | |
if isinstance(tool_choice, FunctionToolChoice): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update this class: https://github.com/livekit/agents/blob/main/livekit-plugins/livekit-plugins-llama-index/livekit/plugins/llama_index/llm.py
livekit-plugins/livekit-plugins-anthropic/livekit/plugins/anthropic/llm.py
Outdated
Show resolved
Hide resolved
…ropic/llm.py Co-authored-by: Théo Monnom <theo.8bits@gmail.com>
@@ -51,6 +60,11 @@ class ChatChunk: | |||
usage: CompletionUsage | None = None | |||
|
|||
|
|||
class FunctionToolChoice(TypedDict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class FunctionToolChoice(TypedDict): | |
class ToolChoice(TypedDict): |
--- | ||
"livekit-plugins-anthropic": patch | ||
"livekit-plugins-openai": patch | ||
"livekit-agents": patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add llama-index here
What
This PR implements custom tool choice and parallel tool call functionality for LLMs.
Why
Feature Improvement
Example Usage
Relevant Links