mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-13 03:39:44 +08:00
feat: 兼容base64
This commit is contained in:
@@ -247,12 +247,15 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
||||
return nil, errors.New("LLM service is not initialized")
|
||||
}
|
||||
|
||||
// Parse action options to get ResetHistory setting
|
||||
options := option.NewActionOptions(opts...)
|
||||
screenOptions := []option.ActionOption{option.WithScreenShotFileName("ai_action"), option.WithScreenShotBase64(true)}
|
||||
if options.ScreenShotWithUpload {
|
||||
screenOptions = append(screenOptions, option.WithScreenShotUpload(true))
|
||||
}
|
||||
|
||||
// Step 1: Take screenshot and convert to base64
|
||||
screenResult, err := dExt.GetScreenResult(
|
||||
option.WithScreenShotFileName("ai_assert"),
|
||||
option.WithScreenShotBase64(true),
|
||||
option.WithScreenShotUpload(true),
|
||||
)
|
||||
screenResult, err := dExt.GetScreenResult(screenOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -263,12 +266,17 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
||||
ImagePath: screenResult.ImagePath,
|
||||
Resolution: &screenResult.Resolution,
|
||||
}
|
||||
|
||||
var imageURL string
|
||||
if screenResult.UploadedURL != "" {
|
||||
imageURL = screenResult.UploadedURL
|
||||
} else {
|
||||
imageURL = screenResult.Base64
|
||||
}
|
||||
// Step 2: Call model and measure time
|
||||
modelCallStartTime := time.Now()
|
||||
assertOpts := &ai.AssertOptions{
|
||||
Assertion: assertion,
|
||||
Screenshot: screenResult.UploadedURL,
|
||||
Screenshot: imageURL,
|
||||
Size: screenResult.Resolution,
|
||||
}
|
||||
result, err := dExt.LLMService.Assert(context.Background(), assertOpts)
|
||||
@@ -298,9 +306,8 @@ func (dExt *XTDriver) PlanNextAction(ctx context.Context, prompt string, opts ..
|
||||
// Parse action options to get ResetHistory setting
|
||||
options := option.NewActionOptions(opts...)
|
||||
resetHistory := options.ResetHistory
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
screenOptions := []option.ActionOption{option.WithScreenShotFileName("ai_action"), option.WithScreenShotBase64(true)}
|
||||
if actionOptions.ScreenShotWithUpload {
|
||||
if options.ScreenShotWithUpload {
|
||||
screenOptions = append(screenOptions, option.WithScreenShotUpload(true))
|
||||
}
|
||||
|
||||
@@ -320,7 +327,7 @@ func (dExt *XTDriver) PlanNextAction(ctx context.Context, prompt string, opts ..
|
||||
if screenResult.UploadedURL != "" {
|
||||
imageURL = screenResult.UploadedURL
|
||||
} else {
|
||||
imageURL = screenResult.ImagePath
|
||||
imageURL = screenResult.Base64
|
||||
}
|
||||
planningOpts := &ai.PlanningOptions{
|
||||
UserInstruction: prompt,
|
||||
|
||||
Reference in New Issue
Block a user