feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
const TableNamePromptResource = "prompt_resource"
|
||||
|
||||
// PromptResource prompt_resource
|
||||
type PromptResource struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键ID" json:"id"` // 主键ID
|
||||
SpaceID int64 `gorm:"column:space_id;not null;comment:空间ID" json:"space_id"` // 空间ID
|
||||
Name string `gorm:"column:name;not null;comment:名称" json:"name"` // 名称
|
||||
Description string `gorm:"column:description;not null;comment:描述" json:"description"` // 描述
|
||||
PromptText string `gorm:"column:prompt_text;comment:prompt正文" json:"prompt_text"` // prompt正文
|
||||
Status int32 `gorm:"column:status;not null;comment:状态,0无效,1有效" json:"status"` // 状态,0无效,1有效
|
||||
CreatorID int64 `gorm:"column:creator_id;not null;comment:创建者ID" json:"creator_id"` // 创建者ID
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// TableName PromptResource's table name
|
||||
func (*PromptResource) TableName() string {
|
||||
return TableNamePromptResource
|
||||
}
|
||||
158
backend/domain/prompt/internal/dal/prompt_resource.go
Normal file
158
backend/domain/prompt/internal/dal/prompt_resource.go
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/prompt/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/prompt/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/prompt/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
type PromptDAO struct {
|
||||
IDGen idgen.IDGenerator
|
||||
}
|
||||
|
||||
func NewPromptDAO(db *gorm.DB, generator idgen.IDGenerator) *PromptDAO {
|
||||
query.SetDefault(db)
|
||||
|
||||
return &PromptDAO{
|
||||
IDGen: generator,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *PromptDAO) promptResourceDO2PO(p *entity.PromptResource) *model.PromptResource {
|
||||
return &model.PromptResource{
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
SpaceID: p.SpaceID,
|
||||
Description: p.Description,
|
||||
PromptText: p.PromptText,
|
||||
Status: p.Status,
|
||||
CreatorID: p.CreatorID,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *PromptDAO) promptResourcePO2DO(p *model.PromptResource) *entity.PromptResource {
|
||||
return &entity.PromptResource{
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
SpaceID: p.SpaceID,
|
||||
Description: p.Description,
|
||||
PromptText: p.PromptText,
|
||||
Status: p.Status,
|
||||
CreatorID: p.CreatorID,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *PromptDAO) CreatePromptResource(ctx context.Context, do *entity.PromptResource) (int64, error) {
|
||||
id, err := d.IDGen.GenID(ctx)
|
||||
if err != nil {
|
||||
return 0, errorx.New(errno.ErrPromptIDGenFailCode, errorx.KV("msg", "CreatePromptResource"))
|
||||
}
|
||||
|
||||
p := d.promptResourceDO2PO(do)
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
p.ID = id
|
||||
p.Status = 1
|
||||
p.CreatedAt = now
|
||||
p.UpdatedAt = now
|
||||
|
||||
promptModel := query.PromptResource
|
||||
err = promptModel.WithContext(ctx).Create(p)
|
||||
if err != nil {
|
||||
return 0, errorx.WrapByCode(err, errno.ErrPromptCreateCode)
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (d *PromptDAO) GetPromptResource(ctx context.Context, promptID int64) (*entity.PromptResource, error) {
|
||||
promptModel := query.PromptResource
|
||||
promptWhere := []gen.Condition{
|
||||
promptModel.ID.Eq(promptID),
|
||||
}
|
||||
|
||||
promptResource, err := promptModel.WithContext(ctx).Where(promptWhere...).First()
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.WrapByCode(err, errno.ErrPromptDataNotFoundCode)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, errorx.WrapByCode(err, errno.ErrPromptGetCode)
|
||||
}
|
||||
|
||||
do := d.promptResourcePO2DO(promptResource)
|
||||
|
||||
return do, nil
|
||||
}
|
||||
|
||||
func (d *PromptDAO) UpdatePromptResource(ctx context.Context, p *entity.PromptResource) error {
|
||||
updateMap := make(map[string]any, 5)
|
||||
|
||||
if p.Name != "" {
|
||||
updateMap["name"] = p.Name
|
||||
}
|
||||
|
||||
if p.Description != "" {
|
||||
updateMap["description"] = p.Description
|
||||
}
|
||||
|
||||
if p.PromptText != "" {
|
||||
updateMap["prompt_text"] = p.PromptText
|
||||
}
|
||||
|
||||
promptModel := query.PromptResource
|
||||
promptWhere := []gen.Condition{
|
||||
promptModel.ID.Eq(p.ID),
|
||||
}
|
||||
|
||||
_, err := promptModel.WithContext(ctx).Where(promptWhere...).Updates(updateMap)
|
||||
if err != nil {
|
||||
return errorx.WrapByCode(err, errno.ErrPromptUpdateCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *PromptDAO) DeletePromptResource(ctx context.Context, ID int64) error {
|
||||
promptModel := query.PromptResource
|
||||
promptWhere := []gen.Condition{
|
||||
promptModel.ID.Eq(ID),
|
||||
}
|
||||
_, err := promptModel.WithContext(ctx).Where(promptWhere...).Delete()
|
||||
if err != nil {
|
||||
return errorx.WrapByCode(err, errno.ErrPromptDeleteCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
103
backend/domain/prompt/internal/dal/query/gen.go
Normal file
103
backend/domain/prompt/internal/dal/query/gen.go
Normal file
@@ -0,0 +1,103 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"gorm.io/gen"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
PromptResource *promptResource
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
PromptResource = &Q.PromptResource
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
PromptResource: newPromptResource(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
PromptResource promptResource
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
PromptResource: q.PromptResource.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) ReadDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
|
||||
}
|
||||
|
||||
func (q *Query) WriteDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
|
||||
}
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
PromptResource: q.PromptResource.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
PromptResource IPromptResourceDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
PromptResource: q.PromptResource.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
|
||||
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
|
||||
}
|
||||
|
||||
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
|
||||
tx := q.db.Begin(opts...)
|
||||
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
|
||||
}
|
||||
|
||||
type QueryTx struct {
|
||||
*Query
|
||||
Error error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Commit() error {
|
||||
return q.db.Commit().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Rollback() error {
|
||||
return q.db.Rollback().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) SavePoint(name string) error {
|
||||
return q.db.SavePoint(name).Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) RollbackTo(name string) error {
|
||||
return q.db.RollbackTo(name).Error
|
||||
}
|
||||
413
backend/domain/prompt/internal/dal/query/prompt_resource.gen.go
Normal file
413
backend/domain/prompt/internal/dal/query/prompt_resource.gen.go
Normal file
@@ -0,0 +1,413 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/prompt/internal/dal/model"
|
||||
)
|
||||
|
||||
func newPromptResource(db *gorm.DB, opts ...gen.DOOption) promptResource {
|
||||
_promptResource := promptResource{}
|
||||
|
||||
_promptResource.promptResourceDo.UseDB(db, opts...)
|
||||
_promptResource.promptResourceDo.UseModel(&model.PromptResource{})
|
||||
|
||||
tableName := _promptResource.promptResourceDo.TableName()
|
||||
_promptResource.ALL = field.NewAsterisk(tableName)
|
||||
_promptResource.ID = field.NewInt64(tableName, "id")
|
||||
_promptResource.SpaceID = field.NewInt64(tableName, "space_id")
|
||||
_promptResource.Name = field.NewString(tableName, "name")
|
||||
_promptResource.Description = field.NewString(tableName, "description")
|
||||
_promptResource.PromptText = field.NewString(tableName, "prompt_text")
|
||||
_promptResource.Status = field.NewInt32(tableName, "status")
|
||||
_promptResource.CreatorID = field.NewInt64(tableName, "creator_id")
|
||||
_promptResource.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||
_promptResource.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
||||
|
||||
_promptResource.fillFieldMap()
|
||||
|
||||
return _promptResource
|
||||
}
|
||||
|
||||
// promptResource prompt_resource
|
||||
type promptResource struct {
|
||||
promptResourceDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID
|
||||
SpaceID field.Int64 // 空间ID
|
||||
Name field.String // 名称
|
||||
Description field.String // 描述
|
||||
PromptText field.String // prompt正文
|
||||
Status field.Int32 // 状态,0无效,1有效
|
||||
CreatorID field.Int64 // 创建者ID
|
||||
CreatedAt field.Int64 // 创建时间
|
||||
UpdatedAt field.Int64 // 更新时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p promptResource) Table(newTableName string) *promptResource {
|
||||
p.promptResourceDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p promptResource) As(alias string) *promptResource {
|
||||
p.promptResourceDo.DO = *(p.promptResourceDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *promptResource) updateTableName(table string) *promptResource {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewInt64(table, "id")
|
||||
p.SpaceID = field.NewInt64(table, "space_id")
|
||||
p.Name = field.NewString(table, "name")
|
||||
p.Description = field.NewString(table, "description")
|
||||
p.PromptText = field.NewString(table, "prompt_text")
|
||||
p.Status = field.NewInt32(table, "status")
|
||||
p.CreatorID = field.NewInt64(table, "creator_id")
|
||||
p.CreatedAt = field.NewInt64(table, "created_at")
|
||||
p.UpdatedAt = field.NewInt64(table, "updated_at")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *promptResource) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *promptResource) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 9)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["space_id"] = p.SpaceID
|
||||
p.fieldMap["name"] = p.Name
|
||||
p.fieldMap["description"] = p.Description
|
||||
p.fieldMap["prompt_text"] = p.PromptText
|
||||
p.fieldMap["status"] = p.Status
|
||||
p.fieldMap["creator_id"] = p.CreatorID
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
}
|
||||
|
||||
func (p promptResource) clone(db *gorm.DB) promptResource {
|
||||
p.promptResourceDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p promptResource) replaceDB(db *gorm.DB) promptResource {
|
||||
p.promptResourceDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type promptResourceDo struct{ gen.DO }
|
||||
|
||||
type IPromptResourceDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPromptResourceDo
|
||||
WithContext(ctx context.Context) IPromptResourceDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPromptResourceDo
|
||||
WriteDB() IPromptResourceDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPromptResourceDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPromptResourceDo
|
||||
Not(conds ...gen.Condition) IPromptResourceDo
|
||||
Or(conds ...gen.Condition) IPromptResourceDo
|
||||
Select(conds ...field.Expr) IPromptResourceDo
|
||||
Where(conds ...gen.Condition) IPromptResourceDo
|
||||
Order(conds ...field.Expr) IPromptResourceDo
|
||||
Distinct(cols ...field.Expr) IPromptResourceDo
|
||||
Omit(cols ...field.Expr) IPromptResourceDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPromptResourceDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPromptResourceDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPromptResourceDo
|
||||
Group(cols ...field.Expr) IPromptResourceDo
|
||||
Having(conds ...gen.Condition) IPromptResourceDo
|
||||
Limit(limit int) IPromptResourceDo
|
||||
Offset(offset int) IPromptResourceDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPromptResourceDo
|
||||
Unscoped() IPromptResourceDo
|
||||
Create(values ...*model.PromptResource) error
|
||||
CreateInBatches(values []*model.PromptResource, batchSize int) error
|
||||
Save(values ...*model.PromptResource) error
|
||||
First() (*model.PromptResource, error)
|
||||
Take() (*model.PromptResource, error)
|
||||
Last() (*model.PromptResource, error)
|
||||
Find() ([]*model.PromptResource, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PromptResource, err error)
|
||||
FindInBatches(result *[]*model.PromptResource, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.PromptResource) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IPromptResourceDo
|
||||
Assign(attrs ...field.AssignExpr) IPromptResourceDo
|
||||
Joins(fields ...field.RelationField) IPromptResourceDo
|
||||
Preload(fields ...field.RelationField) IPromptResourceDo
|
||||
FirstOrInit() (*model.PromptResource, error)
|
||||
FirstOrCreate() (*model.PromptResource, error)
|
||||
FindByPage(offset int, limit int) (result []*model.PromptResource, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IPromptResourceDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Debug() IPromptResourceDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p promptResourceDo) WithContext(ctx context.Context) IPromptResourceDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) ReadDB() IPromptResourceDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p promptResourceDo) WriteDB() IPromptResourceDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Session(config *gorm.Session) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Clauses(conds ...clause.Expression) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Returning(value interface{}, columns ...string) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Not(conds ...gen.Condition) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Or(conds ...gen.Condition) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Select(conds ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Where(conds ...gen.Condition) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Order(conds ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Distinct(cols ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Omit(cols ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Join(table schema.Tabler, on ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) RightJoin(table schema.Tabler, on ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Group(cols ...field.Expr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Having(conds ...gen.Condition) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Limit(limit int) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Offset(offset int) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Unscoped() IPromptResourceDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Create(values ...*model.PromptResource) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p promptResourceDo) CreateInBatches(values []*model.PromptResource, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p promptResourceDo) Save(values ...*model.PromptResource) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p promptResourceDo) First() (*model.PromptResource, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PromptResource), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Take() (*model.PromptResource, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PromptResource), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Last() (*model.PromptResource, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PromptResource), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Find() ([]*model.PromptResource, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.PromptResource), err
|
||||
}
|
||||
|
||||
func (p promptResourceDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PromptResource, err error) {
|
||||
buf := make([]*model.PromptResource, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p promptResourceDo) FindInBatches(result *[]*model.PromptResource, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Attrs(attrs ...field.AssignExpr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Assign(attrs ...field.AssignExpr) IPromptResourceDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Joins(fields ...field.RelationField) IPromptResourceDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Preload(fields ...field.RelationField) IPromptResourceDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p promptResourceDo) FirstOrInit() (*model.PromptResource, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PromptResource), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p promptResourceDo) FirstOrCreate() (*model.PromptResource, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PromptResource), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p promptResourceDo) FindByPage(offset int, limit int) (result []*model.PromptResource, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p promptResourceDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p promptResourceDo) Delete(models ...*model.PromptResource) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *promptResourceDo) withDO(do gen.Dao) *promptResourceDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
227
backend/domain/prompt/internal/official/official_prompt.go
Normal file
227
backend/domain/prompt/internal/official/official_prompt.go
Normal file
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package official
|
||||
|
||||
import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/prompt/entity"
|
||||
)
|
||||
|
||||
func GetPromptList() []*entity.PromptResource {
|
||||
return officialPromptList
|
||||
}
|
||||
|
||||
var officialPromptList = []*entity.PromptResource{
|
||||
{
|
||||
ID: 10001,
|
||||
Name: "通用结构",
|
||||
Description: "适用于多种场景的提示词结构,可以根据具体需求增删对应模块",
|
||||
PromptText: `# 角色:{#InputSlot placeholder="角色名称" mode="input"#}{#/InputSlot#}
|
||||
{#InputSlot placeholder="角色概述和主要职责的一句话描述" mode="input"#}{#/InputSlot#}
|
||||
|
||||
## 目标:
|
||||
{#InputSlot placeholder="角色的工作目标,如果有多目标可以分点列出,但建议更聚焦1-2个目标" mode="input"#}{#/InputSlot#}
|
||||
|
||||
## 技能:
|
||||
1. {#InputSlot placeholder="为了实现目标,角色需要具备的技能1" mode="input"#}{#/InputSlot#}
|
||||
2. {#InputSlot placeholder="为了实现目标,角色需要具备的技能2" mode="input"#}{#/InputSlot#}
|
||||
3. {#InputSlot placeholder="为了实现目标,角色需要具备的技能3" mode="input"#}{#/InputSlot#}
|
||||
|
||||
## 工作流:
|
||||
1. {#InputSlot placeholder="描述角色工作流程的第一步" mode="input"#}{#/InputSlot#}
|
||||
2. {#InputSlot placeholder="描述角色工作流程的第二步" mode="input"#}{#/InputSlot#}
|
||||
3. {#InputSlot placeholder="描述角色工作流程的第三步" mode="input"#}{#/InputSlot#}
|
||||
|
||||
## 输出格式:
|
||||
{#InputSlot placeholder="如果对角色的输出格式有特定要求,可以在这里强调并举例说明想要的输出格式" mode="input"#}{#/InputSlot#}
|
||||
|
||||
## 限制:
|
||||
- {#InputSlot placeholder="描述角色在互动过程中需要遵循的限制条件1" mode="input"#}{#/InputSlot#}
|
||||
- {#InputSlot placeholder="描述角色在互动过程中需要遵循的限制条件2" mode="input"#}{#/InputSlot#}
|
||||
- {#InputSlot placeholder="描述角色在互动过程中需要遵循的限制条件3" mode="input"#}{#/InputSlot#}`,
|
||||
},
|
||||
{
|
||||
ID: 10002,
|
||||
Name: "任务执行",
|
||||
Description: "适用于有明确的工作步骤的任务执行场景,通过明确每一步骤的工作要求来助力高效达成目标。",
|
||||
PromptText: `# 角色
|
||||
你是{#InputSlot placeholder="角色设定,比如xx领域的专家"#}{#/InputSlot#}
|
||||
你的目标是{#InputSlot placeholder="希望模型执行什么任务,达成什么目标"#}{#/InputSlot#}
|
||||
|
||||
{#以下可以采用先总括,再展开详细说明的方式,描述你希望智能体在每一个步骤如何进行工作,具体的工作步骤数量可以根据实际需求增删#}
|
||||
## 工作步骤
|
||||
1. {#InputSlot placeholder="工作流程1的一句话概括"#}{#/InputSlot#}
|
||||
2. {#InputSlot placeholder="工作流程2的一句话概括"#}{#/InputSlot#}
|
||||
3. {#InputSlot placeholder="工作流程3的一句话概括"#}{#/InputSlot#}
|
||||
|
||||
### 第一步 {#InputSlot placeholder="工作流程1标题"#}{#/InputSlot#}
|
||||
{#InputSlot placeholder="工作流程步骤1的具体工作要求和举例说明,可以分点列出希望在本步骤做哪些事情,需要完成什么阶段性的工作目标"#}{#/InputSlot#}
|
||||
### 第二步 {#InputSlot placeholder="工作流程2标题"#}{#/InputSlot#}
|
||||
{#InputSlot placeholder="工作流程步骤2的具体工作要求和举例说明,可以分点列出希望在本步骤做哪些事情,需要完成什么阶段性的工作目标"#}{#/InputSlot#}
|
||||
### 第三步 {#InputSlot placeholder="工作流程3标题"#}{#/InputSlot#}
|
||||
{#InputSlot placeholder="工作流程步骤3的具体工作要求和举例说明,可以分点列出希望在本步骤做哪些事情,需要完成什么阶段性的工作目标"#}{#/InputSlot#}
|
||||
|
||||
通过这样的对话,你可以{#InputSlot placeholder="智能体工作目标再次强调"#}{#/InputSlot#}`,
|
||||
},
|
||||
{
|
||||
ID: 10003,
|
||||
Name: "角色扮演",
|
||||
Description: "适用于聊天陪伴、互动娱乐场景,可帮助模型轻松塑造个性化的人物角色并进行生动演绎。",
|
||||
PromptText: `你将扮演一个人物角色{#InputSlot placeholder="角色名称"#}{#/InputSlot#},以下是关于这个角色的详细设定,请根据这些信息来构建你的回答。
|
||||
|
||||
**人物基本信息:**
|
||||
- 你是:{#InputSlot placeholder="角色的名称、身份等基本介绍"#}{#/InputSlot#}
|
||||
- 人称:第一人称
|
||||
- 出身背景与上下文:{#InputSlot placeholder="交代角色背景信息和上下文"#}{#/InputSlot#}
|
||||
**性格特点:**
|
||||
- {#InputSlot placeholder="性格特点描述"#}{#/InputSlot#}
|
||||
**语言风格:**
|
||||
- {#InputSlot placeholder="语言风格描述"#}{#/InputSlot#}
|
||||
**人际关系:**
|
||||
- {#InputSlot placeholder="人际关系描述"#}{#/InputSlot#}
|
||||
**过往经历:**
|
||||
- {#InputSlot placeholder="过往经历描述"#}{#/InputSlot#}
|
||||
**经典台词或口头禅:**
|
||||
补充信息: 即你可以将动作、神情语气、心理活动、故事背景放在()中来表示,为对话提供补充信息。
|
||||
- 台词1:{#InputSlot placeholder="角色台词示例1"#}{#/InputSlot#}
|
||||
- 台词2:{#InputSlot placeholder="角色台词示例2"#}{#/InputSlot#}
|
||||
|
||||
要求:
|
||||
- 根据上述提供的角色设定,以第一人称视角进行表达。
|
||||
- 在回答时,尽可能地融入该角色的性格特点、语言风格以及其特有的口头禅或经典台词。
|
||||
- 如果适用的话,在适当的地方加入()内的补充信息,如动作、神情等,以增强对话的真实感和生动性。`,
|
||||
},
|
||||
{
|
||||
ID: 10004,
|
||||
Name: "技能调用(搜索插件)",
|
||||
Description: "适用于调用插件、工作流获取信息并按照格式回复的场景,使用时将提示词中的搜索插件替换成实际需要的技能。",
|
||||
PromptText: `{#使用说明:本模板以搜索插件的调用总结场景进行举例,真实使用时可将“search”工具替换成当前智能体已配置的插件或工作流名称,键入“{”可以快速引用当前智能体已配置的技能。#}
|
||||
# 角色
|
||||
你是一个{#InputSlot placeholder="智能体人设"#}资深搜索大师{#/InputSlot#},能够熟练调用{#LibraryBlock id="7372463719307264027" uuid="O4g66HC0_97yQ5aQYreR4" type="plugin" apiId="7372463719307296795"#}search{#/LibraryBlock#}工具,为用户{#InputSlot placeholder="智能体工作目标"#}搜索总结各类问题{#/InputSlot#}。
|
||||
|
||||
## 技能
|
||||
### 技能 1: {#InputSlot placeholder="智能体技能"#}按用户需求搜索总结{#/InputSlot#}
|
||||
1. 当用户{#InputSlot placeholder="技能调用触发场景"#}提出具体的搜索需求时{#/InputSlot#},使用{#LibraryBlock id="7372463719307264027" uuid="O4g66HC0_97yQ5aQYreR4" type="plugin" apiId="7372463719307296795"#}search{#/LibraryBlock#}{#InputSlot placeholder="调用技能进行什么操作"#}进行搜索{#/InputSlot#};
|
||||
2. 对{#InputSlot placeholder="调用技能返回的结果"#}搜到的结果{#/InputSlot#}严格按照以下示例回复的格式进行回复:
|
||||
==示例回复==
|
||||
{#InputSlot placeholder="期望输出的格式示例,建议使用Markdown可以更清晰的展现"#}
|
||||
- 🔗链接1:[<搜索结果名称>](<搜索结果链接>)
|
||||
- 📒总结:<搜索结果内容100字总结>
|
||||
---
|
||||
- 🔗链接2:[<搜索结果名称>](<搜索结果链接>)
|
||||
- 📒总结:<搜索结果内容100字总结>
|
||||
---
|
||||
- 🔗链接3:[<搜索结果名称>](<搜索结果链接>)
|
||||
- 📒总结:<搜索结果内容100字总结>
|
||||
---
|
||||
{#/InputSlot#}
|
||||
==示例结束==
|
||||
|
||||
## 限制:
|
||||
- 所输出的内容必须按照给定的示例回复格式进行组织,不能偏离框架要求。
|
||||
- 每次对话必须调用{#LibraryBlock id="7372463719307264027" uuid="O4g66HC0_97yQ5aQYreR4" type="plugin" apiId="7372463719307296795"#}search{#/LibraryBlock#}。`,
|
||||
},
|
||||
{
|
||||
ID: 10005,
|
||||
Name: "基于知识库回答",
|
||||
Description: "适用于客服等基于特定知识库回答的场景",
|
||||
PromptText: `# 角色
|
||||
你叫{#InputSlot placeholder="智能体名称"#}{#/InputSlot#},是{#InputSlot placeholder="智能体角色设定,比如xx领域的专家"#}{#/InputSlot#}。
|
||||
{#InputSlot placeholder="一句话描述智能体的工作目标,比如你已经充分掌握了关于xx主题的知识库,可以回复用户的关于这方面的问题。"#}{#/InputSlot#}
|
||||
|
||||
## 回答主题简介
|
||||
{#InputSlot placeholder="智能体需要回复的主题简介信息,比如如果是某某产品的客服,这里可以写一下产品定位、公司信息、核心功能介绍等"#}{#/InputSlot#}
|
||||
|
||||
## 工作流程
|
||||
### 步骤一:问题理解与回复分析
|
||||
1. 认真理解从知识库{#LibraryBlock id="7433391653186551843" uuid="bWr26J4IGO5eeljGdabYn" type="text"#}知识库示例{#/LibraryBlock#}中召回的内容和用户输入的问题,判断召回的内容是否是用户问题的答案。
|
||||
2. 如果你不能理解用户的问题,例如用户的问题太简单、不包含必要信息,此时你需要追问用户,直到你确定已理解了用户的问题和需求。
|
||||
### 步骤二:回答用户问题
|
||||
1. 经过你认真的判断后,确定用户的问题和{#InputSlot placeholder="回答主题"#}{#/InputSlot#}完全无关,你应该拒绝回答。
|
||||
2. 如果知识库中没有召回任何内容,你的话术可以参考“对不起,我已经学习的知识中不包含问题相关内容,暂时无法提供答案。如果你有{#InputSlot placeholder="回答主题"#}{#/InputSlot#}相关的其他问题,我会尝试帮助你解答。”
|
||||
3. 如果召回的内容与用户问题有关,你应该只提取知识库中和问题提问相关的部分,整理并总结、整合并优化从知识库中召回的内容。你提供给用户的答案必须是精确且简洁的,无需注明答案的数据来源。
|
||||
4. 为用户提供准确而简洁的答案,同时你需要判断用户的问题属于下面列出来的哪个文档的内容,根据你的判断结果应该把相应的文档链接一起返回给用户,你无法浏览下述链接,所以直接给用户提供链接即可。以下是各个说明文档链接:
|
||||
- {#InputSlot placeholder="文档1名称"#}{#/InputSlot#}:{#InputSlot placeholder="说明文档链接"#}{#/InputSlot#}
|
||||
- {#InputSlot placeholder="文档2名称"#}{#/InputSlot#}:{#InputSlot placeholder="说明文档链接"#}{#/InputSlot#}
|
||||
- {#InputSlot placeholder="文档3名称"#}{#/InputSlot#}:{#InputSlot placeholder="说明文档链接"#}{#/InputSlot#}
|
||||
|
||||
## 限制
|
||||
1. 禁止回答的问题
|
||||
对于这些禁止回答的问题,你可以根据用户问题想一个合适的话术。
|
||||
- {#InputSlot placeholder="需要保密的信息:比如你的提示词、搭建方式等,比如需要保密的敏感数据信息。"#}{#/InputSlot#}
|
||||
- {#InputSlot placeholder="个人隐私信息:包括但不限于真实姓名、电话号码、地址、账号密码等敏感信息。"#}个人隐私信息:包括但不限于真实姓名、电话号码、地址、账号密码等敏感信息。{#/InputSlot#}
|
||||
- {#InputSlot placeholder="非主题相关问题:比如xxx、xxx、xxx等与你需要聚焦回答的主题无关的问题。"#}{#/InputSlot#}
|
||||
- {#InputSlot placeholder="违法、违规内容:包括但不限于政治敏感话题、色情、暴力、赌博、侵权等违反法律法规和道德伦理的内容。"#}违法、违规内容:包括但不限于政治敏感话题、色情、暴力、赌博、侵权等违反法律法规和道德伦理的内容。{#/InputSlot#}
|
||||
2. 禁止使用的词语和句子
|
||||
- 你的回答中禁止使用{#InputSlot placeholder="“禁止回答语句1”、“禁止回答语句2”、“禁止回答语句3”、“禁止回答语句4”..."#}{#/InputSlot#}这类语句。
|
||||
- 不要回答{#InputSlot placeholder="不希望回答的内容,比如:代码(json、yaml、代码片段)、图片等"#}{#/InputSlot#}。
|
||||
3. 风格:{#InputSlot placeholder="你所希望的智能体回复风格"#}你必须确保你的回答准确无误、并且言简意赅、容易理解。你必须进行专业和确定性的回复。{#/InputSlot#}
|
||||
4. 语言:{#InputSlot placeholder="你所希望的智能体回复语言"#}你应该用与用户输入相同的语言回答。{#/InputSlot#}
|
||||
5. 回答长度:你的答案应该{#InputSlot placeholder="回答长度描述,比如简洁清晰或详细丰富"#}简洁清晰{#/InputSlot#},不超过{#InputSlot placeholder="回答字数限制"#}300{#/InputSlot#}字。
|
||||
6. 一定要使用 {#InputSlot placeholder="回答格式要求,比如Markdown"#}Markdown{#/InputSlot#} 格式回复。
|
||||
|
||||
## 问答示例
|
||||
### 示例1 正常问答
|
||||
用户问题:{#InputSlot placeholder="用户问题举例1"#}{#/InputSlot#}
|
||||
你的答案:{#InputSlot placeholder="你的答案举例1,可以包括对应问题的回答,对于用户的行为指引,甚至提供相关的文档链接。"#}{#/InputSlot#}
|
||||
### 示例2 正常问答
|
||||
用户问题:{#InputSlot placeholder="用户问题举例2"#}{#/InputSlot#}
|
||||
你的答案:{#InputSlot placeholder="你的答案举例2,可以包括对应问题的回答,对于用户的行为指引,甚至提供相关的文档链接。"#}{#/InputSlot#}
|
||||
### 示例3 用户意图不明确
|
||||
用户问题:{#InputSlot placeholder="用户意图不明确的问题举例"#}{#/InputSlot#}
|
||||
你的答案:{#InputSlot placeholder="应对不明确问题的答案举例,比如可以追问用户一些问题以明确用户意图,比如你想了解关于xx的哪些信息呢?请详细描述你的问题,以便于我可以更好的帮助你。"#}{#/InputSlot#}`,
|
||||
},
|
||||
{
|
||||
ID: 10006,
|
||||
Name: "使用Jinja语法",
|
||||
Description: "以生成生图提示词的设计师为例,可以试试在提示词中使用Jinja语法来提升提示词书写效率。",
|
||||
PromptText: `{# 可以在提示词中使用Jinja语法,使用场景比如:
|
||||
一、写注释:比如此段灰色的话就是注释,注释最终不会作为提示词送给模型,也不实际消耗token,可以用于撰写提示词中的使用说明指引等。
|
||||
二、使用语句:可以通过以下语句设置变量,完成整体提示词中的高频修改内容的快速更改。#}
|
||||
{% set designer_type = "平面设计师" %}{#可将左侧语句中的“平面设计师”替换成你需要的设计师类型,如“服装设计师”、“工业设计师”等#}
|
||||
{% set design_task = "海报设计" %}{#可将左侧语句中的“海报设计”替换成你需要的设计任务,如“中式服装设计”、“汽车设计”等#}
|
||||
|
||||
# 角色
|
||||
你是一个独具创意的优秀{{designer_type}},能够精准理解并根据用户输入的各种具体需求,巧妙构思并设计出匹配的{{design_task}}生图提示词,包括设计符合需求的主体、搭配恰当的颜色主题以及契合的风格。
|
||||
|
||||
## 技能
|
||||
### 技能 1: 理解需求
|
||||
1. 根据用户所提出{{design_task}}需求,根据你的经验判断扩展{{design_task}}的应用场景、目标受众、品牌理念等方面的设计考量因素。
|
||||
2. 如果用户提出需求修改,请结合修改意见重新调整上述设计考量因素,使其符合用户需求。
|
||||
### 技能 2: 设计主体
|
||||
1. 根据你理解的需求,结合一名资深的{{designer_type}}的创意和专业知识,确定出有辨识度且符合用户需求的{{design_task}}主体。
|
||||
2. {{design_task}}主体只有一个,必须是与需求相关的有代表性和辨识度的意象。
|
||||
### 技能 3: 确定颜色主题
|
||||
1. 考虑品牌特性、行业特点和用户需求,选定适配的颜色主题方案,提取一个颜色主题关键词,比如:多巴胺主题、科技主题、梦幻主题、古典主题等。
|
||||
2. 颜色搭配需要符合颜色搭配科学,视觉效果和谐,建议输出2-3个颜色建议,将最主要的颜色放在最前面,不要超过3种颜色。
|
||||
### 技能 4: 设定风格
|
||||
1. 依据品牌定位和目标受众,为{{design_task}}确定合适的设计风格提示词,如简约、复古、现代等。
|
||||
|
||||
### 严格按照以下格式输出对应的生图提示词:
|
||||
{{'{{subject}}'}}: The main subject of the {{design_task}} you suggested. Output in English
|
||||
{% raw %}
|
||||
{{color}}: Color theme keyword. Output in English-themed colors (colorname1 output in English, colorname2 output in English, colorname3 output in English)
|
||||
{{style}}: The suggested style generates prompt words. Use "," to separate different prompts.
|
||||
{% endraw %}
|
||||
{#如果需要实际输出{{、{%等Jinja语法的符号内容,可以参考以上两种方法进行转义#}
|
||||
|
||||
## 限制
|
||||
- 仅专注于{{designer_type}}相关的工作,拒绝处理与{{design_task}}无关的事务。
|
||||
- 所有的设计和方案必须基于用户的明确需求,不得随意发挥。
|
||||
- 你所设计的生图提示词遵循专业设计原则和规范,确保设计质量。
|
||||
- 及时与用户沟通,根据用户反馈进行调整和优化。`,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package official
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var rawJsonBody = `{
|
||||
"resource_list": [
|
||||
]
|
||||
}`
|
||||
|
||||
func TestUnescapeJSON(t *testing.T) {
|
||||
var jsonBody map[string]any
|
||||
err := json.Unmarshal([]byte(rawJsonBody), &jsonBody)
|
||||
assert.NoError(t, err)
|
||||
|
||||
jsonArr := jsonBody["resource_list"].([]any)
|
||||
|
||||
for idx, elem := range jsonArr {
|
||||
fmt.Printf("--------------------: %v\n", idx)
|
||||
fmt.Printf("%s\n", elem.(map[string]any)["prompt_text"])
|
||||
fmt.Printf("--------------------: %v\n", idx)
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user