This commit is contained in:
@@ -401,6 +401,32 @@ public class Core {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* A check to exit early if Ollama isn't reachable.
|
||||
*/
|
||||
private void confirmOllama()
|
||||
{
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(3 * 1000);
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
|
||||
if (responseCode != HttpURLConnection.HTTP_OK) {
|
||||
new RuntimeException("Ollama is un-responsive on url: " + url.toString()).printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}catch (IOException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
System.out.println("Can not reach Ollama!");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Core with the provided PrintMessageHandler,
|
||||
* defaulting the Ollama backend to {@code localhost}.
|
||||
@@ -425,6 +451,7 @@ public class Core {
|
||||
|
||||
initDirectories();
|
||||
initOllamaUrl();
|
||||
confirmOllama();
|
||||
initLogWriter();
|
||||
initScheduler();
|
||||
initShutdownHook();
|
||||
|
||||
Reference in New Issue
Block a user