Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
WeatherTool.java
Go to the documentation of this file.
1package io.github.ollama4j.tools.sampletools;
2
3import io.github.ollama4j.tools.Tools;
4
5import java.util.Map;
6
7@SuppressWarnings("resource")
8public class WeatherTool {
9 private String paramCityName = "cityName";
10
11 public WeatherTool() {
12 }
13
14 public String getCurrentWeather(Map<String, Object> arguments) {
15 String city = (String) arguments.get(paramCityName);
16 return "It is sunny in " + city;
17 }
18
19 public Tools.ToolSpecification getSpecification() {
20 return Tools.ToolSpecification.builder()
21 .functionName("weather-reporter")
22 .functionDescription(
23 "You are a tool who simply finds the city name from the user's message input/query about weather.")
24 .toolFunction(this::getCurrentWeather)
25 .toolPrompt(
27 .type("prompt")
28 .function(
30 .builder()
31 .name("get-city-name")
32 .description("Get the city name")
33 .parameters(
35 .builder()
36 .type("object")
37 .properties(
38 Map.of(
39 paramCityName,
41 .builder()
42 .type("string")
43 .description(
44 "The name of the city. e.g. Bengaluru")
45 .required(true)
46 .build()))
47 .required(java.util.List
48 .of(paramCityName))
49 .build())
50 .build())
51 .build())
52 .build();
53 }
54}
String getCurrentWeather(Map< String, Object > arguments)