| iomodo | f1ddefe | 2025-07-28 09:02:05 +0400 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "log" |
| 7 | |
| 8 | "github.com/iomodo/staff/llm" |
| 9 | _ "github.com/iomodo/staff/llm/providers" // Auto-register providers |
| 10 | ) |
| 11 | |
| 12 | func main() { |
| 13 | // Create fake LLM config |
| 14 | config := llm.Config{ |
| 15 | Provider: llm.ProviderFake, |
| 16 | APIKey: "fake-key", |
| 17 | BaseURL: "fake://test", |
| 18 | } |
| 19 | |
| 20 | // Create provider |
| 21 | provider, err := llm.CreateProvider(config) |
| 22 | if err != nil { |
| 23 | log.Fatalf("Failed to create provider: %v", err) |
| 24 | } |
| 25 | defer provider.Close() |
| 26 | |
| 27 | // Test chat completion |
| 28 | req := llm.ChatCompletionRequest{ |
| 29 | Model: "fake-gpt-4", |
| 30 | Messages: []llm.Message{ |
| 31 | { |
| 32 | Role: llm.RoleSystem, |
| 33 | Content: "You are a helpful AI assistant.", |
| 34 | }, |
| 35 | { |
| 36 | Role: llm.RoleUser, |
| 37 | Content: "Create a solution for implementing user authentication", |
| 38 | }, |
| 39 | }, |
| 40 | MaxTokens: &[]int{4000}[0], |
| 41 | Temperature: &[]float64{0.3}[0], |
| 42 | } |
| 43 | |
| 44 | fmt.Println("Testing Fake LLM Provider...") |
| 45 | fmt.Println("==========================") |
| 46 | |
| 47 | resp, err := provider.ChatCompletion(context.Background(), req) |
| 48 | if err != nil { |
| 49 | log.Fatalf("Chat completion failed: %v", err) |
| 50 | } |
| 51 | |
| 52 | fmt.Printf("Response ID: %s\n", resp.ID) |
| 53 | fmt.Printf("Model: %s\n", resp.Model) |
| 54 | fmt.Printf("Provider: %s\n", resp.Provider) |
| 55 | fmt.Printf("Usage: %+v\n", resp.Usage) |
| 56 | fmt.Println("\nGenerated Solution:") |
| 57 | fmt.Println("===================") |
| 58 | fmt.Println(resp.Choices[0].Message.Content) |
| 59 | fmt.Println("\n✅ Fake LLM Provider is working correctly!") |
| 60 | } |