From caecde2b3c09e56f8da9d2928667345793543f10 Mon Sep 17 00:00:00 2001 From: mrmer1 Date: Sun, 12 Jan 2025 15:25:01 +0800 Subject: [PATCH 1/4] add tool choice docs --- fern/pages/text-generation/tools/tool-use.mdx | 12 ++++++++++++ fern/pages/v2/text-generation/tools/tool-use.mdx | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fern/pages/text-generation/tools/tool-use.mdx b/fern/pages/text-generation/tools/tool-use.mdx index 2fe6d6f7a..f2104a436 100644 --- a/fern/pages/text-generation/tools/tool-use.mdx +++ b/fern/pages/text-generation/tools/tool-use.mdx @@ -306,6 +306,18 @@ if not response.tool_calls: co.chat(message=message, tools=tools, tool_results=[]) ``` +## Forcing Tool Use + +During the tool calling step, the model may decide to either: +- make tool call(s) or +- respond to a user message directly. + +You can, however, force the model to always make the former choice, that is to make at least one tool call This can be done by setting the `force_single_step` parameter to `True`. + +This is equivalent to setting the `tool_choice` as `REQUIRED` in the v2 API. + +While if `force_single_step=True` and `tool_results` are passed, this is equivalent to specifying `NONE`. + ## Single-Step Tool Use and Chat History Single-step tool use functions as part of a two-part conversational process. Here’s how that works: diff --git a/fern/pages/v2/text-generation/tools/tool-use.mdx b/fern/pages/v2/text-generation/tools/tool-use.mdx index 2d2d441ad..4821538e0 100644 --- a/fern/pages/v2/text-generation/tools/tool-use.mdx +++ b/fern/pages/v2/text-generation/tools/tool-use.mdx @@ -411,6 +411,18 @@ Start: 177 | End: 204 | Text: 'Laptop: $1,000, 15 in stock' Start: 207 | End: 232 | Text: 'Tablet: $300, 25 in stock' ``` +## Forcing Tool Use + +During the tool calling step, the model may decide to either: +- make tool call(s) or +- respond to a user message directly. + +You can, however, force the model to always make the former choice, that is to make at least one tool call This can be done by setting the `tool_choice` parameter to `REQUIRED`. + +If you don't specify the `tool_choice` parameter, then the model is free to choose whether to use the specified tools or not. + +This parameter is only compatible with the [Command R7B](https://docs.cohere.com/v2/docs/command-r7b) and newer models. + ## Structured Outputs (Tools) Setting the `strict_tools` parameter to True will enforce each tool call to follow the specified tool schema. To learn more about this feature, visit the [Structured Outputs documentation](https://docs.cohere.com/v2/docs/structured-outputs). From 2f9885ff49d553327df981824055bb8ec8207e99 Mon Sep 17 00:00:00 2001 From: mrmer1 Date: Mon, 13 Jan 2025 23:24:58 +0800 Subject: [PATCH 2/4] add code snippet --- .../v2/text-generation/tools/tool-use.mdx | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/fern/pages/v2/text-generation/tools/tool-use.mdx b/fern/pages/v2/text-generation/tools/tool-use.mdx index 4821538e0..44bbed9d7 100644 --- a/fern/pages/v2/text-generation/tools/tool-use.mdx +++ b/fern/pages/v2/text-generation/tools/tool-use.mdx @@ -421,6 +421,15 @@ You can, however, force the model to always make the former choice, that is to m If you don't specify the `tool_choice` parameter, then the model is free to choose whether to use the specified tools or not. +```python PYTHON {5} +response = co.chat( + model="command-r-plus-08-2024", + messages=messages, + tools=tools, + tool_choice="REQUIRED" +) +``` + This parameter is only compatible with the [Command R7B](https://docs.cohere.com/v2/docs/command-r7b) and newer models. ## Structured Outputs (Tools) @@ -429,11 +438,13 @@ Setting the `strict_tools` parameter to True will enforce each tool call to foll Note that `strict_tools` is currently an experimental feature. -```python PYTHON {4} -response = co.chat(model="command-r-plus-08-2024", - messages=messages, - tools=tools, - strict_tools=True) +```python PYTHON {5} +response = co.chat( + model="command-r-plus-08-2024", + messages=messages, + tools=tools, + strict_tools=True +) ``` ## How to Get Good Answers With Tool Use From 59a688bff0f95a1892e08c065ddb473d03bb070b Mon Sep 17 00:00:00 2001 From: mrmer1 Date: Thu, 23 Jan 2025 20:30:49 +0800 Subject: [PATCH 3/4] update some wording --- fern/pages/text-generation/tools/tool-use.mdx | 8 ++++---- fern/pages/v2/text-generation/tools/tool-use.mdx | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fern/pages/text-generation/tools/tool-use.mdx b/fern/pages/text-generation/tools/tool-use.mdx index f2104a436..115a57c01 100644 --- a/fern/pages/text-generation/tools/tool-use.mdx +++ b/fern/pages/text-generation/tools/tool-use.mdx @@ -309,14 +309,14 @@ if not response.tool_calls: ## Forcing Tool Use During the tool calling step, the model may decide to either: -- make tool call(s) or -- respond to a user message directly. +- make tool call(s) +- or, respond to a user message directly. -You can, however, force the model to always make the former choice, that is to make at least one tool call This can be done by setting the `force_single_step` parameter to `True`. +You can force the model to make tool call(s), i.e. to not respond directly, by setting the `force_single_step` parameter to `True`. This is equivalent to setting the `tool_choice` as `REQUIRED` in the v2 API. -While if `force_single_step=True` and `tool_results` are passed, this is equivalent to specifying `NONE`. +While if `force_single_step=True` and `tool_results` are passed, this is equivalent to specifying `tool_choice` as `NONE`. ## Single-Step Tool Use and Chat History diff --git a/fern/pages/v2/text-generation/tools/tool-use.mdx b/fern/pages/v2/text-generation/tools/tool-use.mdx index 44bbed9d7..5d52bf7b7 100644 --- a/fern/pages/v2/text-generation/tools/tool-use.mdx +++ b/fern/pages/v2/text-generation/tools/tool-use.mdx @@ -414,19 +414,22 @@ Start: 207 | End: 232 | Text: 'Tablet: $300, 25 in stock' ## Forcing Tool Use During the tool calling step, the model may decide to either: -- make tool call(s) or -- respond to a user message directly. +- make tool call(s) +- or, respond to a user message directly. -You can, however, force the model to always make the former choice, that is to make at least one tool call This can be done by setting the `tool_choice` parameter to `REQUIRED`. +You can force the model to make tool call(s), i.e. to not respond directly, by setting the `tool_choice` parameter to `REQUIRED`. -If you don't specify the `tool_choice` parameter, then the model is free to choose whether to use the specified tools or not. +Alternatively, you can force the model to respond directly, i.e. to not make tool call(s), by setting the `tool_choice` parameter to `NONE`. + +By default, if you don’t specify the `tool_choice` parameter, then the model will decide whether it's more appropriate to call tools or to respond directly. ```python PYTHON {5} response = co.chat( model="command-r-plus-08-2024", messages=messages, tools=tools, - tool_choice="REQUIRED" + tool_choice="REQUIRED" # optional, to force tool calls + # tool_choice="NONE" # optional, to force a direct response ) ``` From ee599962274f8a19ce1ff9ad9afe0c30df81b372 Mon Sep 17 00:00:00 2001 From: mrmer1 Date: Tue, 28 Jan 2025 17:18:48 +0800 Subject: [PATCH 4/4] fix v1 wording --- fern/pages/text-generation/tools/tool-use.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fern/pages/text-generation/tools/tool-use.mdx b/fern/pages/text-generation/tools/tool-use.mdx index 115a57c01..490d170ff 100644 --- a/fern/pages/text-generation/tools/tool-use.mdx +++ b/fern/pages/text-generation/tools/tool-use.mdx @@ -312,11 +312,11 @@ During the tool calling step, the model may decide to either: - make tool call(s) - or, respond to a user message directly. -You can force the model to make tool call(s), i.e. to not respond directly, by setting the `force_single_step` parameter to `True`. +You can force the model to make tool call(s), i.e. to not respond directly, by setting the `force_single_step=True` and providing some tool definitions through the `tools` parameter. This is equivalent to setting the `tool_choice` as `REQUIRED` in the v2 API. -While if `force_single_step=True` and `tool_results` are passed, this is equivalent to specifying `tool_choice` as `NONE`. +Besides, you can force the model to respond directly, by setting `force_single_step=True` and by providing some tool results through the `tool_results` parameter. This is equivalent to specifying `tool_choice` as `NONE` in the v2 API. ## Single-Step Tool Use and Chat History