Skip to content

Commit 2e858cb

Browse files
authored
Update use-function-calling.mdx
Add response display to tool call and update step descriptions
1 parent 94388bd commit 2e858cb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pages/generative-apis/how-to/use-function-calling.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ tools = [{
110110

111111
### Simple function call example
112112

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

115115
```python
116116
# Initialize the OpenAI client
@@ -138,6 +138,13 @@ response = client.chat.completions.create(
138138
tools=tools,
139139
tool_choice="auto"
140140
)
141+
142+
print(response.choices[0].message.tool_calls)
143+
```
144+
145+
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 parameters properties:
146+
```bash
147+
[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')]
141148
```
142149

143150
<Message type="note">
@@ -148,9 +155,9 @@ response = client.chat.completions.create(
148155
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.
149156
</Message>
150157

151-
### Multi-turn conversation handling
158+
### Call tool and provide final answer
152159

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

155162
```python
156163
# Process the tool call
@@ -329,4 +336,4 @@ Function calling significantly extends the capabilities of language models by al
329336

330337
<Message type="note">
331338
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
332-
</Message>
339+
</Message>

0 commit comments

Comments
 (0)