mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-10-14 09:28:58 +02:00
Enhance SampleAgent with improved Javadoc comments for tool specifications and descriptions, clarifying usage and parameters for weather, calculator, and hotel booking tools.
This commit is contained in:
parent
da6d20d118
commit
6df57c4a23
@ -16,6 +16,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example usage of the Agent API with some dummy tool functions.
|
||||||
|
*/
|
||||||
public class SampleAgent {
|
public class SampleAgent {
|
||||||
public static void main(String[] args) throws OllamaException {
|
public static void main(String[] args) throws OllamaException {
|
||||||
Ollama ollama = new Ollama("http://192.168.29.224:11434");
|
Ollama ollama = new Ollama("http://192.168.29.224:11434");
|
||||||
@ -31,8 +34,8 @@ public class SampleAgent {
|
|||||||
Tools.ToolSpec.builder()
|
Tools.ToolSpec.builder()
|
||||||
.name("weather-tool")
|
.name("weather-tool")
|
||||||
.description(
|
.description(
|
||||||
"Gets current weather for a given location and a"
|
"Gets the current weather for a given location and"
|
||||||
+ " given day")
|
+ " day.")
|
||||||
.parameters(
|
.parameters(
|
||||||
Tools.Parameters.of(
|
Tools.Parameters.of(
|
||||||
Map.of(
|
Map.of(
|
||||||
@ -40,10 +43,10 @@ public class SampleAgent {
|
|||||||
Tools.Property.builder()
|
Tools.Property.builder()
|
||||||
.type("string")
|
.type("string")
|
||||||
.description(
|
.description(
|
||||||
"The location to"
|
"The location for"
|
||||||
+ " get the"
|
+ " which to"
|
||||||
+ " weather"
|
+ " get the"
|
||||||
+ " for.")
|
+ " weather.")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build(),
|
.build(),
|
||||||
"day",
|
"day",
|
||||||
@ -51,9 +54,10 @@ public class SampleAgent {
|
|||||||
.type("string")
|
.type("string")
|
||||||
.description(
|
.description(
|
||||||
"The day of the"
|
"The day of the"
|
||||||
+ " week to get"
|
+ " week for"
|
||||||
+ " the weather"
|
+ " which to"
|
||||||
+ " for.")
|
+ " get the"
|
||||||
|
+ " weather.")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build())))
|
.build())))
|
||||||
.build())
|
.build())
|
||||||
@ -68,7 +72,7 @@ public class SampleAgent {
|
|||||||
.name("calculator-tool")
|
.name("calculator-tool")
|
||||||
.description(
|
.description(
|
||||||
"Performs a simple arithmetic operation between two"
|
"Performs a simple arithmetic operation between two"
|
||||||
+ " numbers")
|
+ " numbers.")
|
||||||
.parameters(
|
.parameters(
|
||||||
Tools.Parameters.of(
|
Tools.Parameters.of(
|
||||||
Map.of(
|
Map.of(
|
||||||
@ -76,20 +80,22 @@ public class SampleAgent {
|
|||||||
Tools.Property.builder()
|
Tools.Property.builder()
|
||||||
.type("string")
|
.type("string")
|
||||||
.description(
|
.description(
|
||||||
"Arithmetic"
|
"The arithmetic"
|
||||||
+ " operation"
|
+ " operation"
|
||||||
+ " to perform:"
|
+ " to perform."
|
||||||
|
+ " One of:"
|
||||||
+ " add,"
|
+ " add,"
|
||||||
+ " subtract,"
|
+ " subtract,"
|
||||||
+ " multiply,"
|
+ " multiply,"
|
||||||
+ " divide")
|
+ " divide.")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build(),
|
.build(),
|
||||||
"a",
|
"a",
|
||||||
Tools.Property.builder()
|
Tools.Property.builder()
|
||||||
.type("number")
|
.type("number")
|
||||||
.description(
|
.description(
|
||||||
"The first operand")
|
"The first"
|
||||||
|
+ " operand.")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build(),
|
.build(),
|
||||||
"b",
|
"b",
|
||||||
@ -97,7 +103,7 @@ public class SampleAgent {
|
|||||||
.type("number")
|
.type("number")
|
||||||
.description(
|
.description(
|
||||||
"The second"
|
"The second"
|
||||||
+ " operand")
|
+ " operand.")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build())))
|
.build())))
|
||||||
.build())
|
.build())
|
||||||
@ -111,8 +117,8 @@ public class SampleAgent {
|
|||||||
Tools.ToolSpec.builder()
|
Tools.ToolSpec.builder()
|
||||||
.name("hotel-booking-tool")
|
.name("hotel-booking-tool")
|
||||||
.description(
|
.description(
|
||||||
"Helps with booking a hotel room in a specified"
|
"Books a hotel room in a specified city for given"
|
||||||
+ " city for given dates and number of guests.")
|
+ " dates and number of guests.")
|
||||||
.parameters(
|
.parameters(
|
||||||
Tools.Parameters.of(
|
Tools.Parameters.of(
|
||||||
Map.of(
|
Map.of(
|
||||||
@ -120,31 +126,36 @@ public class SampleAgent {
|
|||||||
Tools.Property.builder()
|
Tools.Property.builder()
|
||||||
.type("string")
|
.type("string")
|
||||||
.description(
|
.description(
|
||||||
"The city where you"
|
"The city where the"
|
||||||
+ " want to"
|
+ " hotel will"
|
||||||
+ " book the"
|
+ " be booked.")
|
||||||
+ " hotel.")
|
|
||||||
.required(true)
|
.required(true)
|
||||||
.build(),
|
.build(),
|
||||||
"checkin_date",
|
"checkin_date",
|
||||||
Tools.Property.builder()
|
Tools.Property.builder()
|
||||||
.type("string")
|
.type("string")
|
||||||
.description(
|
.description(
|
||||||
"Check-in date.")
|
"Check-in date"
|
||||||
|
+ " (e.g."
|
||||||
|
+ " 2025-08-10).")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build(),
|
.build(),
|
||||||
"checkout_date",
|
"checkout_date",
|
||||||
Tools.Property.builder()
|
Tools.Property.builder()
|
||||||
.type("string")
|
.type("string")
|
||||||
.description(
|
.description(
|
||||||
"Check-out date.")
|
"Check-out date"
|
||||||
|
+ " (e.g."
|
||||||
|
+ " 2025-08-12).")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build(),
|
.build(),
|
||||||
"guests",
|
"guests",
|
||||||
Tools.Property.builder()
|
Tools.Property.builder()
|
||||||
.type("number")
|
.type("number")
|
||||||
.description(
|
.description(
|
||||||
"Number of guests.")
|
"Number of guests"
|
||||||
|
+ " for the"
|
||||||
|
+ " booking.")
|
||||||
.required(true)
|
.required(true)
|
||||||
.build())))
|
.build())))
|
||||||
.build())
|
.build())
|
||||||
@ -156,18 +167,22 @@ public class SampleAgent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ToolFunction implementation for diff checking. */
|
/**
|
||||||
|
* ToolFunction implementation that returns a dummy weekly weather forecast.
|
||||||
|
*/
|
||||||
class WeatherToolFunction implements ToolFunction {
|
class WeatherToolFunction implements ToolFunction {
|
||||||
@Override
|
@Override
|
||||||
public Object apply(Map<String, Object> arguments) {
|
public Object apply(Map<String, Object> arguments) {
|
||||||
String response =
|
String response =
|
||||||
"Monday: pleasant, Tuesday: Sunny, Wednesday: Windy, Thursday: Cloudy, Friday:"
|
"Monday: Pleasant, Tuesday: Sunny, Wednesday: Windy, Thursday: Cloudy, Friday:"
|
||||||
+ " Rainy, Saturday: Heavy rains, Sunday: Clear";
|
+ " Rainy, Saturday: Heavy rains, Sunday: Clear";
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ToolFunction implementation for simple calculations. */
|
/**
|
||||||
|
* ToolFunction implementation for basic arithmetic calculations.
|
||||||
|
*/
|
||||||
class CalculatorToolFunction implements ToolFunction {
|
class CalculatorToolFunction implements ToolFunction {
|
||||||
@Override
|
@Override
|
||||||
public Object apply(Map<String, Object> arguments) {
|
public Object apply(Map<String, Object> arguments) {
|
||||||
@ -198,7 +213,9 @@ class CalculatorToolFunction implements ToolFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ToolFunction implementation for a dummy hotel booking agent. */
|
/**
|
||||||
|
* ToolFunction implementation simulating a hotel booking.
|
||||||
|
*/
|
||||||
class HotelBookingToolFunction implements ToolFunction {
|
class HotelBookingToolFunction implements ToolFunction {
|
||||||
@Override
|
@Override
|
||||||
public Object apply(Map<String, Object> arguments) {
|
public Object apply(Map<String, Object> arguments) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user