Update Mistral AI function calling docs and layout
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 511 KiB |
@@ -1,4 +1,4 @@
|
||||
= Mistral Function Calling
|
||||
= Mistral AI Function Calling
|
||||
|
||||
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.
|
||||
This allows you to connect the LLM capabilities with external tools and APIs.
|
||||
@@ -6,7 +6,7 @@ The `mistral_small_latest` and `mistral_large_latest` models are trained to dete
|
||||
|
||||
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.
|
||||
|
||||
NOTE: Currently the MistralAI API doesn't support parallel function calling, similarly to the OpenAI API, Azure OpenAI API, and Vertex AI Gemini API.
|
||||
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.
|
||||
|
||||
Spring AI provides flexible and user-friendly ways to register and call custom functions.
|
||||
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
|
||||
This approach allows to dynamically chose different functions to be called based on the user input.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
== Appendices
|
||||
|
||||
=== 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]
|
||||
|
||||
=== Mistral AI API Function Calling Flow
|
||||
|
||||
The following diagram illustrates the flow of the Mistral AI low-level API for link:https://docs.mistral.ai/guides/function-calling[Function Calling]:
|
||||
|
||||
image:mistral-ai-function-calling-flow.jpg[title="Mistral AI API Function Calling Flow", width=800, link=https://docs.mistral.ai/guides/function-calling]
|
||||
|
||||
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.
|
||||
It is based on the https://docs.mistral.ai/guides/function-calling[Mistral AI Function Calling tutorial].
|
||||
|
||||
@@ -108,7 +108,7 @@ This is useful if you want to use different MistralAI accounts for different mod
|
||||
|
||||
TIP: All properties prefixed with `spring.ai.mistralai.chat.options` can be overridden at runtime by adding a request specific <<chat-options>> to the `Prompt` call.
|
||||
|
||||
=== Chat Options [[chat-options]]
|
||||
== Chat Options [[chat-options]]
|
||||
|
||||
The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatOptions.java[MistralAiChatOptions.java] provides model configurations, such as the model to use, the temperature, the frequency penalty, etc.
|
||||
|
||||
@@ -131,7 +131,13 @@ ChatResponse response = chatClient.call(
|
||||
|
||||
TIP: In addition to the model specific link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatOptions.java[MistralAiChatOptions] you can use a portable https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatOptions.java[ChatOptions] instance, created with the https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatOptionsBuilder.java[ChatOptionsBuilder#builder()].
|
||||
|
||||
=== Sample Controller (Auto-configuration)
|
||||
== Function Calling
|
||||
|
||||
You can register custom Java functions with the MistralAiChatClient and have the Mistral AI model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions.
|
||||
This is a powerful technique to connect the LLM capabilities with external tools and APIs.
|
||||
Read more about xref:api/clients/functions/mistralai-chat-functions.adoc[Mistral AI Function Calling].
|
||||
|
||||
== Sample Controller (Auto-configuration)
|
||||
|
||||
https://start.spring.io/[Create] a new Spring Boot project and add the `spring-ai-mistralai-spring-boot-starter` to your pom (or gradle) dependencies.
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ This is useful if you want to use different OpenAI accounts for different models
|
||||
|
||||
TIP: All properties prefixed with `spring.ai.openai.chat.options` can be overridden at runtime by adding a request specific <<chat-options>> to the `Prompt` call.
|
||||
|
||||
=== Chat Options [[chat-options]]
|
||||
== Chat Options [[chat-options]]
|
||||
|
||||
The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java[OpenAiChatOptions.java] provides model configurations, such as the model to use, the temperature, the frequency penalty, etc.
|
||||
|
||||
@@ -135,13 +135,13 @@ ChatResponse response = chatClient.call(
|
||||
|
||||
TIP: In addition to the model specific https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatOptions.java[OpenAiChatOptions] you can use a portable https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatOptions.java[ChatOptions] instance, created with the https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatOptionsBuilder.java[ChatOptionsBuilder#builder()].
|
||||
|
||||
=== Function Calling
|
||||
== Function Calling
|
||||
|
||||
You can register custom Java functions with the OpenAiChatClient and have the OpenAI model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions.
|
||||
This is a powerful technique to connect the LLM capabilities with external tools and APIs.
|
||||
Read more about xref:api/clients/functions/openai-chat-functions.adoc[OpenAI Function Calling].
|
||||
|
||||
=== Sample Controller (Auto-configuration)
|
||||
== Sample Controller (Auto-configuration)
|
||||
|
||||
https://start.spring.io/[Create] a new Spring Boot project and add the `spring-ai-openai-spring-boot-starter` to your pom (or gradle) dependencies.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user