mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-04 18:45:38 +08:00
### What problem does this PR solve?
Adds a shared safe default implementation for unsupported Go
model-driver capability methods and migrates the confirmed panic-stub
providers to use it.
The Go `ModelDriver` interface requires providers to implement many
capability methods even when the provider does not support them. XunFei
had unsupported capability methods implemented as `panic("implement
me")`, Mistral still had a panic in `ParseFile`, and HuaweiCloud carried
an unreachable `panic("implement me")` after a normal chat return.
### Type of change
- [x] Refactoring
Co-authored-by: Haruko386 <tryeverypossible@163.com>
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package models
|
|
|
|
import "testing"
|
|
|
|
func TestXunFeiUnsupportedMethodsReturnNoSuchMethod(t *testing.T) {
|
|
driver := NewXunFeiModel(map[string]string{"default": "http://unused"}, URLSuffix{}).
|
|
NewInstance(map[string]string{"default": "http://unused"})
|
|
modelName := "spark"
|
|
text := "hello"
|
|
|
|
checks := []struct {
|
|
name string
|
|
call func() error
|
|
}{
|
|
{"Embed", func() error {
|
|
_, err := driver.Embed(&modelName, []string{text}, &APIConfig{}, nil)
|
|
return err
|
|
}},
|
|
{"Rerank", func() error {
|
|
_, err := driver.Rerank(&modelName, text, []string{text}, &APIConfig{}, nil)
|
|
return err
|
|
}},
|
|
{"TranscribeAudio", func() error {
|
|
_, err := driver.TranscribeAudio(&modelName, &text, &APIConfig{}, nil)
|
|
return err
|
|
}},
|
|
{"TranscribeAudioWithSender", func() error {
|
|
return driver.TranscribeAudioWithSender(&modelName, &text, &APIConfig{}, nil, nil)
|
|
}},
|
|
{"AudioSpeech", func() error {
|
|
_, err := driver.AudioSpeech(&modelName, &text, &APIConfig{}, nil)
|
|
return err
|
|
}},
|
|
{"AudioSpeechWithSender", func() error {
|
|
return driver.AudioSpeechWithSender(&modelName, &text, &APIConfig{}, nil, nil)
|
|
}},
|
|
{"OCRFile", func() error {
|
|
_, err := driver.OCRFile(&modelName, nil, &text, &APIConfig{}, nil)
|
|
return err
|
|
}},
|
|
{"ParseFile", func() error {
|
|
_, err := driver.ParseFile(&modelName, nil, &text, &APIConfig{}, nil)
|
|
return err
|
|
}},
|
|
{"Balance", func() error {
|
|
_, err := driver.Balance(&APIConfig{})
|
|
return err
|
|
}},
|
|
{"CheckConnection", func() error {
|
|
return driver.CheckConnection(&APIConfig{})
|
|
}},
|
|
{"ListTasks", func() error {
|
|
_, err := driver.ListTasks(&APIConfig{})
|
|
return err
|
|
}},
|
|
{"ShowTask", func() error {
|
|
_, err := driver.ShowTask("task-id", &APIConfig{})
|
|
return err
|
|
}},
|
|
}
|
|
|
|
for _, check := range checks {
|
|
t.Run(check.name, func(t *testing.T) {
|
|
requireNoSuchMethod(t, check.name, check.call())
|
|
})
|
|
}
|
|
}
|