mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-06 07:34:04 +08:00
feat(go-models): migrate batch 3 model drivers to unified handlers (#17698)
## Summary Relate to #17284 Migrate 10 OpenAI-compatible drivers (`minimax`, `mistral`, `modelscope`, `moonshot`, `n1n`, `novita`, `ollama`, `openai`, `openai_api_compatible`, `openrouter`) to use the unified response handlers (`HandleNonStreamingResponse` / `HandleStreamingResponse`), following the same pattern established by `deepseek` in #17634. - Cut ~150 lines per driver (1692 lines removed, 172 added across 10 files). - `openai_api_compatible` gains `ChatWithMessages` + `ChatStreamlyWithSender` required by the unified handler infrastructure. - `openai` driver preserves `reasoning_content` extraction for o-series models. - All drivers: pure deduplication of HTTP plumbing. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,6 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func newModelScopeForTest(baseURL string) *ModelScopeModel {
|
||||
@@ -36,15 +35,6 @@ func newModelScopeForTest(baseURL string) *ModelScopeModel {
|
||||
)
|
||||
}
|
||||
|
||||
func withModelScopeIdleTimeout(t *testing.T, d time.Duration) {
|
||||
t.Helper()
|
||||
original := modelscopeStreamIdleTimeout
|
||||
modelscopeStreamIdleTimeout = d
|
||||
t.Cleanup(func() {
|
||||
modelscopeStreamIdleTimeout = original
|
||||
})
|
||||
}
|
||||
|
||||
func TestModelScopeName(t *testing.T) {
|
||||
m := newModelScopeForTest("http://unused")
|
||||
if got := m.Name(); got != "ModelScope" {
|
||||
@@ -271,37 +261,6 @@ func TestModelScopeStreamRejectsFalseStreamConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelScopeStreamCancelsOnIdle(t *testing.T) {
|
||||
withSSRFBypass(t)
|
||||
ctx := t.Context()
|
||||
withModelScopeIdleTimeout(t, 200*time.Millisecond)
|
||||
|
||||
hold := make(chan struct{})
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if f, ok := w.(http.Flusher); ok {
|
||||
_, _ = io.WriteString(w, `data: {"choices":[{"delta":{"content":"hi"}}]}`+"\n")
|
||||
f.Flush()
|
||||
}
|
||||
select {
|
||||
case <-hold:
|
||||
case <-r.Context().Done():
|
||||
}
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
t.Cleanup(func() { close(hold) })
|
||||
|
||||
m := newModelScopeForTest(srv.URL)
|
||||
err := m.ChatStreamlyWithSender(ctx, "Qwen/Qwen2.5-7B-Instruct",
|
||||
[]Message{{Role: "user", Content: "x"}},
|
||||
&APIConfig{}, nil, nil,
|
||||
func(*string, *string) error { return nil })
|
||||
if err == nil || !strings.Contains(err.Error(), "stream idle") {
|
||||
t.Errorf("expected stream-idle error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelScopeListModelsAndCheckConnection(t *testing.T) {
|
||||
withSSRFBypass(t)
|
||||
ctx := t.Context()
|
||||
|
||||
Reference in New Issue
Block a user