coai/addition/generation/generate.go
2023-10-27 20:40:01 +08:00

24 lines
745 B
Go

package generation
import (
"chat/globals"
"chat/utils"
"fmt"
)
func CreateGenerationWithCache(model string, prompt string, enableReverse bool, hook func(buffer *utils.Buffer, data string)) (string, error) {
hash, path := GetFolderByHash(model, prompt)
if !utils.Exists(path) {
if err := CreateGeneration(model, prompt, path, enableReverse, hook); err != nil {
globals.Info(fmt.Sprintf("[Project] error during generation %s (model %s): %s", prompt, model, err.Error()))
return "", fmt.Errorf("error during generate project: %s", err.Error())
}
}
if _, _, err := utils.GenerateCompressTask(hash, path, path); err != nil {
return "", fmt.Errorf("error during generate compress task: %s", err.Error())
}
return hash, nil
}