init code

This commit is contained in:
Christoph K.
2026-02-25 07:30:06 +01:00
parent 270eb56ac8
commit 797657c56b
7 changed files with 403 additions and 0 deletions

67
main.go Normal file
View File

@@ -0,0 +1,67 @@
package main
import (
"bufio"
"context"
"fmt"
"log"
"os"
"strconv"
"strings"
"github.com/openai/openai-go"
oaioption "github.com/openai/openai-go/option"
"llm-agent/agent"
)
const baseURL = "http://127.0.0.1:12434/v1"
func selectModel(client *openai.Client) string {
modelsPage, err := client.Models.List(context.Background())
if err != nil {
log.Fatalf("Fehler beim Abrufen der Modelle: %v", err)
}
models := modelsPage.Data
if len(models) == 0 {
log.Fatal("Keine Modelle verfügbar!")
}
fmt.Println("\n📦 Verfügbare Modelle:")
fmt.Println(strings.Repeat("─", 50))
for i, m := range models {
fmt.Printf(" [%d] %s\n", i+1, m.ID)
}
fmt.Println(strings.Repeat("─", 50))
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Printf("Wähle ein Modell (1-%d): ", len(models))
if !scanner.Scan() {
log.Fatal("Eingabe fehlgeschlagen")
}
choice, err := strconv.Atoi(strings.TrimSpace(scanner.Text()))
if err != nil || choice < 1 || choice > len(models) {
fmt.Printf("❌ Ungültige Eingabe.\n")
continue
}
selected := models[choice-1].ID
fmt.Printf("✅ Modell gewählt: %s\n", selected)
return selected
}
}
func main() {
client := openai.NewClient(
oaioption.WithBaseURL(baseURL),
oaioption.WithAPIKey("ollama"),
)
fmt.Println("🤖 LLM Agent")
model := selectModel(&client)
loop := agent.NewAgentLoop(model, ".", "PRD.md")
if err := loop.Run(); err != nil {
log.Fatalf("Agent fehlgeschlagen: %v", err)
}
}