feat: add Mistral support

This commit is contained in:
2025-03-28 10:26:37 +01:00
parent cd3b58f7f8
commit dd361e8cea
8 changed files with 61 additions and 2205 deletions

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/home/xeon0x/Projects/ClientServer" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/home/xeon0x/Projects/ClientServer")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi
# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/home/xeon0x/Projects/ClientServer" true
# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/home/xeon0x/Projects/ClientServer/.envrc"
# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/home/xeon0x/Projects/ClientServer/.envrc" "/home/xeon0x/Projects/ClientServer/.direnv"/*.rc

View File

@@ -1 +0,0 @@
/nix/store/64wh73gawgn91x4mdp92dxazdy2v0v05-source

View File

@@ -1 +0,0 @@
/nix/store/s1fbk6a410xn8vcaj54iqv22agyn0ria-source

View File

@@ -1 +0,0 @@
/nix/store/n7xw4vhgmr3is6kljqb8g8z37gg9339m-nix-shell-env

2
.gitignore vendored
View File

@@ -3,3 +3,5 @@
# Ignore Gradle build output directory # Ignore Gradle build output directory
build build
config.properties
.direnv

View File

@@ -9,6 +9,6 @@ public class App {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(new App().getGreeting()); System.out.println(new App().getGreeting());
Server.scannerUDP(0, 5000); MistralDirectAPI.main(new String[] {});
} }
} }

View File

@@ -0,0 +1,58 @@
package clientserver;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.io.FileInputStream;
import java.util.Properties;
public class MistralDirectAPI {
public static void main(String[] args) {
String apiKey;
// Load API key from properties file
try {
Properties props = new Properties();
FileInputStream input = new FileInputStream("config.properties");
props.load(input);
apiKey = props.getProperty("mistral.api.key");
input.close();
} catch (IOException e) {
System.err.println("Could not load API key: " + e.getMessage());
return;
}
String payload =
"""
{
"model": "mistral-medium",
"messages": [
{ "role": "user", "content": "Explain recursion like I'm five." }
]
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.mistral.ai/v1/chat/completions"))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpClient client = HttpClient.newHttpClient();
try {
HttpResponse<String> response = client.send(
request,
HttpResponse.BodyHandlers.ofString()
);
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Body: " + response.body());
} catch (IOException | InterruptedException e) {
System.err.println("Error occurred: " + e.getMessage());
}
}
}