updated doc

This commit is contained in:
amithkoujalgi 2025-03-24 23:43:20 +05:30
parent b05f1d9b12
commit 12aa38cab0
No known key found for this signature in database
GPG Key ID: E29A37746AF94B70
2 changed files with 10 additions and 10 deletions

View File

@ -255,11 +255,12 @@ public class StructuredOutput {
OllamaAPI api = new OllamaAPI(host);
String chatModel = "llama3.1:8b";
chatModel = "qwen2.5:0.5b";
api.pullModel(chatModel);
int age = 28;
boolean available = false;
String prompt = "Batman is " + age + " years old and is " + (available ? "available" : "not available")
+ " because he is busy saving Gotham City. Respond using JSON";
String prompt = "Ollama is 22 years old and is busy saving the world. Respond using JSON";
Map<String, Object> format = new HashMap<>();
format.put("type", "object");
format.put("properties", new HashMap<String, Object>() {
@ -278,11 +279,12 @@ public class StructuredOutput {
});
format.put("required", Arrays.asList("age", "available"));
OllamaResult result = api.generate(chatModel, prompt, format);
Person person = result.getStructuredResponse(Person.class);
System.out.println(person);
}
OllamaResult result = api.generate(CHAT_MODEL_QWEN_SMALL, prompt, format);
Person person = result.as(Person.class);
System.out.println(person.getAge());
System.out.println(person.getAvailable());
}
}
@Data

View File

@ -183,8 +183,6 @@ public class OllamaAPIIntegrationTest {
assertNotNull(result.getResponse());
assertFalse(result.getResponse().isEmpty());
System.out.println(result);
assertEquals(result.getStructuredResponse().get("age").toString(),
result.getStructuredResponse().get("age").toString());
assertEquals(result.getStructuredResponse().get("available").toString(),