diff --git a/src/main/java/io/github/ollama4j/OllamaAPI.java b/src/main/java/io/github/ollama4j/OllamaAPI.java
index fdab795..feeafa1 100644
--- a/src/main/java/io/github/ollama4j/OllamaAPI.java
+++ b/src/main/java/io/github/ollama4j/OllamaAPI.java
@@ -371,6 +371,11 @@ public class OllamaAPI {
/**
* Finds a specific model using model name and tag from Ollama library.
*
+ * Deprecated: This method relies on the HTML structure of the Ollama website,
+ * which is subject to change at any time. As a result, it is difficult to keep this API
+ * method consistently updated and reliable. Therefore, this method is deprecated and
+ * may be removed in future releases.
+ *
* This method retrieves the model from the Ollama library by its name, then
* fetches its tags.
* It searches through the tags of the model to find one that matches the
@@ -388,7 +393,9 @@ public class OllamaAPI {
* @throws URISyntaxException If there is an error with the URI syntax.
* @throws InterruptedException If the operation is interrupted.
* @throws NoSuchElementException If the model or the tag is not found.
+ * @deprecated This method relies on the HTML structure of the Ollama website, which can change at any time and break this API. It is deprecated and may be removed in the future.
*/
+ @Deprecated
public LibraryModelTag findModelTagFromLibrary(String modelName, String tag)
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
List libraryModels = this.listModelsFromLibrary();
diff --git a/src/main/java/io/github/ollama4j/tools/sampletools/WeatherTool.java b/src/main/java/io/github/ollama4j/tools/sampletools/WeatherTool.java
index e1bf483..7a32ab0 100644
--- a/src/main/java/io/github/ollama4j/tools/sampletools/WeatherTool.java
+++ b/src/main/java/io/github/ollama4j/tools/sampletools/WeatherTool.java
@@ -1,89 +1,54 @@
package io.github.ollama4j.tools.sampletools;
-import java.io.IOException;
-import java.net.URI;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.util.Map;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
import io.github.ollama4j.tools.Tools;
+import java.util.Map;
+
@SuppressWarnings("resource")
public class WeatherTool {
- private String openWeatherMapAPIKey = null;
- private String paramCityName = "cityName";
- public WeatherTool(String openWeatherMapAPIKey) {
- this.openWeatherMapAPIKey = openWeatherMapAPIKey;
- }
+ private String paramCityName = "cityName";
- public String getCurrentWeather(Map arguments) {
+ public WeatherTool() {
+ }
- String city = (String) arguments.get(paramCityName);
- System.out.println("Finding weather for city: " + city);
+ public String getCurrentWeather(Map arguments) {
+ String city = (String) arguments.get(paramCityName);
+ return "It is sunny in " + city;
+ }
- String url = String.format("https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=metric",
- city,
- this.openWeatherMapAPIKey);
-
- HttpClient client = HttpClient.newHttpClient();
- HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(url))
- .build();
- try {
- HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
- if (response.statusCode() == 200) {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode root = mapper.readTree(response.body());
- JsonNode main = root.path("main");
- double temperature = main.path("temp").asDouble();
- String description = root.path("weather").get(0).path("description").asText();
- return String.format("Weather in %s: %.1f°C, %s", city, temperature, description);
- } else {
- return "Could not retrieve weather data for " + city + ". Status code: "
- + response.statusCode();
- }
- } catch (IOException | InterruptedException e) {
- return "Error retrieving weather data: " + e.getMessage();
- }
- }
-
- public Tools.ToolSpecification getSpecification() {
- return Tools.ToolSpecification.builder()
- .functionName("weather-reporter")
- .functionDescription(
- "You are a tool who simply finds the city name from the user's message input/query about weather.")
- .toolFunction(this::getCurrentWeather)
- .toolPrompt(
- Tools.PromptFuncDefinition.builder()
- .type("prompt")
- .function(
- Tools.PromptFuncDefinition.PromptFuncSpec
- .builder()
- .name("get-city-name")
- .description("Get the city name")
- .parameters(
- Tools.PromptFuncDefinition.Parameters
- .builder()
- .type("object")
- .properties(
- Map.of(
- paramCityName,
- Tools.PromptFuncDefinition.Property
- .builder()
- .type("string")
- .description(
- "The name of the city. e.g. Bengaluru")
- .required(true)
- .build()))
- .required(java.util.List
- .of(paramCityName))
- .build())
- .build())
+ public Tools.ToolSpecification getSpecification() {
+ return Tools.ToolSpecification.builder()
+ .functionName("weather-reporter")
+ .functionDescription(
+ "You are a tool who simply finds the city name from the user's message input/query about weather.")
+ .toolFunction(this::getCurrentWeather)
+ .toolPrompt(
+ Tools.PromptFuncDefinition.builder()
+ .type("prompt")
+ .function(
+ Tools.PromptFuncDefinition.PromptFuncSpec
+ .builder()
+ .name("get-city-name")
+ .description("Get the city name")
+ .parameters(
+ Tools.PromptFuncDefinition.Parameters
+ .builder()
+ .type("object")
+ .properties(
+ Map.of(
+ paramCityName,
+ Tools.PromptFuncDefinition.Property
+ .builder()
+ .type("string")
+ .description(
+ "The name of the city. e.g. Bengaluru")
+ .required(true)
+ .build()))
+ .required(java.util.List
+ .of(paramCityName))
.build())
- .build();
- }
+ .build())
+ .build())
+ .build();
+ }
}