refactor: NewXTDriver api, return error if init failed

This commit is contained in:
lilong.129
2025-04-30 14:31:36 +08:00
parent 2ae252b52a
commit 0e9389c796
21 changed files with 146 additions and 146 deletions
-13
View File
@@ -1,13 +0,0 @@
package ai
import (
"testing"
)
func TestOption(t *testing.T) {
options := NewAIService(
WithCVService(CVServiceTypeOpenCV),
WithLLMService(LLMServiceTypeUITARS),
)
t.Log(options)
}
+4 -3
View File
@@ -14,6 +14,7 @@ import (
"github.com/getkin/kin-openapi/openapi3gen"
"github.com/httprunner/httprunner/v5/code"
"github.com/httprunner/httprunner/v5/internal/json"
"github.com/httprunner/httprunner/v5/uixt/option"
"github.com/httprunner/httprunner/v5/uixt/types"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
@@ -57,11 +58,11 @@ func NewAsserter(ctx context.Context) (*Asserter, error) {
return nil, err
}
if strings.Contains(EnvModelUse, string(LLMServiceTypeUITARS)) {
if strings.Contains(EnvModelUse, string(option.LLMServiceTypeUITARS)) {
asserter.systemPrompt += "\n\n" + uiTarsAssertionResponseFormat
} else if strings.Contains(EnvModelUse, string(LLMServiceTypeQwenVL)) {
} else if strings.Contains(EnvModelUse, string(option.LLMServiceTypeQwenVL)) {
asserter.systemPrompt += "\n\n" + defaultAssertionResponseJsonFormat
} else if strings.Contains(EnvModelUse, string(LLMServiceTypeGPT)) {
} else if strings.Contains(EnvModelUse, string(option.LLMServiceTypeGPT)) {
// define output format
type OutputFormat struct {
Thought string `json:"thought"`
+7
View File
@@ -22,6 +22,13 @@ type ICVService interface {
ReadFromPath(imagePath string, opts ...option.ActionOption) (*CVResult, error)
}
func NewCVService(modelType option.CVServiceType) (ICVService, error) {
if modelType == option.CVServiceTypeVEDEM {
return NewVEDEMImageService()
}
return nil, errors.New("invalid cv service type")
}
type CVResult struct {
URL string `json:"url,omitempty"` // image uploaded url
OCRResult OCRResults `json:"ocrResult,omitempty"` // OCR texts
+4 -6
View File
@@ -19,9 +19,8 @@ func TestGetImageFromBuffer(t *testing.T) {
buf := new(bytes.Buffer)
buf.Read(file)
service := NewAIService(
WithCVService(CVServiceTypeVEDEM),
)
service, err := NewVEDEMImageService()
require.Nil(t, err)
cvResult, err := service.ReadFromBuffer(buf)
assert.Nil(t, err)
fmt.Println(fmt.Sprintf("cvResult: %v", cvResult))
@@ -29,9 +28,8 @@ func TestGetImageFromBuffer(t *testing.T) {
func TestGetImageFromPath(t *testing.T) {
imagePath := "/Users/debugtalk/Downloads/s1.png"
service := NewAIService(
WithCVService(CVServiceTypeVEDEM),
)
service, err := NewVEDEMImageService()
require.Nil(t, err)
cvResult, err := service.ReadFromPath(imagePath)
assert.Nil(t, err)
fmt.Println(fmt.Sprintf("cvResult: %v", cvResult))