diff --git a/pages/generative-apis/how-to/use-function-calling.mdx b/pages/generative-apis/how-to/use-function-calling.mdx index a9729433a0..bae8b377c5 100644 --- a/pages/generative-apis/how-to/use-function-calling.mdx +++ b/pages/generative-apis/how-to/use-function-calling.mdx @@ -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 @@ -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')] ``` @@ -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. -### 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 @@ -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. - 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 - \ No newline at end of file + 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. +