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

Function testBasicVision

examples/custom_claude_api/test_vision.go:103–152  ·  view source on GitHub ↗

testBasicVision 测试基础图片识别

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

Source from the content-addressed store, hash-verified

101
102// testBasicVision 测试基础图片识别
103func 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 测试详细图片分析
155func testDetailedVision(cp *provider.CustomClaudeProvider, imageData []byte, mediaType string) {

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