Skip to content
Merged
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
17 changes: 12 additions & 5 deletions pages/generative-apis/how-to/use-function-calling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ tools = [{

### Simple function call example

Here is how to implement a basic function call:
To implement a basic function call, add the following code:

```python
# Initialize the OpenAI client
Expand Down Expand Up @@ -138,6 +138,13 @@ response = client.chat.completions.create(
tools=tools,
tool_choice="auto"
)

print(response.choices[0].message.tool_calls)
```

As the model detects properly that a tool call is required to answer the question, the output should be a list of tool calls specifying function names and parameter properties:
```bash
[ChatCompletionMessageToolCall(id='chatcmpl-tool-81e63f4f496d429ba9ec6efcff6a86e1', function=Function(arguments='{"departure_airport": "CDG", "destination_airport": "LHR", "departure_date": "2024-11-01"}', name='get_flight_schedule'), type='function')]
```

<Message type="note">
Expand All @@ -148,9 +155,9 @@ response = client.chat.completions.create(
Some models must be told they can use external functions in the system prompt. If you do not provide a system prompt when using tools, Scaleway will automatically add one that works best for that specific model.
</Message>

### Multi-turn conversation handling
### Call the tool and provide a final answer

For more complex interactions, you will need to handle multiple turns of conversation:
To provide the answer, or for more complex interactions, you will need to handle multiple turns of conversation:

```python
# Process the tool call
Expand Down Expand Up @@ -328,5 +335,5 @@ For more information about function calling and advanced implementations, refer
Function calling significantly extends the capabilities of language models by allowing them to interact with external tools and APIs.

<Message type="note">
We can't wait to see what you will build with function calls. Tell us what you are up to, share your experiments on Scaleway's [Slack community](https://slack.scaleway.com/) #ai
</Message>
We cannot wait to see what you will build with function calls. Tell us what you are up to, and share your experiments on Scaleway's [Slack community](https://slack.scaleway.com/) in the #ai channel.
</Message>