mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 14:32:31 +08:00
feat: 支持动态改变上传图片
This commit is contained in:
@@ -298,13 +298,14 @@ func (dExt *XTDriver) PlanNextAction(ctx context.Context, prompt string, opts ..
|
|||||||
// 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
|
||||||
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
screenOptions := []option.ActionOption{option.WithScreenShotFileName("ai_action"), option.WithScreenShotBase64(true)}
|
||||||
|
if actionOptions.ScreenShotWithUpload {
|
||||||
|
screenOptions = append(screenOptions, option.WithScreenShotUpload(true))
|
||||||
|
}
|
||||||
|
|
||||||
// Step 1: Take screenshot and convert to base64
|
// Step 1: Take screenshot and convert to base64
|
||||||
screenResult, err := dExt.GetScreenResult(
|
screenResult, err := dExt.GetScreenResult(screenOptions...)
|
||||||
option.WithScreenShotFileName("ai_planning"),
|
|
||||||
option.WithScreenShotBase64(true),
|
|
||||||
option.WithScreenShotUpload(true),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -315,6 +316,12 @@ func (dExt *XTDriver) PlanNextAction(ctx context.Context, prompt string, opts ..
|
|||||||
|
|
||||||
// Step 2: Call model
|
// Step 2: Call model
|
||||||
modelCallStartTime := time.Now()
|
modelCallStartTime := time.Now()
|
||||||
|
var imageURL string
|
||||||
|
if screenResult.UploadedURL != "" {
|
||||||
|
imageURL = screenResult.UploadedURL
|
||||||
|
} else {
|
||||||
|
imageURL = screenResult.ImagePath
|
||||||
|
}
|
||||||
planningOpts := &ai.PlanningOptions{
|
planningOpts := &ai.PlanningOptions{
|
||||||
UserInstruction: prompt,
|
UserInstruction: prompt,
|
||||||
Message: &schema.Message{
|
Message: &schema.Message{
|
||||||
@@ -323,7 +330,7 @@ func (dExt *XTDriver) PlanNextAction(ctx context.Context, prompt string, opts ..
|
|||||||
{
|
{
|
||||||
Type: schema.ChatMessagePartTypeImageURL,
|
Type: schema.ChatMessagePartTypeImageURL,
|
||||||
ImageURL: &schema.ChatMessageImageURL{
|
ImageURL: &schema.ChatMessageImageURL{
|
||||||
URL: screenResult.UploadedURL,
|
URL: imageURL,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user