Nomad changes
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s

This commit is contained in:
Henrik Jess Nielsen
2026-06-01 23:40:55 +02:00
parent 72b1a0a6ed
commit b4c07d3693
5723 changed files with 1130655 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
```csharp title="usage.cs"
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
var dockerClient = new DockerKreuzbergLib();
try
{
await dockerClient.StartContainerAsync();
await Task.Delay(2000);
var content = await dockerClient.ExtractFileAsync("document.pdf");
Console.WriteLine($"Extracted content:\n{content}");
}
finally
{
await dockerClient.StopContainerAsync();
}
class DockerKreuzbergLib
{
private const string ContainerName = "kreuzberg-api";
private const string ContainerImage = "kreuzberg:latest";
private const int ApiPort = 8000;
public async Task StartContainerAsync()
{
Console.WriteLine("Starting Kreuzberg Docker container...");
var processInfo = new ProcessStartInfo
{
FileName = "docker",
Arguments = $"run -d --name {ContainerName} -p {ApiPort}:8000 {ContainerImage}",
UseShellExecute = false,
RedirectStandardOutput = true,
};
using (var process = Process.Start(processInfo))
{
await process.WaitForExitAsync();
}
Console.WriteLine($"Container started on http://localhost:{ApiPort}");
}
public async Task<string> ExtractFileAsync(string filePath)
{
using (var client = new HttpClient())
{
var fileBytes = await File.ReadAllBytesAsync(filePath);
using (var content = new MultipartFormDataContent())
{
content.Add(new ByteArrayContent(fileBytes), "file", Path.GetFileName(filePath));
var response = await client.PostAsync(
$"http://localhost:{ApiPort}/api/extract",
content
);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<JsonElement>(json);
return result.GetProperty("content").GetString();
}
}
}
public async Task StopContainerAsync()
{
Console.WriteLine("Stopping Kreuzberg Docker container...");
var processInfo = new ProcessStartInfo
{
FileName = "docker",
Arguments = $"stop {ContainerName}",
UseShellExecute = false,
};
using (var process = Process.Start(processInfo))
{
await process.WaitForExitAsync();
}
processInfo.Arguments = $"rm {ContainerName}";
using (var process = Process.Start(processInfo))
{
await process.WaitForExitAsync();
}
Console.WriteLine("Container stopped and removed");
}
}
```