mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
refactor: NewXTDriver api, return error if init failed
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOption(t *testing.T) {
|
||||
options := NewAIService(
|
||||
WithCVService(CVServiceTypeOpenCV),
|
||||
WithLLMService(LLMServiceTypeUITARS),
|
||||
)
|
||||
t.Log(options)
|
||||
}
|
||||
+4
-3
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user