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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -94,11 +96,6 @@ func TestSummarizeChat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSendMessageWithImage(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
|
// Initialize Client
|
||||||
baseURL, err := url.Parse("https://llm-api.va.reichard.io/v1")
|
baseURL, err := url.Parse("https://llm-api.va.reichard.io/v1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -110,21 +107,34 @@ func TestSendMessageWithImage(t *testing.T) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Build Data URL from embedded test image (10x10 red PNG)
|
// Load Test Image and Convert to Base64 Data URL
|
||||||
const dataURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAADklEQVR42mNk+P/k/wEAn6gE9QxN+7QAAAAASUVORK5CYII="
|
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
|
// Generate Text Stream
|
||||||
|
var outputBuf bytes.Buffer
|
||||||
_, err = client.SendMessage(ctx, []*store.Message{{
|
_, err = client.SendMessage(ctx, []*store.Message{{
|
||||||
Role: "user",
|
Role: "user",
|
||||||
Content: "What is in this image?",
|
Content: "Describe this image in detail.",
|
||||||
Images: []string{dataURL},
|
Images: []string{dataURL},
|
||||||
}}, model, func(mc *MessageChunk) error {
|
}}, model, func(mc *MessageChunk) error {
|
||||||
if mc.Message != nil {
|
if mc.Message != nil {
|
||||||
t.Logf("Received: %s", *mc.Message)
|
outputBuf.WriteString(*mc.Message)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to generate text stream: %v", err)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
backend/internal/client/test_image.jpg
Normal file
BIN
backend/internal/client/test_image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user