|
1 |
| -= Mistral Function Calling |
| 1 | += Mistral AI Function Calling |
2 | 2 |
|
3 | 3 | You can register custom Java functions with the `MistralAiChatClient` and have the Mistral AI models intelligently choose to output a JSON object containing arguments to call one or many of the registered functions.
|
4 | 4 | This allows you to connect the LLM capabilities with external tools and APIs.
|
5 | 5 | The `mistral_small_latest` and `mistral_large_latest` models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature.
|
6 | 6 |
|
7 | 7 | The MistralAI API does not call the function directly; instead, the model generates JSON that you can use to call the function in your code and return the result back to the model to complete the conversation.
|
8 | 8 |
|
9 |
| -NOTE: Currently the MistralAI API doesn't support parallel function calling, similarly to the OpenAI API, Azure OpenAI API, and Vertex AI Gemini API. |
| 9 | +NOTE: As of March 13, 2024, Mistral AI has integrated support for parallel function calling into their `mistral_large_latest`` model, a feature that was absent at the time of the first Spring AI Mistral AI. |
10 | 10 |
|
11 | 11 | Spring AI provides flexible and user-friendly ways to register and call custom functions.
|
12 | 12 | In general, the custom functions need to provide a function `name`, `description`, and the function call `signature` (as JSON schema) to let the model know what arguments the function expects.
|
@@ -191,3 +191,17 @@ NOTE: The in-prompt registered functions are enabled by default for the duration
|
191 | 191 | This approach allows to dynamically chose different functions to be called based on the user input.
|
192 | 192 |
|
193 | 193 | The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusPromptIT.java[PaymentStatusPromptIT.java] integration test provides a complete example of how to register a function with the `MistralAiChatClient` and use it in a prompt request.
|
| 194 | + |
| 195 | + |
| 196 | +== Appendices |
| 197 | + |
| 198 | +=== https://spring.io/blog/2024/03/06/function-calling-in-java-and-spring-ai-using-the-latest-mistral-ai-api[(Blog) Function Calling in Java and Spring AI using the latest Mistral AI API] |
| 199 | + |
| 200 | +=== Mistral AI API Function Calling Flow |
| 201 | + |
| 202 | +The following diagram illustrates the flow of the Mistral AI low-level API for link:https://docs.mistral.ai/guides/function-calling[Function Calling]: |
| 203 | + |
| 204 | +image:mistral-ai-function-calling-flow.jpg[title="Mistral AI API Function Calling Flow", width=800, link=https://docs.mistral.ai/guides/function-calling] |
| 205 | + |
| 206 | +The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/api/tool/PaymentStatusFunctionCallingIT.java[PaymentStatusFunctionCallingIT.java] provides a complete example on how to use the Mistral AI API function calling. |
| 207 | +It is based on the https://docs.mistral.ai/guides/function-calling[Mistral AI Function Calling tutorial]. |
0 commit comments