feat: set LLMService/CVService for case runner

This commit is contained in:
lilong.129
2025-04-28 19:45:07 +08:00
parent 7fa4155390
commit 4d7dc466f3
5 changed files with 31 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import (
"reflect"
"github.com/httprunner/httprunner/v5/internal/builtin"
"github.com/httprunner/httprunner/v5/uixt/ai"
"github.com/httprunner/httprunner/v5/uixt/option"
)
@@ -42,6 +43,8 @@ type TConfig struct {
Path string `json:"path,omitempty" yaml:"path,omitempty"` // testcase file path
PluginSetting *PluginConfig `json:"plugin,omitempty" yaml:"plugin,omitempty"` // plugin config
IgnorePopup bool `json:"ignore_popup,omitempty" yaml:"ignore_popup,omitempty"`
LLMService ai.LLMServiceType `json:"llm_service,omitempty" yaml:"llm_service,omitempty"`
CVService ai.CVServiceType `json:"cv_service,omitempty" yaml:"cv_service,omitempty"`
}
func (c *TConfig) Get() *TConfig {
@@ -108,6 +111,18 @@ func (c *TConfig) SetWeight(weight int) *TConfig {
return c
}
// SetLLMService sets LLM service for current testcase.
func (c *TConfig) SetLLMService(llmService ai.LLMServiceType) *TConfig {
c.LLMService = llmService
return c
}
// SetCVService sets CV service for current testcase.
func (c *TConfig) SetCVService(cvService ai.CVServiceType) *TConfig {
c.CVService = cvService
return c
}
func (c *TConfig) SetWebSocket(times, interval, timeout, size int64) *TConfig {
c.WebSocketSetting = &WebSocketConfig{
ReconnectionTimes: times,

View File

@@ -1 +1 @@
v5.0.0-beta-2504272237
v5.0.0-beta-2504281945

View File

@@ -418,6 +418,17 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
}
r.parametersIterator = parametersIterator
// ai options
aiOpts := []ai.AIServiceOption{}
if parsedConfig.LLMService != "" {
aiOpts = append(aiOpts, ai.WithLLMService(parsedConfig.LLMService))
}
if parsedConfig.CVService == "" {
// default to vedem
parsedConfig.CVService = ai.CVServiceTypeVEDEM
}
aiOpts = append(aiOpts, ai.WithCVService(parsedConfig.CVService))
// parse android devices config
for _, androidDeviceOptions := range parsedConfig.Android {
err := r.parseDeviceConfig(androidDeviceOptions, parsedConfig.Variables)
@@ -435,7 +446,7 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
return nil, errors.Wrap(err, "init android driver failed")
}
driverExt := uixt.NewXTDriver(driver, ai.WithCVService(ai.CVServiceTypeVEDEM))
driverExt := uixt.NewXTDriver(driver, aiOpts...)
r.uixtDrivers[androidDeviceOptions.SerialNumber] = driverExt
}
// parse iOS devices config
@@ -455,7 +466,7 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
return nil, errors.Wrap(err, "init ios driver failed")
}
driverExt := uixt.NewXTDriver(driver, ai.WithCVService(ai.CVServiceTypeVEDEM))
driverExt := uixt.NewXTDriver(driver, aiOpts...)
r.uixtDrivers[iosDeviceOptions.UDID] = driverExt
}
// parse harmony devices config
@@ -475,7 +486,7 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
return nil, errors.Wrap(err, "init harmony driver failed")
}
driverExt := uixt.NewXTDriver(driver, ai.WithCVService(ai.CVServiceTypeVEDEM))
driverExt := uixt.NewXTDriver(driver, aiOpts...)
r.uixtDrivers[harmonyDeviceOptions.ConnectKey] = driverExt
}

View File

@@ -62,6 +62,7 @@ func WithLLMService(service LLMServiceType) AIServiceOption {
return func(opts *AIServices) {
switch service {
case LLMServiceTypeGPT4o:
// TODO: implement gpt-4o planner and asserter
planner, err := NewPlanner(context.Background())
if err != nil {
log.Error().Err(err).Msg("init gpt-4o planner failed")

View File

@@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/require"
)
// 创建AI服务的辅助函数
func createAIService(t *testing.T) *AIServices {
aiService := NewAIService(WithLLMService(LLMServiceTypeUITARS))
require.NotNil(t, aiService)