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

Function testDetailedVision

examples/custom_claude_api/test_vision.go:155–204  ·  view source on GitHub ↗

testDetailedVision 测试详细图片分析

(cp *provider.CustomClaudeProvider, imageData []byte, mediaType string)

Source from the content-addressed store, hash-verified

153
154// testDetailedVision 测试详细图片分析
155func testDetailedVision(cp *provider.CustomClaudeProvider, imageData []byte, mediaType string) {
156 ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
157 defer cancel()
158
159 // Base64 编码
160 base64Data := base64.StdEncoding.EncodeToString(imageData)
161
162 // 构造消息
163 messages := []types.Message{
164 {
165 Role: types.MessageRoleUser,
166 ContentBlocks: []types.ContentBlock{
167 &types.ImageContent{
168 Type: "base64",
169 Source: base64Data,
170 MimeType: mediaType,
171 },
172 &types.TextBlock{
173 Text: "请详细描述这张图片的:1) 主要内容 2) 颜色 3) 风格。用中文回答,不超过100字。",
174 },
175 },
176 },
177 }
178
179 fmt.Println("💬 问题: 请详细描述图片的内容、颜色和风格")
180 fmt.Print("🤖 回复: ")
181
182 // 调用
183 opts := &provider.StreamOptions{
184 MaxTokens: 1000,
185 }
186 response, err := cp.Complete(ctx, messages, opts)
187 if err != nil {
188 fmt.Printf("\n❌ 调用失败: %v\n", err)
189 return
190 }
191
192 // 输出结果
193 var content string
194 for _, block := range response.Message.ContentBlocks {
195 if textBlock, ok := block.(*types.TextBlock); ok {
196 content += textBlock.Text
197 }
198 }
199 fmt.Printf("%s\n", content)
200 if response.Usage != nil {
201 fmt.Printf("📊 Token: 输入=%d, 输出=%d\n",
202 response.Usage.InputTokens, response.Usage.OutputTokens)
203 }
204}

Callers 1

mainFunction · 0.85

Calls 4

cancelFunction · 0.85
PrintfMethod · 0.80
CompleteMethod · 0.65
WithTimeoutMethod · 0.45

Tested by

no test coverage detected