From b199c10ab78d67c9823a1e805296cfed1aaeeb5e Mon Sep 17 00:00:00 2001 From: mudler Date: Mon, 24 Mar 2025 19:46:56 +0100 Subject: [PATCH] do not re-generate avatar if already existing Signed-off-by: mudler --- core/state/pool.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/state/pool.go b/core/state/pool.go index 40d3694..9f9ebc0 100644 --- a/core/state/pool.go +++ b/core/state/pool.go @@ -180,6 +180,13 @@ func createAgentAvatar(APIURL, APIKey, model, imageModel, avatarDir string, agen return fmt.Errorf("default model not set") } + imagePath := filepath.Join(avatarDir, "avatars", fmt.Sprintf("%s.png", agent.Name)) + if _, err := os.Stat(imagePath); err == nil { + // Image already exists + xlog.Debug("Avatar already exists", "path", imagePath) + return nil + } + var results struct { ImagePrompt string `json:"image_prompt"` } @@ -232,7 +239,6 @@ func createAgentAvatar(APIURL, APIKey, model, imageModel, avatarDir string, agen os.MkdirAll(filepath.Join(avatarDir, "avatars"), 0755) // Save the image to the agent directory - imagePath := filepath.Join(avatarDir, "avatars", fmt.Sprintf("%s.png", agent.Name)) imageData, err := base64.StdEncoding.DecodeString(imageJson) if err != nil { return err @@ -244,7 +250,7 @@ func createAgentAvatar(APIURL, APIKey, model, imageModel, avatarDir string, agen func (a *AgentPool) List() []string { a.Lock() defer a.Unlock() - + var agents []string for agent := range a.pool { agents = append(agents, agent)