feat(multimodal): 视觉分层路由(多模态检测→主/视觉/OCR 工具)+ 语音 STT→TTS 降级链(异步)
This commit is contained in:
1 parent
02aae2bbb4
commit
0a936a3202
19 files changed
+2121
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package vision
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
||||
)
|
||||
|
||||
func TestOpenAICompatibleAdapter_Describe(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/chat/completions" {
|
||||
t.Errorf("path = %s, want /chat/completions", r.URL.Path)
|
||||
}
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("decode body: %v", err)
|
||||
}
|
||||
msgs, _ := body["messages"].([]any)
|
||||
if len(msgs) != 1 {
|
||||
t.Fatalf("messages = %d, want 1", len(msgs))
|
||||
}
|
||||
content, _ := msgs[0].(map[string]any)["content"].([]any)
|
||||
if len(content) != 2 {
|
||||
t.Fatalf("content parts = %d, want 2", len(content))
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = io.WriteString(w, `{"choices":[{"message":{"content":"a red car"}}]}`)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
ad := NewOpenAICompatible(config.LLMConfig{BaseURL: srv.URL, Model: "vision-"})
|
||||
text, err := ad.Describe(context.Background(), ImageRef{Source: SourceBase64, Data: "aGVsbG8="}, "")
|
||||
if err != nil {
|
||||
t.Fatalf("Describe error: %v", err)
|
||||
}
|
||||
if text != "a red car" {
|
||||
t.Errorf("text = %q, want a red car", text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenAICompatibleAdapter_NotConfigured(t *testing.T) {
|
||||
t.Parallel()
|
||||
ad := NewOpenAICompatible(config.LLMConfig{})
|
||||
if _, err := ad.Describe(context.Background(), ImageRef{Source: SourceBase64, Data: "aGVsbG8="}, ""); err == nil {
|
||||
t.Fatal("want error for empty base url, got nil")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user