63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"geo/internal/data/impl"
|
|
"geo/internal/data/model"
|
|
"geo/internal/entitys"
|
|
"geo/pkg"
|
|
|
|
volmodle "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
|
|
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
type AiBiz struct {
|
|
platImpl *impl.PlatImpl
|
|
}
|
|
|
|
func NewAiBiz(platImpl *impl.PlatImpl) *AiBiz {
|
|
return &AiBiz{
|
|
platImpl: platImpl,
|
|
}
|
|
}
|
|
|
|
func (a *AiBiz) CreateArticlePrompt(ctx context.Context, data *entitys.BotChat) []*volmodle.ChatCompletionMessage {
|
|
mes := []*volmodle.ChatCompletionMessage{
|
|
{
|
|
Role: volmodle.ChatMessageRoleUser,
|
|
Content: &volmodle.ChatCompletionMessageContent{
|
|
StringValue: volcengine.String(pkg.JsonStringIgonErr(data)),
|
|
},
|
|
},
|
|
}
|
|
var plats []*model.Plat
|
|
cond := builder.NewCond().
|
|
And(builder.Eq{"plat_type": 1}).
|
|
And(builder.Eq{"status": 1})
|
|
_, err := a.platImpl.GetListToStruct(ctx, &cond, nil, &plats, "id asc")
|
|
if err != nil {
|
|
return mes
|
|
}
|
|
var platList = &entitys.PlatList{
|
|
Desc: "平台列表",
|
|
PlatItem: make([]*entitys.PlatItem, 0, len(plats)),
|
|
}
|
|
for _, plat := range plats {
|
|
platList.PlatItem = append(platList.PlatItem, &entitys.PlatItem{
|
|
Platform: plat.Name,
|
|
PlatformIndex: plat.Index,
|
|
})
|
|
}
|
|
if len(platList.PlatItem) > 0 {
|
|
mes = append(mes, &volmodle.ChatCompletionMessage{
|
|
Role: volmodle.ChatMessageRoleSystem,
|
|
Content: &volmodle.ChatCompletionMessageContent{
|
|
StringValue: volcengine.String(pkg.JsonStringIgonErr(platList)),
|
|
},
|
|
})
|
|
}
|
|
|
|
return mes
|
|
}
|