mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 17:09:33 +08:00
change: remove addDeviceContextForWings
This commit is contained in:
@@ -345,8 +345,8 @@ func (w *WingsService) extractScreenshotFromMessage(message *schema.Message) (st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getDeviceInfoFromContext gets device info from context with fallback
|
// getDeviceInfoFromContext gets device info from context with fallback
|
||||||
func (w *WingsService) getDeviceInfoFromContext(ctx context.Context, screenshot string) WingsDeviceInfo {
|
func (w *WingsService) getDeviceInfoFromContext(_ context.Context, screenshot string) WingsDeviceInfo {
|
||||||
// Fallback to default device info
|
// use default device info
|
||||||
return WingsDeviceInfo{
|
return WingsDeviceInfo{
|
||||||
DeviceID: "default-device",
|
DeviceID: "default-device",
|
||||||
NowImage: screenshot,
|
NowImage: screenshot,
|
||||||
|
|||||||
+1
-42
@@ -245,8 +245,6 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
|||||||
return nil, errors.New("LLM service is not initialized")
|
return nil, errors.New("LLM service is not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := dExt.addDeviceContextForWings(context.Background())
|
|
||||||
|
|
||||||
// Step 1: Take screenshot and convert to base64
|
// Step 1: Take screenshot and convert to base64
|
||||||
screenResult, err := dExt.GetScreenResult(
|
screenResult, err := dExt.GetScreenResult(
|
||||||
option.WithScreenShotFileName("ai_assert"),
|
option.WithScreenShotFileName("ai_assert"),
|
||||||
@@ -270,7 +268,7 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
|||||||
Screenshot: screenResult.Base64,
|
Screenshot: screenResult.Base64,
|
||||||
Size: screenResult.Resolution,
|
Size: screenResult.Resolution,
|
||||||
}
|
}
|
||||||
result, err := dExt.LLMService.Assert(ctx, assertOpts)
|
result, err := dExt.LLMService.Assert(context.Background(), assertOpts)
|
||||||
assertResult.ModelCallElapsed = time.Since(modelCallStartTime).Milliseconds()
|
assertResult.ModelCallElapsed = time.Since(modelCallStartTime).Milliseconds()
|
||||||
assertResult.AssertionResult = result
|
assertResult.AssertionResult = result
|
||||||
|
|
||||||
@@ -294,8 +292,6 @@ func (dExt *XTDriver) PlanNextAction(ctx context.Context, prompt string, opts ..
|
|||||||
return nil, errors.New("LLM service is not initialized")
|
return nil, errors.New("LLM service is not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = dExt.addDeviceContextForWings(ctx)
|
|
||||||
|
|
||||||
// Parse action options to get ResetHistory setting
|
// Parse action options to get ResetHistory setting
|
||||||
options := option.NewActionOptions(opts...)
|
options := option.NewActionOptions(opts...)
|
||||||
resetHistory := options.ResetHistory
|
resetHistory := options.ResetHistory
|
||||||
@@ -505,40 +501,3 @@ func (dExt *XTDriver) AIQuery(text string, opts ...option.ActionOption) (*AIExec
|
|||||||
}
|
}
|
||||||
return aiResult, nil
|
return aiResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context key types to avoid collisions
|
|
||||||
type contextKey string
|
|
||||||
|
|
||||||
const (
|
|
||||||
deviceIDKey contextKey = "device_id"
|
|
||||||
platformTypeKey contextKey = "platform_type"
|
|
||||||
)
|
|
||||||
|
|
||||||
// addDeviceContextForWings adds device information to context for Wings service
|
|
||||||
func (dExt *XTDriver) addDeviceContextForWings(ctx context.Context) context.Context {
|
|
||||||
device := dExt.GetDevice()
|
|
||||||
if device == nil {
|
|
||||||
return ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add device ID to context
|
|
||||||
ctx = context.WithValue(ctx, deviceIDKey, device.UUID())
|
|
||||||
|
|
||||||
// Add platform type to context
|
|
||||||
platformType := "android" // default
|
|
||||||
switch device.(type) {
|
|
||||||
case *AndroidDevice:
|
|
||||||
platformType = "android"
|
|
||||||
case *IOSDevice:
|
|
||||||
platformType = "ios"
|
|
||||||
case *HarmonyDevice:
|
|
||||||
platformType = "harmony"
|
|
||||||
case *BrowserDevice:
|
|
||||||
platformType = "browser"
|
|
||||||
default:
|
|
||||||
platformType = "unknown"
|
|
||||||
}
|
|
||||||
ctx = context.WithValue(ctx, platformTypeKey, platformType)
|
|
||||||
|
|
||||||
return ctx
|
|
||||||
}
|
|
||||||
|
|||||||
+12
-6
@@ -29,23 +29,29 @@ func NewXTDriver(driver IDriver, opts ...option.AIServiceOption) (*XTDriver, 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 service configuration if provided
|
||||||
driverExt.LLMService, err = ai.NewLLMServiceWithOptionConfig(services.LLMConfig)
|
driverExt.LLMService, err = ai.NewLLMServiceWithOptionConfig(services.LLMConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msg("init llm service with config failed, Wings service will be used")
|
log.Warn().Err(err).Msg("init llm service with config failed")
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("LLM service initialized with advanced config")
|
log.Info().Msg("LLM service initialized with advanced config")
|
||||||
}
|
}
|
||||||
} else if services.LLMService != "" {
|
} else if services.LLMService != "" {
|
||||||
// Fallback to simple LLM service if no config provided
|
// Use simple LLM service configuration if provided
|
||||||
driverExt.LLMService, err = ai.NewLLMService(services.LLMService)
|
driverExt.LLMService, err = ai.NewLLMService(services.LLMService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msg("init llm service failed, Wings service will be used")
|
log.Warn().Err(err).Msg("init llm service failed")
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("LLM service initialized")
|
log.Info().Msg("LLM service initialized with simple config")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("no LLM service config provided, using Wings service only")
|
// Use Wings service as fallback
|
||||||
|
driverExt.LLMService, err = ai.NewWingsService()
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Err(err).Msg("init Wings service failed")
|
||||||
|
} else {
|
||||||
|
log.Info().Msg("Wings service initialized")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register uixt MCP tools to LLM service if it exists
|
// Register uixt MCP tools to LLM service if it exists
|
||||||
|
|||||||
Reference in New Issue
Block a user