Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaChatResult.java
Go to the documentation of this file.
1/*
2 * Ollama4j - Java library for interacting with Ollama server.
3 * Copyright (c) 2025 Amith Koujalgi and contributors.
4 *
5 * Licensed under the MIT License (the "License");
6 * you may not use this file except in compliance with the License.
7 *
8*/
9package io.github.ollama4j.models.chat;
10
11import static io.github.ollama4j.utils.Utils.getObjectMapper;
12
13import com.fasterxml.jackson.core.JsonProcessingException;
14import java.util.List;
15import lombok.Getter;
16
21@Getter
22public class OllamaChatResult {
23
24 private final List<OllamaChatMessage> chatHistory;
25
26 private final OllamaChatResponseModel responseModel;
27
29 OllamaChatResponseModel responseModel, List<OllamaChatMessage> chatHistory) {
30 this.chatHistory = chatHistory;
31 this.responseModel = responseModel;
32 appendAnswerToChatHistory(responseModel);
33 }
34
35 private void appendAnswerToChatHistory(OllamaChatResponseModel response) {
36 this.chatHistory.add(response.getMessage());
37 }
38
39 @Override
40 public String toString() {
41 try {
42 return getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this);
43 } catch (JsonProcessingException e) {
44 throw new RuntimeException(e);
45 }
46 }
47}
OllamaChatResult(OllamaChatResponseModel responseModel, List< OllamaChatMessage > chatHistory)