Klasse OllamaAPI
java.lang.Object
io.github.amithkoujalgi.ollama4j.core.OllamaAPI
The base Ollama API class.
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungAsk a question to a model running on Ollama server.Ask a question to a model running on Ollama server and get a callback handle that can be used to check for status and get the response from the model later.askWithImageFiles(String model, String promptText, List<File> imageFiles) With one or more image files, ask a question to a model running on Ollama server.askWithImageURLs(String model, String promptText, List<String> imageURLs) With one or more image URLs, ask a question to a model running on Ollama server.voidcreateModelWithFilePath(String modelName, String modelFilePath) Create a custom model from a model file.voidcreateModelWithModelFileContents(String modelName, String modelFileContents) Create a custom model from a model file.voiddeleteModel(String modelName, boolean ignoreIfNotPresent) Delete a model from Ollama server.generateEmbeddings(String model, String prompt) Generate embeddings for a given text from a modelgetModelDetails(String modelName) Gets model details from the Ollama server.List available models from Ollama server.booleanping()API to check the reachability of Ollama server.voidPull a model on the Ollama server from the list of available models.voidsetBasicAuth(String username, String password) voidsetRequestTimeoutSeconds(long requestTimeoutSeconds) voidsetVerbose(boolean verbose) Set/unset logging of responses
-
Konstruktordetails
-
OllamaAPI
Instantiates the Ollama API.- Parameter:
host- the host address of Ollama server
-
-
Methodendetails
-
setRequestTimeoutSeconds
public void setRequestTimeoutSeconds(long requestTimeoutSeconds) -
setVerbose
public void setVerbose(boolean verbose) Set/unset logging of responses- Parameter:
verbose- true/false
-
setBasicAuth
-
ping
public boolean ping()API to check the reachability of Ollama server.- Gibt zurück:
- true if the server is reachable, false otherwise.
-
listModels
public List<Model> listModels() throws OllamaBaseException, IOException, InterruptedException, URISyntaxExceptionList available models from Ollama server.- Gibt zurück:
- the list
- Löst aus:
OllamaBaseExceptionIOExceptionInterruptedExceptionURISyntaxException
-
pullModel
public void pullModel(String modelName) throws OllamaBaseException, IOException, URISyntaxException, InterruptedException Pull a model on the Ollama server from the list of available models.- Parameter:
modelName- the name of the model- Löst aus:
OllamaBaseExceptionIOExceptionURISyntaxExceptionInterruptedException
-
getModelDetails
public ModelDetail getModelDetails(String modelName) throws IOException, OllamaBaseException, InterruptedException Gets model details from the Ollama server.- Parameter:
modelName- the model- Gibt zurück:
- the model details
- Löst aus:
IOExceptionOllamaBaseExceptionInterruptedException
-
createModelWithFilePath
public void createModelWithFilePath(String modelName, String modelFilePath) throws IOException, InterruptedException, OllamaBaseException Create a custom model from a model file. Read more about custom model file creation here.- Parameter:
modelName- the name of the custom model to be created.modelFilePath- the path to model file that exists on the Ollama server.- Löst aus:
IOExceptionInterruptedExceptionOllamaBaseException
-
createModelWithModelFileContents
public void createModelWithModelFileContents(String modelName, String modelFileContents) throws IOException, InterruptedException, OllamaBaseException Create a custom model from a model file. Read more about custom model file creation here.- Parameter:
modelName- the name of the custom model to be created.modelFileContents- the path to model file that exists on the Ollama server.- Löst aus:
IOExceptionInterruptedExceptionOllamaBaseException
-
deleteModel
public void deleteModel(String modelName, boolean ignoreIfNotPresent) throws IOException, InterruptedException, OllamaBaseException Delete a model from Ollama server.- Parameter:
modelName- the name of the model to be deleted.ignoreIfNotPresent- - ignore errors if the specified model is not present on Ollama server.- Löst aus:
IOExceptionInterruptedExceptionOllamaBaseException
-
generateEmbeddings
public List<Double> generateEmbeddings(String model, String prompt) throws IOException, InterruptedException, OllamaBaseException Generate embeddings for a given text from a model- Parameter:
model- name of model to generate embeddings fromprompt- text to generate embeddings for- Gibt zurück:
- embeddings
- Löst aus:
IOExceptionInterruptedExceptionOllamaBaseException
-
ask
public OllamaResult ask(String model, String promptText) throws OllamaBaseException, IOException, InterruptedException Ask a question to a model running on Ollama server. This is a sync/blocking call.- Parameter:
model- the ollama model to ask the question topromptText- the prompt/question text- Gibt zurück:
- OllamaResult - that includes response text and time taken for response
- Löst aus:
OllamaBaseExceptionIOExceptionInterruptedException
-
askAsync
Ask a question to a model running on Ollama server and get a callback handle that can be used to check for status and get the response from the model later. This would be an async/non-blocking call.- Parameter:
model- the ollama model to ask the question topromptText- the prompt/question text- Gibt zurück:
- the ollama async result callback handle
-
askWithImageFiles
public OllamaResult askWithImageFiles(String model, String promptText, List<File> imageFiles) throws OllamaBaseException, IOException, InterruptedException With one or more image files, ask a question to a model running on Ollama server. This is a sync/blocking call.- Parameter:
model- the ollama model to ask the question topromptText- the prompt/question textimageFiles- the list of image files to use for the question- Gibt zurück:
- OllamaResult - that includes response text and time taken for response
- Löst aus:
OllamaBaseExceptionIOExceptionInterruptedException
-
askWithImageURLs
public OllamaResult askWithImageURLs(String model, String promptText, List<String> imageURLs) throws OllamaBaseException, IOException, InterruptedException, URISyntaxException With one or more image URLs, ask a question to a model running on Ollama server. This is a sync/blocking call.- Parameter:
model- the ollama model to ask the question topromptText- the prompt/question textimageURLs- the list of image URLs to use for the question- Gibt zurück:
- OllamaResult - that includes response text and time taken for response
- Löst aus:
OllamaBaseExceptionIOExceptionInterruptedExceptionURISyntaxException
-