init code
This commit is contained in:
67
main.go
Normal file
67
main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user