This commit is contained in:
Amith Koujalgi 2023-12-17 11:44:04 +05:30
parent 9658dd2993
commit b6c1afff32
2 changed files with 65 additions and 14 deletions

View File

@ -251,13 +251,13 @@ public class OllamaAPI {
/** /**
* Ask a question to a model running on Ollama server. This is a sync/blocking call. * Ask a question to a model running on Ollama server. This is a sync/blocking call.
* *
* @param ollamaModelType the ollama model to ask the question to * @param model the ollama model to ask the question to
* @param promptText the prompt/question text * @param promptText the prompt/question text
* @return OllamaResult - that includes response text and time taken for response * @return OllamaResult - that includes response text and time taken for response
*/ */
public OllamaResult ask(String ollamaModelType, String promptText) public OllamaResult ask(String model, String promptText)
throws OllamaBaseException, IOException, InterruptedException { throws OllamaBaseException, IOException, InterruptedException {
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(ollamaModelType, promptText); OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText);
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
HttpClient httpClient = HttpClient.newHttpClient(); HttpClient httpClient = HttpClient.newHttpClient();
URI uri = URI.create(this.host + "/api/generate"); URI uri = URI.create(this.host + "/api/generate");
@ -304,12 +304,12 @@ public class OllamaAPI {
* to check for status and get the response from the model later. This would be an * to check for status and get the response from the model later. This would be an
* async/non-blocking call. * async/non-blocking call.
* *
* @param ollamaModelType the ollama model to ask the question to * @param model the ollama model to ask the question to
* @param promptText the prompt/question text * @param promptText the prompt/question text
* @return the ollama async result callback handle * @return the ollama async result callback handle
*/ */
public OllamaAsyncResultCallback askAsync(String ollamaModelType, String promptText) { public OllamaAsyncResultCallback askAsync(String model, String promptText) {
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(ollamaModelType, promptText); OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText);
HttpClient httpClient = HttpClient.newHttpClient(); HttpClient httpClient = HttpClient.newHttpClient();
URI uri = URI.create(this.host + "/api/generate"); URI uri = URI.create(this.host + "/api/generate");
OllamaAsyncResultCallback ollamaAsyncResultCallback = OllamaAsyncResultCallback ollamaAsyncResultCallback =

View File

@ -1,12 +1,63 @@
package io.github.amithkoujalgi.ollama4j.core.types; package io.github.amithkoujalgi.ollama4j.core.types;
/**
* A class to provide constants for all the supported models by Ollama.
*
* <p>Refer to the full list of models and the details here: <a
* href="https://ollama.ai/library">https://ollama.ai/library<a/>
*/
@SuppressWarnings("ALL")
public class OllamaModelType { public class OllamaModelType {
public static final String LLAMA2 = "llama2"; public static final String LLAMA2 = "llama2";
public static final String MISTRAL = "mistral"; public static final String MISTRAL = "mistral";
public static final String MEDLLAMA2 = "medllama2"; public static final String LLAVA = "llava";
public static final String MIXTRAL = "mixtral";
public static final String STARLING_LM = "starling-lm";
public static final String NEURAL_CHAT = "neural-chat";
public static final String CODELLAMA = "codellama"; public static final String CODELLAMA = "codellama";
public static final String LLAMA2_UNCENSORED = "llama2-uncensored";
public static final String DOLPHIN_MIXTRAL = "dolphin-mixtral";
public static final String ORCA_MINI = "orca-mini";
public static final String VICUNA = "vicuna"; public static final String VICUNA = "vicuna";
public static final String ORCAMINI = "orca-mini"; public static final String WIZARD_VICUNA_UNCENSORED = "wizard-vicuna-uncensored";
public static final String PHIND_CODELLAMA = "phind-codellama";
public static final String ZEPHYR = "zephyr";
public static final String WIZARDCODER = "wizardcoder";
public static final String MISTRAL_OPENORCA = "mistral-openorca";
public static final String NOUS_HERMES = "nous-hermes";
public static final String DEEPSEEK_CODER = "deepseek-coder";
public static final String WIZARD_MATH = "wizard-math";
public static final String LLAMA2_CHINESE = "llama2-chinese";
public static final String FALCON = "falcon";
public static final String ORCA2 = "orca2";
public static final String STABLE_BELUGA = "stable-beluga";
public static final String CODEUP = "codeup";
public static final String EVERYTHINGLM = "everythinglm";
public static final String MEDLLAMA2 = "medllama2";
public static final String WIZARDLM_UNCENSORED = "wizardlm-uncensored";
public static final String STARCODER = "starcoder";
public static final String DOLPHIN22_MISTRAL = "dolphin2.2-mistral";
public static final String OPENCHAT = "openchat";
public static final String WIZARD_VICUNA = "wizard-vicuna";
public static final String OPENHERMES25_MISTRAL = "openhermes2.5-mistral";
public static final String OPEN_ORCA_PLATYPUS2 = "open-orca-platypus2";
public static final String YI = "yi";
public static final String YARN_MISTRAL = "yarn-mistral";
public static final String SAMANTHA_MISTRAL = "samantha-mistral";
public static final String SQLCODER = "sqlcoder"; public static final String SQLCODER = "sqlcoder";
public static final String WIZARDMATH = "wizard-math"; public static final String YARN_LLAMA2 = "yarn-llama2";
public static final String MEDITRON = "meditron";
public static final String STABLELM_ZEPHYR = "stablelm-zephyr";
public static final String OPENHERMES2_MISTRAL = "openhermes2-mistral";
public static final String DEEPSEEK_LLM = "deepseek-llm";
public static final String MISTRALLITE = "mistrallite";
public static final String DOLPHIN21_MISTRAL = "dolphin2.1-mistral";
public static final String WIZARDLM = "wizardlm";
public static final String CODEBOOGA = "codebooga";
public static final String MAGICODER = "magicoder";
public static final String GOLIATH = "goliath";
public static final String NEXUSRAVEN = "nexusraven";
public static final String ALFRED = "alfred";
public static final String XWINLM = "xwinlm";
public static final String BAKLLAVA = "bakllava";
} }