testBasicVision 测试基础图片识别
(cp *provider.CustomClaudeProvider, imageData []byte, mediaType string)
| 101 | |
| 102 | // testBasicVision 测试基础图片识别 |
| 103 | func testBasicVision(cp *provider.CustomClaudeProvider, imageData []byte, mediaType string) { |
| 104 | ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) |
| 105 | defer cancel() |
| 106 | |
| 107 | // Base64 编码 |
| 108 | base64Data := base64.StdEncoding.EncodeToString(imageData) |
| 109 | |
| 110 | // 构造消息 |
| 111 | messages := []types.Message{ |
| 112 | { |
| 113 | Role: types.MessageRoleUser, |
| 114 | ContentBlocks: []types.ContentBlock{ |
| 115 | &types.ImageContent{ |
| 116 | Type: "base64", |
| 117 | Source: base64Data, |
| 118 | MimeType: mediaType, |
| 119 | }, |
| 120 | &types.TextBlock{ |
| 121 | Text: "这张图片里有什么?请用中文简短描述(不超过30字)。", |
| 122 | }, |
| 123 | }, |
| 124 | }, |
| 125 | } |
| 126 | |
| 127 | fmt.Println("💬 问题: 这张图片里有什么?") |
| 128 | fmt.Print("🤖 回复: ") |
| 129 | |
| 130 | // 调用 Provider |
| 131 | opts := &provider.StreamOptions{ |
| 132 | MaxTokens: 500, |
| 133 | } |
| 134 | response, err := cp.Complete(ctx, messages, opts) |
| 135 | if err != nil { |
| 136 | fmt.Printf("\n❌ 调用失败: %v\n", err) |
| 137 | return |
| 138 | } |
| 139 | |
| 140 | // 输出结果 |
| 141 | var content string |
| 142 | for _, block := range response.Message.ContentBlocks { |
| 143 | if textBlock, ok := block.(*types.TextBlock); ok { |
| 144 | content += textBlock.Text |
| 145 | } |
| 146 | } |
| 147 | fmt.Printf("%s\n", content) |
| 148 | if response.Usage != nil { |
| 149 | fmt.Printf("📊 Token: 输入=%d, 输出=%d\n", |
| 150 | response.Usage.InputTokens, response.Usage.OutputTokens) |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // testDetailedVision 测试详细图片分析 |
| 155 | func testDetailedVision(cp *provider.CustomClaudeProvider, imageData []byte, mediaType string) { |
no test coverage detected