-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainClass.cs
More file actions
54 lines (47 loc) · 1.81 KB
/
Copy pathMainClass.cs
File metadata and controls
54 lines (47 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
using LocalKIAgent; // Hier liegt dein ResponseFormatter
class MainClass
{
static async Task Main(string[] args)
{
// 1) Ollama-Client
var client = new OllamaChatClient(
new Uri("http://localhost:11434/"),
modelId: "deepseek-r1:8b"
);
// 2) Formatter konfigurieren
var formatter = new ResponseFormatter
{ // Beispiel-Prefix
PrefixColor = ConsoleColor.DarkGreen,
EnableWordWrap = true,
// WrapWidth = 80, // alternativ feste Breite
};
Console.WriteLine("Lokale KI bereit — gib deinen Prompt ein (oder 'exit' zum Beenden):");
while (true)
{
Console.Write("> ");
var input = Console.ReadLine();
if (string.IsNullOrWhiteSpace(input) || input.Trim().Equals("exit", StringComparison.OrdinalIgnoreCase))
break;
try
{
// 3) System- und User-Nachricht
var systemMessage = new ChatMessage(ChatRole.System, " Antworte immer auf Deutsch!");
var userMessage = new ChatMessage(ChatRole.User, input);
// Wichtig: System zuerst, dann User
var response = await client.GetResponseAsync(new[] { userMessage, systemMessage });
// 4) Ausgabe über den Formatter
formatter.WriteConversation(input,response.Messages);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Fehler: {ex.Message}");
Console.ResetColor();
}
}
Console.WriteLine("Programm beendet.");
}
}