From 65d852fdc90c4ec2bdde5b98cb7ac64816b28dfc Mon Sep 17 00:00:00 2001 From: Markus Klenke Date: Fri, 9 Feb 2024 22:48:48 +0000 Subject: [PATCH] Creates OllamaChatResult extension class --- .../core/models/chat/OllamaChatResult.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/io/github/amithkoujalgi/ollama4j/core/models/chat/OllamaChatResult.java diff --git a/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/chat/OllamaChatResult.java b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/chat/OllamaChatResult.java new file mode 100644 index 0000000..6ac6578 --- /dev/null +++ b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/chat/OllamaChatResult.java @@ -0,0 +1,32 @@ +package io.github.amithkoujalgi.ollama4j.core.models.chat; + +import java.util.List; + +import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult; + +/** + * Specific chat-API result that contains the chat history sent to the model and appends the answer as {@link OllamaChatResult} given by the + * {@link OllamaChatMessageRole#ASSISTANT} role. + */ +public class OllamaChatResult extends OllamaResult{ + + private List chatHistory; + + public OllamaChatResult(String response, long responseTime, int httpStatusCode, + List chatHistory) { + super(response, responseTime, httpStatusCode); + this.chatHistory = chatHistory; + appendAnswerToChatHistory(response); + } + + public List getChatHistory() { + return chatHistory; + } + + private void appendAnswerToChatHistory(String answer){ + OllamaChatMessage assistantMessage = new OllamaChatMessage(OllamaChatMessageRole.ASSISTANT, answer); + this.chatHistory.add(assistantMessage); + } + + +}