afce45396e
move js to root
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package openai
|
|
|
|
import (
|
|
"apigo.cc/ai/ai/llm"
|
|
"context"
|
|
"github.com/sashabaranov/go-openai"
|
|
"strings"
|
|
)
|
|
|
|
// func (lm *LLM) FastMakeImage(prompt, size, refImage string) ([]string, error) {
|
|
// return lm.MakeImage(ModelDallE3Std, prompt, size, refImage)
|
|
// }
|
|
//
|
|
// func (lm *LLM) BestMakeImage(prompt, size, refImage string) ([]string, error) {
|
|
// return lm.MakeImage(ModelDallE3HD, prompt, size, refImage)
|
|
// }
|
|
//
|
|
// func (lm *LLM) MakeImage(model, prompt, size, refImage string) ([]string, error) {
|
|
func (lm *LLM) FastMakeImage(prompt string, config llm.GCConfig) ([]string, error) {
|
|
config.Model = ModelDallE3Std
|
|
return lm.MakeImage(prompt, config)
|
|
}
|
|
|
|
func (lm *LLM) BestMakeImage(prompt string, config llm.GCConfig) ([]string, error) {
|
|
config.Model = ModelDallE3HD
|
|
return lm.MakeImage(prompt, config)
|
|
}
|
|
|
|
func (lm *LLM) MakeImage(prompt string, config llm.GCConfig) ([]string, error) {
|
|
openaiConf := openai.DefaultConfig(lm.config.ApiKey)
|
|
if lm.config.Endpoint != "" {
|
|
openaiConf.BaseURL = lm.config.Endpoint
|
|
}
|
|
config.SetDefault(&lm.config.GCConfig)
|
|
c := openai.NewClientWithConfig(openaiConf)
|
|
style := openai.CreateImageStyleVivid
|
|
if (!strings.Contains(prompt, "vivid") || !strings.Contains(prompt, "生动的")) && (strings.Contains(prompt, "natural") || strings.Contains(prompt, "自然的")) {
|
|
style = openai.CreateImageStyleNatural
|
|
}
|
|
quality := openai.CreateImageQualityStandard
|
|
model := config.GetModel()
|
|
if strings.HasSuffix(model, "-hd") {
|
|
quality = openai.CreateImageQualityHD
|
|
model = model[0 : len(model)-3]
|
|
}
|
|
r, err := c.CreateImage(context.Background(), openai.ImageRequest{
|
|
Prompt: prompt,
|
|
Model: model,
|
|
Quality: quality,
|
|
Size: config.GetSize(),
|
|
Style: style,
|
|
ResponseFormat: openai.CreateImageResponseFormatURL,
|
|
})
|
|
if err == nil {
|
|
results := make([]string, 0)
|
|
for _, item := range r.Data {
|
|
results = append(results, item.URL)
|
|
}
|
|
return results, nil
|
|
} else {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (lm *LLM) FastMakeVideo(prompt string, config llm.GCConfig) ([]string, []string, error) {
|
|
return lm.MakeVideo(prompt, config)
|
|
}
|
|
|
|
func (lm *LLM) BestMakeVideo(prompt string, config llm.GCConfig) ([]string, []string, error) {
|
|
return lm.MakeVideo(prompt, config)
|
|
}
|
|
|
|
func (lm *LLM) MakeVideo(prompt string, config llm.GCConfig) ([]string, []string, error) {
|
|
return nil, nil, nil
|
|
}
|