You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/groq-chat.adoc
+61-4Lines changed: 61 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,13 +154,70 @@ TIP: In addition to the model specific https://github.com/spring-projects/spring
154
154
155
155
== Function Calling
156
156
157
-
Groq API endpoints support https://console.groq.com/docs/tool-use[function calling].
158
-
You can register custom Java functions with the OpenAiChatModel and have the OpenAI model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions.
159
-
This is a powerful technique to connect the LLM capabilities with external tools and APIs.
160
-
Read more about xref:api/chat/functions/openai-chat-functions.adoc[OpenAI Function Calling].
157
+
Groq API endpoints support https://console.groq.com/docs/tool-use[tool/function calling] when selecting one of the Tool/Function supporting models.
161
158
162
159
TIP: Check the Tool https://console.groq.com/docs/tool-use[Supported Models].
You can register custom Java functions with your ChatModel and have the provided Groq model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions.
164
+
This is a powerful technique to connect the LLM capabilities with external tools and APIs.
165
+
166
+
=== Tool Example
167
+
168
+
Here's a simple example of how to use Groq function calling with Spring AI:
.user("What is the weather in Amsterdam and Paris?")
186
+
.functions("weatherFunction") // reference by bean name.
187
+
.call()
188
+
.content();
189
+
190
+
System.out.println(response);
191
+
};
192
+
}
193
+
194
+
@Bean
195
+
@Description("Get the weather in location")
196
+
public Function<WeatherRequest, WeatherResponse> weatherFunction() {
197
+
return new MockWeatherService();
198
+
}
199
+
200
+
public static class MockWeatherService implements Function<WeatherRequest, WeatherResponse> {
201
+
202
+
public record WeatherRequest(String location, String unit) {}
203
+
public record WeatherResponse(double temp, String unit) {}
204
+
205
+
@Override
206
+
public WeatherResponse apply(WeatherRequest request) {
207
+
double temperature = request.location().contains("Amsterdam") ? 20 : 25;
208
+
return new WeatherResponse(temperature, request.unit);
209
+
}
210
+
}
211
+
}
212
+
----
213
+
214
+
In this example, when the model needs weather information, it will automatically call the `weatherFunction` bean, which can then fetch real-time weather data.
215
+
The expected response looks like this: "The weather in Amsterdam is currently 20 degrees Celsius, and the weather in Paris is currently 25 degrees Celsius."
216
+
217
+
Read more about OpenAI link:https://docs.spring.io/spring-ai/reference/api/chat/functions/openai-chat-functions.html[Function Calling].
218
+
219
+
220
+
164
221
== Multimodal
165
222
166
223
NOTE: Currently the Groq API doesn't support media content.
0 commit comments