MCPcopy Create free account
hub / github.com/astercloud/aster / main

Function main

examples/custom_claude_api/test_vision.go:18–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func main() {
19 apiKey := os.Getenv("CLAUDE_API_KEY")
20 baseURL := os.Getenv("CLAUDE_BASE_URL")
21
22 if apiKey == "" {
23 fmt.Println("❌ 请设置 CLAUDE_API_KEY 环境变量")
24 os.Exit(1)
25 }
26 if baseURL == "" {
27 baseURL = "https://api.anthropic.com"
28 }
29
30 fmt.Println("=== Claude API 图片识别测试 ===")
31 fmt.Printf("API 端点: %s\n", baseURL)
32 fmt.Printf("模型: claude-sonnet-4-5-20250929\n\n")
33
34 // 下载测试图片
35 fmt.Println("📥 下载测试图片...")
36 imageData, mediaType, err := downloadTestImage()
37 if err != nil {
38 fmt.Printf("❌ 下载失败: %v\n", err)
39 os.Exit(1)
40 }
41 fmt.Printf("✅ 下载成功 (类型: %s, 大小: %d bytes)\n\n", mediaType, len(imageData))
42
43 // 创建 Provider
44 config := &types.ModelConfig{
45 Provider: "anthropic",
46 Model: "claude-sonnet-4-5-20250929",
47 APIKey: apiKey,
48 BaseURL: baseURL,
49 }
50
51 cp, err := provider.NewCustomClaudeProvider(config)
52 if err != nil {
53 fmt.Printf("❌ 创建 Provider 失败: %v\n", err)
54 os.Exit(1)
55 }
56
57 // 测试 1: 基础图片识别
58 fmt.Println("【测试 1】基础图片识别")
59 fmt.Println("----------------------------------------")
60 testBasicVision(cp, imageData, mediaType)
61
62 // 测试 2: 详细分析
63 fmt.Println("\n【测试 2】详细图片分析")
64 fmt.Println("----------------------------------------")
65 testDetailedVision(cp, imageData, mediaType)
66
67 fmt.Println("\n✅ 图片识别测试完成!")
68}
69
70// downloadTestImage 下载测试图片
71func downloadTestImage() ([]byte, string, error) {

Callers

nothing calls this directly

Calls 5

NewCustomClaudeProviderFunction · 0.92
downloadTestImageFunction · 0.85
testBasicVisionFunction · 0.85
testDetailedVisionFunction · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected