Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaChatStreamObserver.java
Go to the documentation of this file.
1
package
io.github.ollama4j.models.chat;
2
3
import
io.github.ollama4j.models.generate.OllamaStreamHandler;
4
5
import
java.util.ArrayList;
6
import
java.util.List;
7
8
public
class
OllamaChatStreamObserver
{
9
10
private
OllamaStreamHandler
streamHandler;
11
12
private
List<OllamaChatResponseModel> responseParts =
new
ArrayList<>();
13
14
private
String message =
""
;
15
16
public
OllamaChatStreamObserver
(
OllamaStreamHandler
streamHandler) {
17
this.streamHandler = streamHandler;
18
}
19
20
public
void
notify
(
OllamaChatResponseModel
currentResponsePart) {
21
responseParts.add(currentResponsePart);
22
handleCurrentResponsePart
(currentResponsePart);
23
}
24
25
protected
void
handleCurrentResponsePart
(
OllamaChatResponseModel
currentResponsePart) {
26
message = message + currentResponsePart.getMessage().getContent();
27
streamHandler.
accept
(message);
28
}
29
30
31
}
io.github.ollama4j.models.chat.OllamaChatResponseModel
Definition
OllamaChatResponseModel.java:9
io.github.ollama4j.models.chat.OllamaChatStreamObserver
Definition
OllamaChatStreamObserver.java:8
io.github.ollama4j.models.chat.OllamaChatStreamObserver.handleCurrentResponsePart
void handleCurrentResponsePart(OllamaChatResponseModel currentResponsePart)
Definition
OllamaChatStreamObserver.java:25
io.github.ollama4j.models.chat.OllamaChatStreamObserver.OllamaChatStreamObserver
OllamaChatStreamObserver(OllamaStreamHandler streamHandler)
Definition
OllamaChatStreamObserver.java:16
io.github.ollama4j.models.chat.OllamaChatStreamObserver.notify
void notify(OllamaChatResponseModel currentResponsePart)
Definition
OllamaChatStreamObserver.java:20
io.github.ollama4j.models.generate.OllamaStreamHandler
Definition
OllamaStreamHandler.java:5
io.github.ollama4j.models.generate.OllamaStreamHandler.accept
void accept(String message)
src
main
java
io
github
ollama4j
models
chat
OllamaChatStreamObserver.java
Generated by
1.12.0