diff --git a/go.mod b/go.mod index 14a587ba1..6e75eba38 100644 --- a/go.mod +++ b/go.mod @@ -70,4 +70,4 @@ go 1.17 replace github.com/nyaruka/gocommon => github.com/Ilhasoft/gocommon v1.16.2-weni -replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v0.3.0-goflow-0.144.3-catalog-9-develop +replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v0.3.0-goflow-0.144.3-catalog-11-develop diff --git a/go.sum b/go.sum index ea837b595..a7f2d08c1 100644 --- a/go.sum +++ b/go.sum @@ -204,8 +204,8 @@ github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLD github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eNAjXGDx2yma7uG2XoyRZTq1uv3M/o7imD0= github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao= github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= -github.com/weni-ai/goflow v0.3.0-goflow-0.144.3-catalog-9-develop h1:/8JAlvYgDYLMChZY45pXc0CeaorMZLJuBQpVWdwTcHg= -github.com/weni-ai/goflow v0.3.0-goflow-0.144.3-catalog-9-develop/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c= +github.com/weni-ai/goflow v0.3.0-goflow-0.144.3-catalog-11-develop h1:HM6RdyuqGsa8Qs0s+i1/GjRBtQZs6eJx9rWS//UXTj8= +github.com/weni-ai/goflow v0.3.0-goflow-0.144.3-catalog-11-develop/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/services/external/weni/service.go b/services/external/weni/service.go index 1ba429766..3cceb3728 100644 --- a/services/external/weni/service.go +++ b/services/external/weni/service.go @@ -77,32 +77,34 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log defer cancel() content := params.ProductSearch - productList, err := GetProductListFromWeniGPT(s.rtConfig, content) + productList, traceWeniGPT, err := GetProductListFromWeniGPT(s.rtConfig, content) + callResult.TraceWeniGPT = traceWeniGPT if err != nil { - return nil, err + return callResult, err } channelUUID := params.ChannelUUID channel, err := models.GetActiveChannelByUUID(ctx, db, channelUUID) if err != nil { - return nil, err + return callResult, err } catalog, err := models.GetActiveCatalogFromChannel(ctx, *db, channel.ID()) if err != nil { - return nil, err + return callResult, err } channelThreshold := channel.ConfigValue("threshold", "1.5") searchThreshold, err := strconv.ParseFloat(channelThreshold, 64) if err != nil { - return nil, err + return callResult, err } productRetailerIDS := []string{} for _, product := range productList { - searchResult, err := GetProductListFromSentenX(product, catalog.FacebookCatalogID(), searchThreshold, s.rtConfig) + searchResult, trace, err := GetProductListFromSentenX(product, catalog.FacebookCatalogID(), searchThreshold, s.rtConfig) + callResult.TraceSentenx = trace if err != nil { - return nil, errors.Wrapf(err, "on iterate to search products on sentenx") + return callResult, errors.Wrapf(err, "on iterate to search products on sentenx") } for _, prod := range searchResult { productRetailerIDS = append(productRetailerIDS, prod["product_retailer_id"]) @@ -114,7 +116,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log return callResult, nil } -func GetProductListFromWeniGPT(rtConfig *runtime.Config, content string) ([]string, error) { +func GetProductListFromWeniGPT(rtConfig *runtime.Config, content string) ([]string, *httpx.Trace, error) { httpClient, httpRetries, _ := goflow.HTTP(rtConfig) weniGPTClient := wenigpt.NewClient(httpClient, httpRetries, rtConfig.WeniGPTBaseURL, rtConfig.WeniGPTAuthToken, rtConfig.WeniGPTCookie) @@ -129,9 +131,9 @@ func GetProductListFromWeniGPT(rtConfig *runtime.Config, content string) ([]stri wenigpt.DefaultStopSequences, ) - response, _, err := weniGPTClient.WeniGPTRequest(dr) + response, trace, err := weniGPTClient.WeniGPTRequest(dr) if err != nil { - return nil, errors.Wrapf(err, "error on wenigpt call fot list products") + return nil, trace, errors.Wrapf(err, "error on wenigpt call fot list products") } productsJson := response.Output.Text[0] @@ -139,23 +141,23 @@ func GetProductListFromWeniGPT(rtConfig *runtime.Config, content string) ([]stri var products map[string][]string err = json.Unmarshal([]byte(productsJson), &products) if err != nil { - return nil, errors.Wrapf(err, "error on unmarshalling product list") + return nil, trace, errors.Wrapf(err, "error on unmarshalling product list") } - return products["products"], nil + return products["products"], trace, nil } -func GetProductListFromSentenX(productSearch string, catalogID string, threshold float64, rtConfig *runtime.Config) ([]map[string]string, error) { +func GetProductListFromSentenX(productSearch string, catalogID string, threshold float64, rtConfig *runtime.Config) ([]map[string]string, *httpx.Trace, error) { client := sentenx.NewClient(http.DefaultClient, nil, rtConfig.SentenXBaseURL) searchParams := sentenx.NewSearchRequest(productSearch, catalogID, threshold) - searchResponse, _, err := client.SearchProducts(searchParams) + searchResponse, trace, err := client.SearchProducts(searchParams) if err != nil { - return nil, err + return nil, trace, err } if len(searchResponse.Products) < 1 { - return nil, errors.New("no products found on sentenx") + return nil, trace, errors.New("no products found on sentenx") } pmap := []map[string]string{} @@ -164,7 +166,7 @@ func GetProductListFromSentenX(productSearch string, catalogID string, threshold pmap = append(pmap, mapElement) } - return pmap, nil + return pmap, trace, nil } func GetProductListFromChatGPT(ctx context.Context, rt *runtime.Runtime, content string) ([]string, error) {