mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-07 04:52:47 +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)
|
||||
// perform CV processing if any CV-related option is enabled
|
||||
if needsCVProcessing(screenshotOptions) {
|
||||
if err = dExt.initCVService(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imageResult, err := dExt.CVService.ReadFromBuffer(compressBufSource, opts...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("ReadFromBuffer from ImageService failed")
|
||||
|
||||
35
uixt/sdk.go
35
uixt/sdk.go
@@ -15,29 +15,18 @@ import (
|
||||
)
|
||||
|
||||
func NewXTDriver(driver IDriver, opts ...option.AIServiceOption) (*XTDriver, error) {
|
||||
services := option.NewAIServiceOptions(opts...)
|
||||
driverExt := &XTDriver{
|
||||
IDriver: driver,
|
||||
client: &MCPClient4XTDriver{
|
||||
Server: NewMCPServer(),
|
||||
},
|
||||
services: services,
|
||||
loadedMCPClients: make(map[string]client.MCPClient),
|
||||
}
|
||||
|
||||
services := option.NewAIServiceOptions(opts...)
|
||||
|
||||
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
|
||||
if services.LLMConfig != nil {
|
||||
// Use advanced LLM configuration if provided
|
||||
@@ -73,10 +62,30 @@ type XTDriver struct {
|
||||
CVService ai.ICVService // OCR/CV
|
||||
LLMService ai.ILLMService // LLM
|
||||
|
||||
services *option.AIServiceOptions // AI services options
|
||||
client *MCPClient4XTDriver // MCP Client for built-in uixt server
|
||||
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
|
||||
type MCPClient4XTDriver struct {
|
||||
client.MCPClient
|
||||
|
||||
Reference in New Issue
Block a user