Skip to content

Commit

Permalink
Merge pull request #44 from pilksoc/fix/faster_return_for_ai_calls
Browse files Browse the repository at this point in the history
fix: genereate image in new thread
  • Loading branch information
djpiper28 authored Mar 15, 2024
2 parents 2e8f8a7 + ef524fe commit 769b683
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions kube_cache/server/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,23 @@ func (s *Server) craft(c *gin.Context, id1, id2 string) (model.KubeRecipe, error
return model.KubeRecipe{}, errors.New("Cannot generate kube recipe")
}

image, err := s.Ai.GenerateDalleForKube(newKubeId)
if err != nil {
log.Printf("Error generating Dalle for kube: %s", err)
return model.KubeRecipe{}, errors.New("Error generating Dalle for kube")
}

err = s.Database.SetKubeRecipe(kube1, kube2, newKubeId, image)
if err != nil {
log.Printf("Cannot save kube recipe: %s", err)
return model.KubeRecipe{}, errors.New("Cannot save kube recipe")
}

recipe, err = s.Database.GetKubeRecipe(id1, id2)
if err != nil {
log.Printf("Cannot get kube recipe: %s", err)
return model.KubeRecipe{}, errors.New("Cannot get kube recipe")
}
log.Printf("Generated new kube: %s, generating image in new thread", newKubeId)
go func() {
image, err := s.Ai.GenerateDalleForKube(newKubeId)
if err != nil {
log.Printf("Error generating Dalle for kube: %s", err)
}

err = s.Database.SetKubeRecipe(kube1, kube2, newKubeId, image)
if err != nil {
log.Printf("Cannot save kube recipe: %s", err)
}

recipe, err = s.Database.GetKubeRecipe(id1, id2)
if err != nil {
log.Printf("Cannot get kube recipe: %s", err)
}
}()

} else {
s.Metrics.IncrementCacheHits()
Expand Down

0 comments on commit 769b683

Please sign in to comment.