Class Core
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCore(@NotNull PrintAdvanceMessageHandler printMessageHandler) Creates a new instance of Core with the provided PrintMessageHandler, defaulting the Ollama backend tolocalhost.Core(@NotNull PrintAdvanceMessageHandler printMessageHandler, @NotNull String ollamaIP) Creates a new instance of Core with the provided PrintMessageHandler and a specific Ollama backend address. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTool(OllamaFunctionTool functionTool, String source) Adds a new tool to the SystemvoidaddTools(OllamaFunctionTools tools) Adds a list of tools to the Systemvoidcancel()voidenablePlugins(File pluginDirectory) static voidEnsures that a directory exists at the given path, creating it if it does not.static voidflushLog()Flushes the log fileGets the list of tools added to the SystemGets the Ollama ObjectvoidhandleResponse(org.json.JSONObject response) Handles the response from Ollama.CompletableFuture<org.json.JSONObject> Queries Ollama and resolves once the full response is available, discarding any intermediate streaming chunks along the way.CompletableFuture<org.json.JSONObject> qurryOllama(Consumer<org.json.JSONObject> onChunk) Queries Ollama, invokingonChunkfor each JSON object received from the server, and resolves once the final response is available.voidremoveTool(String name) Removes a tool with a given namestatic voidsetLogDirectory(String logDirectory) voidsetOllamaObject(OllamaObject ollamaObject) Sets theollamaObjectobject to the provided argument, Also adds the memory base system.voidsetOllamaObjectNoMemory(OllamaObject ollamaObject) Sets theollamaObjectobject to the provided argument, Dose not add the base system for memory.static voidWrites a message to the log file
-
Constructor Details
-
Core
Creates a new instance of Core with the provided PrintMessageHandler, defaulting the Ollama backend tolocalhost.- Parameters:
printMessageHandler- The PrintMessageHandler to use as the default output
-
Core
public Core(@NotNull @NotNull PrintAdvanceMessageHandler printMessageHandler, @NotNull @NotNull String ollamaIP) Creates a new instance of Core with the provided PrintMessageHandler and a specific Ollama backend address.- Parameters:
printMessageHandler- The PrintMessageHandler to use as the default outputollamaIP- The IP or hostname of the Ollama backend
-
-
Method Details
-
setLogDirectory
-
ensureDir
Ensures that a directory exists at the given path, creating it if it does not.- Parameters:
path- The path of the directory to create
-
setOllamaObject
Sets theollamaObjectobject to the provided argument, Also adds the memory base system. SeesetOllamaObjectNoMemory(OllamaObject)if you don't want to add memory functions- Parameters:
ollamaObject- The OllamaObject to use
-
setOllamaObjectNoMemory
Sets theollamaObjectobject to the provided argument, Dose not add the base system for memory. seesetOllamaObject(OllamaObject)if you want to add memory function- Parameters:
ollamaObject- The OllamaObject to use
-
addTool
Adds a new tool to the System- Parameters:
functionTool- The tool to addsource- The source of the tool
-
addTools
Adds a list of tools to the System- Parameters:
tools- The tools to add
-
getFuntionTools
Gets the list of tools added to the System- Returns:
- The list of tools added to the System compressed as Pairs of the tool and the source
-
getOllamaObject
-
removeTool
Removes a tool with a given name- Parameters:
name- The tool to remove
-
flushLog
public static void flushLog()Flushes the log file -
cancel
public void cancel() -
qurryOllama
Queries Ollama and resolves once the full response is available, discarding any intermediate streaming chunks along the way.This is a convenience overload of
qurryOllama(Consumer)with a no-op chunk listener. Whether the underlying request is actually sent as a streaming or non-streaming HTTP request is determined entirely by this query'sOllamaObject'sstreamsetting — this method does not itself impose a mode. If theOllamaObjectis configured to stream, each intermediate chunk is still received and parsed internally, just not exposed to the caller; usequrryOllama(Consumer)if intermediate chunks are needed.- Returns:
- a future that resolves to the final response object once generation completes
-
qurryOllama
Queries Ollama, invokingonChunkfor each JSON object received from the server, and resolves once the final response is available.Whether this is a streaming or non-streaming exchange is determined by this query's
OllamaObject'sstreamsetting, not by which overload was called:- If
streamistrue, Ollama emits one JSON object per line as generation progresses;onChunkfires once per line, in order, as each arrives. - If
streamisfalse, Ollama emits the entire response as a single object once generation is complete;onChunkfires exactly once with that full object.
done: true) response object —onChunkis for observing progress, the returned future is for "the response is complete."If
cancel()is called while this query is in flight, the underlying connection is closed and the returned future completes exceptionally with aCancellationException.- Parameters:
onChunk- callback invoked for each response object received from Ollama, in arrival order; never invoked withnull- Returns:
- a future that resolves to the final response object once generation completes
- If
-
handleResponse
public void handleResponse(org.json.JSONObject response) Handles the response from Ollama. Processes tool calls, logs information, appends messages to the OllamaObject, and prints output to the user.- Parameters:
response- The response from Ollama
-
writeLog
Writes a message to the log file- Parameters:
message- The message to write
-
enablePlugins
-