mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
refactor: init CV service
This commit is contained in:
@@ -114,6 +114,10 @@ func (dExt *XTDriver) createScreenshotWithSession(opts ...option.ActionOption) (
|
|||||||
logger := log.Debug().Str("imagePath", imagePath)
|
logger := log.Debug().Str("imagePath", imagePath)
|
||||||
// perform CV processing if any CV-related option is enabled
|
// perform CV processing if any CV-related option is enabled
|
||||||
if needsCVProcessing(screenshotOptions) {
|
if needsCVProcessing(screenshotOptions) {
|
||||||
|
if err = dExt.initCVService(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
imageResult, err := dExt.CVService.ReadFromBuffer(compressBufSource, opts...)
|
imageResult, err := dExt.CVService.ReadFromBuffer(compressBufSource, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("ReadFromBuffer from ImageService failed")
|
log.Error().Err(err).Msg("ReadFromBuffer from ImageService failed")
|
||||||
|
|||||||
+22
-13
@@ -15,29 +15,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewXTDriver(driver IDriver, opts ...option.AIServiceOption) (*XTDriver, error) {
|
func NewXTDriver(driver IDriver, opts ...option.AIServiceOption) (*XTDriver, error) {
|
||||||
|
services := option.NewAIServiceOptions(opts...)
|
||||||
driverExt := &XTDriver{
|
driverExt := &XTDriver{
|
||||||
IDriver: driver,
|
IDriver: driver,
|
||||||
client: &MCPClient4XTDriver{
|
client: &MCPClient4XTDriver{
|
||||||
Server: NewMCPServer(),
|
Server: NewMCPServer(),
|
||||||
},
|
},
|
||||||
|
services: services,
|
||||||
loadedMCPClients: make(map[string]client.MCPClient),
|
loadedMCPClients: make(map[string]client.MCPClient),
|
||||||
}
|
}
|
||||||
|
|
||||||
services := option.NewAIServiceOptions(opts...)
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// default to vedem CV service
|
|
||||||
if services.CVService == "" {
|
|
||||||
log.Warn().Msg("no CV service config provided, not using CV service")
|
|
||||||
} else {
|
|
||||||
driverExt.CVService, err = ai.NewCVService(services.CVService)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("init vedem image service failed")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle LLM service initialization
|
// Handle LLM service initialization
|
||||||
if services.LLMConfig != nil {
|
if services.LLMConfig != nil {
|
||||||
// Use advanced LLM configuration if provided
|
// Use advanced LLM configuration if provided
|
||||||
@@ -73,10 +62,30 @@ type XTDriver struct {
|
|||||||
CVService ai.ICVService // OCR/CV
|
CVService ai.ICVService // OCR/CV
|
||||||
LLMService ai.ILLMService // LLM
|
LLMService ai.ILLMService // LLM
|
||||||
|
|
||||||
|
services *option.AIServiceOptions // AI services options
|
||||||
client *MCPClient4XTDriver // MCP Client for built-in uixt server
|
client *MCPClient4XTDriver // MCP Client for built-in uixt server
|
||||||
loadedMCPClients map[string]client.MCPClient // External MCP clients
|
loadedMCPClients map[string]client.MCPClient // External MCP clients
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dExt *XTDriver) initCVService() error {
|
||||||
|
if dExt.CVService != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cvServiceType := dExt.services.CVService
|
||||||
|
if cvServiceType == "" {
|
||||||
|
log.Warn().Msg("no CV service config provided, use default vedem")
|
||||||
|
cvServiceType = option.CVServiceTypeVEDEM
|
||||||
|
}
|
||||||
|
cvService, err := ai.NewCVService(cvServiceType)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Str("type", string(cvServiceType)).
|
||||||
|
Msg("init cv service failed")
|
||||||
|
return errors.Wrap(err, "init cv service failed")
|
||||||
|
}
|
||||||
|
dExt.CVService = cvService
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// MCPClient4XTDriver is a mock MCP client that only implements the methods used by the host
|
// MCPClient4XTDriver is a mock MCP client that only implements the methods used by the host
|
||||||
type MCPClient4XTDriver struct {
|
type MCPClient4XTDriver struct {
|
||||||
client.MCPClient
|
client.MCPClient
|
||||||
|
|||||||
Reference in New Issue
Block a user