Skip to content

Commit

Permalink
Switch weniGPT to chatGPT
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Oct 31, 2023
1 parent 9c62edd commit 8a75d5c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions services/external/weni/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log
defer cancel()

content := params.ProductSearch
productList, traceWeniGPT, err := GetProductListFromWeniGPT(s.rtConfig, content)
productList, traceWeniGPT, err := GetProductListFromChatGPT(ctx, s.rtConfig, content)
callResult.TraceWeniGPT = traceWeniGPT
if err != nil {
return callResult, err
Expand Down Expand Up @@ -169,9 +169,9 @@ func GetProductListFromSentenX(productSearch string, catalogID string, threshold
return pmap, trace, nil
}

func GetProductListFromChatGPT(ctx context.Context, rt *runtime.Runtime, content string) ([]string, error) {
httpClient, httpRetries, _ := goflow.HTTP(rt.Config)
chatGPTClient := chatgpt.NewClient(httpClient, httpRetries, rt.Config.ChatGPTBaseURL, rt.Config.ChatGPTKey)
func GetProductListFromChatGPT(ctx context.Context, rtConfig *runtime.Config, content string) ([]string, *httpx.Trace, error) {
httpClient, httpRetries, _ := goflow.HTTP(rtConfig)
chatGPTClient := chatgpt.NewClient(httpClient, httpRetries, rtConfig.ChatGPTBaseURL, rtConfig.ChatGPTKey)

prompt1 := chatgpt.ChatCompletionMessage{
Role: chatgpt.ChatMessageRoleSystem,
Expand All @@ -190,17 +190,17 @@ func GetProductListFromChatGPT(ctx context.Context, rt *runtime.Runtime, content
Content: content,
}
completionRequest := chatgpt.NewChatCompletionRequest([]chatgpt.ChatCompletionMessage{prompt1, prompt2, prompt3, question})
response, _, err := chatGPTClient.CreateChatCompletion(completionRequest)
response, trace, err := chatGPTClient.CreateChatCompletion(completionRequest)
if err != nil {
return nil, errors.Wrapf(err, "error on chatgpt call for list products")
return nil, trace, errors.Wrapf(err, "error on chatgpt call for list products")
}

productsJson := response.Choices[0].Message.Content

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
}

0 comments on commit 8a75d5c

Please sign in to comment.