mirror of
				https://github.com/amithkoujalgi/ollama4j.git
				synced 2025-11-04 10:30:41 +01:00 
			
		
		
		
	Creates OllamaChatResult extension class
This commit is contained in:
		@@ -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<OllamaChatMessage> chatHistory;
 | 
			
		||||
 | 
			
		||||
    public OllamaChatResult(String response, long responseTime, int httpStatusCode,
 | 
			
		||||
            List<OllamaChatMessage> chatHistory) {
 | 
			
		||||
        super(response, responseTime, httpStatusCode);
 | 
			
		||||
        this.chatHistory = chatHistory;
 | 
			
		||||
        appendAnswerToChatHistory(response);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<OllamaChatMessage> getChatHistory() {
 | 
			
		||||
        return chatHistory;
 | 
			
		||||
    } 
 | 
			
		||||
 | 
			
		||||
    private void appendAnswerToChatHistory(String answer){
 | 
			
		||||
        OllamaChatMessage assistantMessage = new OllamaChatMessage(OllamaChatMessageRole.ASSISTANT, answer);
 | 
			
		||||
        this.chatHistory.add(assistantMessage);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user