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,46 @@
```csharp title="basic_cli.cs"
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;
using Kreuzberg;
var rootCommand = new RootCommand("Kreuzberg document extraction CLI");
var extractFileCommand = new Command("extract-file", "Extract text from a document file");
var filePath = new Argument<string>("path", "Path to the document file");
var outputFormat = new Option<string>(
new[] { "-f", "--format" },
getDefaultValue: () => "text",
"Output format (text, json)"
);
extractFileCommand.AddArgument(filePath);
extractFileCommand.AddOption(outputFormat);
extractFileCommand.SetHandler(async (path, format) =>
{
try
{
var result = await KreuzbergLib.ExtractFileAsync(path);
if (format == "json")
{
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(result));
}
else
{
Console.WriteLine(result.Content);
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error: {ex.Message}");
Environment.Exit(1);
}
}, filePath, outputFormat);
rootCommand.AddCommand(extractFileCommand);
return await rootCommand.InvokeAsync(args);
```

View File

@@ -0,0 +1,75 @@
```csharp title="cli_with_config.cs"
using System;
using System.CommandLine;
using System.Text.Json;
using System.Threading.Tasks;
using Kreuzberg;
var rootCommand = new RootCommand("Kreuzberg with configuration");
var extractCommand = new Command("extract", "Extract with custom configuration");
var filePath = new Argument<string>("path", "Document file path");
var configPath = new Option<string>(
new[] { "-c", "--config" },
"Path to JSON configuration file"
);
var forceOcr = new Option<bool>(
new[] { "--force-ocr" },
"Force OCR processing"
);
var useCache = new Option<bool>(
new[] { "--use-cache" },
getDefaultValue: () => true,
"Use caching (default: true)"
);
extractCommand.AddArgument(filePath);
extractCommand.AddOption(configPath);
extractCommand.AddOption(forceOcr);
extractCommand.AddOption(useCache);
extractCommand.SetHandler(async (path, config, ocr, cache) =>
{
try
{
ExtractionConfig extractionConfig;
if (!string.IsNullOrEmpty(config))
{
var json = await System.IO.File.ReadAllTextAsync(config);
extractionConfig = JsonSerializer.Deserialize<ExtractionConfig>(json);
}
else
{
extractionConfig = new ExtractionConfig
{
UseCache = cache,
ForceOcr = ocr,
};
}
Console.WriteLine("Extracting with configuration:");
Console.WriteLine($" - File: {path}");
Console.WriteLine($" - Force OCR: {extractionConfig.ForceOcr}");
Console.WriteLine($" - Use Cache: {extractionConfig.UseCache}");
var result = await KreuzbergLib.ExtractFileAsync(path, extractionConfig);
Console.WriteLine($"\nExtraction complete:");
Console.WriteLine($" - Content length: {result.Content.Length}");
Console.WriteLine($" - Format: {result.Metadata.FormatType}");
Console.WriteLine($" - Languages: {string.Join(", ", result.DetectedLanguages)}");
Console.WriteLine($"\n{result.Content}");
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error: {ex.Message}");
Environment.Exit(1);
}
}, filePath, configPath, forceOcr, useCache);
rootCommand.AddCommand(extractCommand);
return await rootCommand.InvokeAsync(args);
```