mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-05-15 20:07:10 +02:00
updated doc
This commit is contained in:
parent
b05f1d9b12
commit
12aa38cab0
@ -255,11 +255,12 @@ public class StructuredOutput {
|
|||||||
|
|
||||||
OllamaAPI api = new OllamaAPI(host);
|
OllamaAPI api = new OllamaAPI(host);
|
||||||
|
|
||||||
String chatModel = "llama3.1:8b";
|
int age = 28;
|
||||||
chatModel = "qwen2.5:0.5b";
|
boolean available = false;
|
||||||
api.pullModel(chatModel);
|
|
||||||
|
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<>();
|
Map<String, Object> format = new HashMap<>();
|
||||||
format.put("type", "object");
|
format.put("type", "object");
|
||||||
format.put("properties", new HashMap<String, Object>() {
|
format.put("properties", new HashMap<String, Object>() {
|
||||||
@ -278,11 +279,12 @@ public class StructuredOutput {
|
|||||||
});
|
});
|
||||||
format.put("required", Arrays.asList("age", "available"));
|
format.put("required", Arrays.asList("age", "available"));
|
||||||
|
|
||||||
OllamaResult result = api.generate(chatModel, prompt, format);
|
OllamaResult result = api.generate(CHAT_MODEL_QWEN_SMALL, prompt, format);
|
||||||
Person person = result.getStructuredResponse(Person.class);
|
|
||||||
System.out.println(person);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Person person = result.as(Person.class);
|
||||||
|
System.out.println(person.getAge());
|
||||||
|
System.out.println(person.getAvailable());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -183,8 +183,6 @@ public class OllamaAPIIntegrationTest {
|
|||||||
assertNotNull(result.getResponse());
|
assertNotNull(result.getResponse());
|
||||||
assertFalse(result.getResponse().isEmpty());
|
assertFalse(result.getResponse().isEmpty());
|
||||||
|
|
||||||
System.out.println(result);
|
|
||||||
|
|
||||||
assertEquals(result.getStructuredResponse().get("age").toString(),
|
assertEquals(result.getStructuredResponse().get("age").toString(),
|
||||||
result.getStructuredResponse().get("age").toString());
|
result.getStructuredResponse().get("age").toString());
|
||||||
assertEquals(result.getStructuredResponse().get("available").toString(),
|
assertEquals(result.getStructuredResponse().get("available").toString(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user