Standardize action results
This commit is contained in:
@@ -24,18 +24,18 @@ type GenImageAction struct {
|
||||
imageModel string
|
||||
}
|
||||
|
||||
func (a *GenImageAction) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
func (a *GenImageAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
result := struct {
|
||||
Prompt string `json:"prompt"`
|
||||
Size string `json:"size"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return action.ActionResult{}, err
|
||||
}
|
||||
|
||||
if result.Prompt == "" {
|
||||
return "", fmt.Errorf("prompt is required")
|
||||
return action.ActionResult{}, fmt.Errorf("prompt is required")
|
||||
}
|
||||
|
||||
req := openai.ImageRequest{
|
||||
@@ -56,14 +56,17 @@ func (a *GenImageAction) Run(ctx context.Context, params action.ActionParams) (s
|
||||
|
||||
resp, err := a.client.CreateImage(ctx, req)
|
||||
if err != nil {
|
||||
return "Failed to generate image " + err.Error(), err
|
||||
return action.ActionResult{Result: "Failed to generate image " + err.Error()}, err
|
||||
}
|
||||
|
||||
if len(resp.Data) == 0 {
|
||||
return "Failed to generate image", nil
|
||||
return action.ActionResult{Result: "Failed to generate image"}, nil
|
||||
}
|
||||
|
||||
return fmt.Sprintf("The image was generated and available at: %s", resp.Data[0].URL), nil
|
||||
return action.ActionResult{
|
||||
Result: fmt.Sprintf("The image was generated and available at: %s", resp.Data[0].URL), Metadata: map[string]interface{}{
|
||||
"url": resp.Data[0].URL,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (a *GenImageAction) Definition() action.ActionDefinition {
|
||||
|
||||
Reference in New Issue
Block a user