package service import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gctx" "github.com/safejob/dify-sdk-go" "github.com/safejob/dify-sdk-go/types" "log" ) type Model struct { } func (ml *Model) Execute(b *BidInfo) (bool, string, int) { return ml.Do(b, 2) } func (ml *Model) Do(b *BidInfo, t int) (bool, string, int) { result := ml.post(b.Id, b.Detail, t) if result == nil { return false, "", 0 } for k, v := range result { if v == nil { delete(result, k) } } quoteMode, _ := result["报价模式"].(string) bidCommonwealth := 0 if result["中标联合体"] != nil { if result["中标联合体"] == "是" { bidCommonwealth = 1 } else { bidCommonwealth = -1 } } return true, quoteMode, bidCommonwealth } func (ml *Model) post(_id, detail string, t int) map[string]interface{} { ctx := gctx.New() client, err := dify.NewClient(dify.ClientConfig{ ApiServer: g.Config().MustGet(ctx, "model.apiServer").String(), ApiKey: g.Config().MustGet(ctx, "model.apiKey").String(), User: g.Config().MustGet(ctx, "model.user").String(), }) if err != nil { log.Println(_id, "%v :Error running client: %v", err) return nil } resp, err := client.WorkflowApp().RunBlock(ctx, types.WorkflowRequest{ Inputs: map[string]interface{}{ "detail": detail, "type": t, }, }) if err != nil { log.Println(_id, "%v :Error running client: %v", err) return nil } log.Println(_id, "大模型", resp.Data.Outputs) return resp.Data.Outputs }