fix(client_test): unskip vision test with embedded test image
- Remove t.Skip for TestSendMessageWithImage (qwen3-8b-vision works with base64) - Add test_image.jpg (400x300) to test directory alongside test file - Load image at runtime, convert to base64 data URL for API - Collect full response in bytes.Buffer and verify non-empty output
This commit is contained in:
@@ -3,7 +3,9 @@ package client
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -94,11 +96,6 @@ func TestSummarizeChat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSendMessageWithImage(t *testing.T) {
|
||||
// Skip: qwen3-8b-vision on LlamaSwap returns 502 for vision requests.
|
||||
// Run manually when a stable vision backend is available:
|
||||
// go test -run TestSendMessageWithImage ./internal/client/
|
||||
t.Skip("requires stable vision backend - LlamaSwap qwen3-8b-vision returns 502 for image inputs")
|
||||
|
||||
// Initialize Client
|
||||
baseURL, err := url.Parse("https://llm-api.va.reichard.io/v1")
|
||||
if err != nil {
|
||||
@@ -110,21 +107,34 @@ func TestSendMessageWithImage(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Build Data URL from embedded test image (10x10 red PNG)
|
||||
const dataURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAADklEQVR42mNk+P/k/wEAn6gE9QxN+7QAAAAASUVORK5CYII="
|
||||
// Load Test Image and Convert to Base64 Data URL
|
||||
imgData, err := os.ReadFile("test_image.jpg")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read test image: %v", err)
|
||||
}
|
||||
dataURL := "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(imgData)
|
||||
|
||||
// Generate Text Stream
|
||||
var outputBuf bytes.Buffer
|
||||
_, err = client.SendMessage(ctx, []*store.Message{{
|
||||
Role: "user",
|
||||
Content: "What is in this image?",
|
||||
Content: "Describe this image in detail.",
|
||||
Images: []string{dataURL},
|
||||
}}, model, func(mc *MessageChunk) error {
|
||||
if mc.Message != nil {
|
||||
t.Logf("Received: %s", *mc.Message)
|
||||
outputBuf.WriteString(*mc.Message)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to generate text stream: %v", err)
|
||||
}
|
||||
|
||||
// Verify Response
|
||||
output := outputBuf.String()
|
||||
if output == "" {
|
||||
t.Error("No content was written to the buffer")
|
||||
} else {
|
||||
t.Logf("Model response (%d chars): %s", len(output), output)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user