mirror of
https://github.com/ritonioz/minecraft-ai-companion-mod-EMVs12-Project.git
synced 2026-03-18 07:10:20 +01:00
Compare commits
1 Commits
antonio
...
ef2567e2ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef2567e2ee |
2
.env
Normal file
2
.env
Normal file
@@ -0,0 +1,2 @@
|
||||
API_BASE_URL="ollama.cametendo.org"
|
||||
MODEL="gpt-oss:20b"
|
||||
0
.env.example
Normal file
0
.env.example
Normal file
@@ -12,11 +12,16 @@ import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public class Aicompanion2_0 implements ModInitializer {
|
||||
|
||||
public static final String MOD_ID = "aicompanion2_0";
|
||||
private static String API_BASE_URL = "http://localhost:11434";
|
||||
private static String API_BASE_URL = "http://ollama.cametendo.org";
|
||||
private static String API_PATH = "/api/generate";
|
||||
|
||||
@Override
|
||||
@@ -73,20 +78,21 @@ public class Aicompanion2_0 implements ModInitializer {
|
||||
System.out.println("[" + MOD_ID + "] MOD GELADEN!");
|
||||
}
|
||||
|
||||
// Innerhalb deiner Klasse Aicompanion2_0
|
||||
|
||||
private String callOllama(String prompt) throws Exception {
|
||||
// URL deines Ollama‑Servers, ggf. anpassen
|
||||
URL url = new URL(API_BASE_URL + API_PATH);
|
||||
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
|
||||
conn.setDoOutput(true);
|
||||
|
||||
// WICHTIG: "stream": false hinzugefügt
|
||||
String json = """
|
||||
{
|
||||
"model": "llama3",
|
||||
"prompt": "%s"
|
||||
"model": "gpt-oss:20b",
|
||||
"prompt": "%s",
|
||||
"stream": false
|
||||
}
|
||||
""".formatted(prompt.replace("\"", "\\\""));
|
||||
|
||||
@@ -95,28 +101,28 @@ public class Aicompanion2_0 implements ModInitializer {
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
int status = conn.getResponseCode();
|
||||
if (status != 200) {
|
||||
System.out.println("[" + MOD_ID + "] Ollama HTTP Status: " + status);
|
||||
return null;
|
||||
}
|
||||
if (conn.getResponseCode() != 200) return "Fehler: " + conn.getResponseCode();
|
||||
|
||||
StringBuilder resp = new StringBuilder();
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream(), "utf-8"))) {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
resp.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
conn.disconnect();
|
||||
|
||||
// Sehr einfach: komplette JSON‑Antwort zurückgeben
|
||||
// Später können wir das noch sauber parsen
|
||||
return resp.toString();
|
||||
// Primitives Parsing der Antwort (ohne externe Library)
|
||||
String fullResponse = resp.toString();
|
||||
if (fullResponse.contains("\"response\":\"")) {
|
||||
int start = fullResponse.indexOf("\"response\":\"") + 12;
|
||||
int end = fullResponse.indexOf("\"", start);
|
||||
return fullResponse.substring(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
return fullResponse;
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
try {
|
||||
Path configPath = Path.of("config", "aicompanion2_0.properties");
|
||||
@@ -130,5 +136,4 @@ private void loadConfig() {
|
||||
System.out.println("[" + MOD_ID + "] Keine Config gefunden, benutze Default-API.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user