mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-05-15 11:57:12 +02:00
Refactor
Signed-off-by: koujalgi.amith@gmail.com <koujalgi.amith@gmail.com>
This commit is contained in:
parent
a4e1b4afe9
commit
c9b05a725b
@ -9,6 +9,7 @@ import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatResult;
|
|||||||
import io.github.amithkoujalgi.ollama4j.core.models.embeddings.OllamaEmbeddingResponseModel;
|
import io.github.amithkoujalgi.ollama4j.core.models.embeddings.OllamaEmbeddingResponseModel;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.embeddings.OllamaEmbeddingsRequestModel;
|
import io.github.amithkoujalgi.ollama4j.core.models.embeddings.OllamaEmbeddingsRequestModel;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaGenerateRequestModel;
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaGenerateRequestModel;
|
||||||
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaStreamHandler;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.request.*;
|
import io.github.amithkoujalgi.ollama4j.core.models.request.*;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.tools.*;
|
import io.github.amithkoujalgi.ollama4j.core.tools.*;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.utils.Options;
|
import io.github.amithkoujalgi.ollama4j.core.utils.Options;
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package io.github.amithkoujalgi.ollama4j.core;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public interface OllamaStreamHandler extends Consumer<String>{
|
|
||||||
void accept(String message);
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
package io.github.amithkoujalgi.ollama4j.core.impl;
|
package io.github.amithkoujalgi.ollama4j.core.impl;
|
||||||
|
|
||||||
import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler;
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaStreamHandler;
|
||||||
|
|
||||||
public class ConsoleOutputStreamHandler implements OllamaStreamHandler {
|
public class ConsoleOutputStreamHandler implements OllamaStreamHandler {
|
||||||
private final StringBuffer response = new StringBuffer();
|
private final StringBuffer response = new StringBuffer();
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package io.github.amithkoujalgi.ollama4j.core.models.chat;
|
package io.github.amithkoujalgi.ollama4j.core.models.chat;
|
||||||
|
|
||||||
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaStreamHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler;
|
|
||||||
|
|
||||||
public class OllamaChatStreamObserver {
|
public class OllamaChatStreamObserver {
|
||||||
|
|
||||||
private OllamaStreamHandler streamHandler;
|
private OllamaStreamHandler streamHandler;
|
||||||
@ -17,12 +17,12 @@ public class OllamaChatStreamObserver {
|
|||||||
this.streamHandler = streamHandler;
|
this.streamHandler = streamHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notify(OllamaChatResponseModel currentResponsePart){
|
public void notify(OllamaChatResponseModel currentResponsePart) {
|
||||||
responseParts.add(currentResponsePart);
|
responseParts.add(currentResponsePart);
|
||||||
handleCurrentResponsePart(currentResponsePart);
|
handleCurrentResponsePart(currentResponsePart);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleCurrentResponsePart(OllamaChatResponseModel currentResponsePart){
|
protected void handleCurrentResponsePart(OllamaChatResponseModel currentResponsePart) {
|
||||||
message = message + currentResponsePart.getMessage().getContent();
|
message = message + currentResponsePart.getMessage().getContent();
|
||||||
streamHandler.accept(message);
|
streamHandler.accept(message);
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ package io.github.amithkoujalgi.ollama4j.core.models.generate;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler;
|
|
||||||
|
|
||||||
public class OllamaGenerateStreamObserver {
|
public class OllamaGenerateStreamObserver {
|
||||||
|
|
||||||
private OllamaStreamHandler streamHandler;
|
private OllamaStreamHandler streamHandler;
|
||||||
@ -17,12 +15,12 @@ public class OllamaGenerateStreamObserver {
|
|||||||
this.streamHandler = streamHandler;
|
this.streamHandler = streamHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notify(OllamaGenerateResponseModel currentResponsePart){
|
public void notify(OllamaGenerateResponseModel currentResponsePart) {
|
||||||
responseParts.add(currentResponsePart);
|
responseParts.add(currentResponsePart);
|
||||||
handleCurrentResponsePart(currentResponsePart);
|
handleCurrentResponsePart(currentResponsePart);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleCurrentResponsePart(OllamaGenerateResponseModel currentResponsePart){
|
protected void handleCurrentResponsePart(OllamaGenerateResponseModel currentResponsePart) {
|
||||||
message = message + currentResponsePart.getResponse();
|
message = message + currentResponsePart.getResponse();
|
||||||
streamHandler.accept(message);
|
streamHandler.accept(message);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package io.github.amithkoujalgi.ollama4j.core.models.generate;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public interface OllamaStreamHandler extends Consumer<String> {
|
||||||
|
void accept(String message);
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package io.github.amithkoujalgi.ollama4j.core.models.request;
|
package io.github.amithkoujalgi.ollama4j.core.models.request;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler;
|
|
||||||
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
|
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.BasicAuth;
|
import io.github.amithkoujalgi.ollama4j.core.models.BasicAuth;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
|
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatResponseModel;
|
import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatResponseModel;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatStreamObserver;
|
import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatStreamObserver;
|
||||||
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaStreamHandler;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.utils.OllamaRequestBody;
|
import io.github.amithkoujalgi.ollama4j.core.utils.OllamaRequestBody;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.utils.Utils;
|
import io.github.amithkoujalgi.ollama4j.core.utils.Utils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package io.github.amithkoujalgi.ollama4j.core.models.request;
|
package io.github.amithkoujalgi.ollama4j.core.models.request;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler;
|
|
||||||
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
|
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.BasicAuth;
|
import io.github.amithkoujalgi.ollama4j.core.models.BasicAuth;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
|
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaGenerateResponseModel;
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaGenerateResponseModel;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaGenerateStreamObserver;
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaGenerateStreamObserver;
|
||||||
|
import io.github.amithkoujalgi.ollama4j.core.models.generate.OllamaStreamHandler;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.utils.OllamaRequestBody;
|
import io.github.amithkoujalgi.ollama4j.core.utils.OllamaRequestBody;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.utils.Utils;
|
import io.github.amithkoujalgi.ollama4j.core.utils.Utils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user