- KreaService: GenerateAsync() mit Job-Polling, Image-Download, Metadaten-Speicherung
- KreaEndpoint: POST /api/images/generate, GET /api/images, GET /api/images/file/{filename}, GET /api/images/status
- KreaImageRecord: Output-Model
- Output: data/images/<timestamp>-<index>.<ext> + data/images/<timestamp>.json
- 16 Modelle: flux, flux-kontext, flux-1.1-pro, imagen-3/4, chatgpt-image, runway-gen-4, etc.
- appsettings.json: KreaToken (Format: KEY_ID:SECRET), obsolete TelegramBotToken/WebhookSecret entfernt
85 lines
3.0 KiB
C#
85 lines
3.0 KiB
C#
using System;
|
||
using System.IO;
|
||
using System.Net.Http;
|
||
using Gott.Endpoints;
|
||
using Gott.Middleware;
|
||
using Gott.Services;
|
||
using Microsoft.AspNetCore.Builder;
|
||
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
|
||
var builder = WebApplication.CreateBuilder(args);
|
||
builder.Services.AddHttpClient();
|
||
|
||
var dataDir = Path.Combine(AppContext.BaseDirectory, "data");
|
||
|
||
var dbPath = Path.Combine(dataDir, "gott.db");
|
||
var authService = new AuthService(dbPath);
|
||
var dbService = new DatabaseService(dbPath);
|
||
dbService.EnsureDefaultUser(authService);
|
||
|
||
builder.Services.AddSingleton(authService);
|
||
builder.Services.AddSingleton(dbService);
|
||
builder.Services.AddSingleton(new ImageService());
|
||
builder.Services.AddSingleton(new StreamingTracker());
|
||
var memoryService = new MemoryService(dataDir);
|
||
var skillService = new SkillService(dataDir);
|
||
builder.Services.AddSingleton(memoryService);
|
||
builder.Services.AddSingleton(skillService);
|
||
|
||
// Shared Services
|
||
var toolService = new ToolService();
|
||
builder.Services.AddSingleton(toolService);
|
||
var chatService = new ChatService(dbService, toolService, memoryService, skillService);
|
||
builder.Services.AddSingleton(chatService);
|
||
|
||
// AnthropicService (Singleton – shared zwischen ChatEndpoint und TelegramService)
|
||
var anthropicToken = builder.Configuration["AnthropicToken"] ?? "";
|
||
var payloadLogging = builder.Configuration.GetValue<bool>("PayloadLogging", false);
|
||
var payloadLoggingGzip = builder.Configuration.GetValue<bool>("PayloadLoggingGzip", false);
|
||
builder.Services.AddSingleton<AnthropicService>(sp =>
|
||
new AnthropicService(
|
||
sp.GetRequiredService<IHttpClientFactory>(),
|
||
anthropicToken, toolService, dbService, memoryService,
|
||
payloadLogging, payloadLoggingGzip));
|
||
|
||
// Telegram Bot (pro Session – Token aus Session-Config)
|
||
var maxIterations = builder.Configuration.GetValue<int>("MaxIterations", 100);
|
||
builder.Services.AddSingleton<TelegramService>(sp =>
|
||
new TelegramService(
|
||
sp.GetRequiredService<IHttpClientFactory>(),
|
||
dbService, chatService,
|
||
sp.GetRequiredService<AnthropicService>(),
|
||
maxIterations));
|
||
|
||
// Krea Image Generation
|
||
var kreaToken = builder.Configuration["KreaToken"] ?? "";
|
||
builder.Services.AddSingleton(sp =>
|
||
new KreaService(sp.GetRequiredService<IHttpClientFactory>(), kreaToken, dataDir));
|
||
|
||
// Cronjob-Service (BackgroundService)
|
||
builder.Services.AddSingleton<CronjobService>();
|
||
builder.Services.AddHostedService<CronjobService>(sp => sp.GetRequiredService<CronjobService>());
|
||
|
||
var app = builder.Build();
|
||
app.UseDefaultFiles();
|
||
app.UseStaticFiles();
|
||
app.UseMiddleware<AuthMiddleware>();
|
||
|
||
app.MapAuthEndpoints();
|
||
app.MapChatEndpoint();
|
||
app.MapHistoryEndpoint();
|
||
app.MapSessionEndpoints();
|
||
app.MapAgentEndpoints();
|
||
app.MapWorkspaceEndpoint();
|
||
app.MapInfoEndpoint();
|
||
app.MapBackupEndpoint();
|
||
app.MapSkillEndpoints();
|
||
app.MapProfileEndpoints();
|
||
app.MapSettingsEndpoints();
|
||
app.MapTelegramEndpoints();
|
||
app.MapCronjobEndpoints();
|
||
app.MapKreaEndpoints();
|
||
|
||
app.Run("http://0.0.0.0:19000");
|