Best Practice for OpenAI to read big product catalogue

(Sioulis Nick) #1


I am using OpenAI since is out and I think now is the time to add it to my flows as it is an awesome tool.
Because of the limitations to prompt size I want to know what is the best practice to read a json for 1000 products?

I already have implemented an API query that for example someone can add the product name or product code and get back basic results like price, photo and description.
In the case that someone know the exact name or product code the results are nice even without AI.

But what if someone search just “hair straightener” and I have 5 different hair straighteners products?
The json will return 5 products with all the product details (json elements). The size is big and the OpenAI don’t read it.

Is there any way that can make rules:

  1. if more than 1 “product_id” results in json,
  2. then filter the results and pass only product names, price and sku (to reduce json the size)
  3. and then parse it to OpenAI’s prompt and “ask customer which of these products customer want…”
  4. and then make a new query of the product with all details?
  5. Give final OpenAi answer about the product

Above is just my idea but I am open to better practices if you can suggest me something else.

thank you in advance!

(Sioulis Nick) #2

i am also facing one more issue, if you can help me with, it is related to when i am trying to filter the JSON so I reduce the answer that will be parsed to OpenAI,

I successfully put the http request trigger (JSON) in a variable called “param”.
Then when I test it in the chat i successfully receive a message with the JSON.:

let data = inputs.param;

Now when I am trying to filter it and get only the results that I need I dont get any answer:

let data = inputs.param;
let result ={ product_id, product }) => ({ product_id, product }));

I have tested the code outside flowxo in a file (console.log) and the results are ok and code works.

Do i have to write it in different way in “execute code” trigger to get the correct result?

(Sioulis Nick) #3

I have solved it:

let param = [];
try {
  param = JSON.parse(inputs.param);
} catch(e) {
  return reject('Input must be valid JSON');
let result ={ product_code, product,price }) => ({ product_code, product ,price}));

(I Magiс) #4

Hi, Nick. You have the very interesting case. Can you give more details about how you using chatGpt for saving and reading data as your product catalogue?

(Sioulis Nick) #5

OpenAi solves a problem I had before with customers that didn’t know the product code (sku) or they couldn’t say the exact name of the product.
So as an example,
I have my platform and flowxo connected with API calls. So I have a trigger that a customer search for a product and I make a query to my platform with the customer’s given message.

  1. a customer enters the chat and then goes into a trigger that can search a product for details.
  2. If the customer gives the product code for example “DM0123” then the product with this unique product code is called and I am serving its product photo, price, and some details.
  3. If a customer writes in a message something like “hair straightener” my API call return all the products that are hair straighteners… So it was complicated to serve all these to customers and ask which finally he wanted

Now with OpenAI I have managed to pass the JSON into it and then I order OpenAI to ask the customer which product he wants from the found ones.
OpenAI answers like that:
I have several products:
Electric Hair straightener DM2222
Ceramic Hair straightener DM3333
Electronic Hair straightener DM444

Which would you like to know more?

So now I am trying to find a way when a customer makes a choice of these to activate trigger that can serve the product info as I wrote above

(Sioulis Nick) #6

As a bonus… the next level of product search trigger is if i could prompt to OpenAI all my products (1400+).
So when a customer ask: “Do you have any hair straighteners?” then the OpenAI can answer yes we have these… bla bla bla … which of these I found would you like to know more?

But for now the 4096token are too small for something like that.
I don’t know if flowxo sheets Q/A could help to make something like that?
That’s why I wrote this post to get some help

(Nathan Stults) #7

Yes, you can do this, but what you’re talking about is what is called Semantic Search. In general, Open AI alone can’t help with that, because there is no way to provide enough data because of the token limit, as you say.

There are multiple solutions to this. One of them would be to use a search index, like, and query its API.

Another one that just uses Google Sheets would be to have a list of your products, with a category column. Then use Open AI to “classify” a query into a product category, search your Google Sheets for all products relating to the category, combine all the text for just those products into a single prompt, THEN use OpenAI again (via ChatGPT) to answer the users question with the prompt containing the filtered products.

It’s will take some work, but it’s definitely possible. We’re probably going to enable a built-in semantic search feature in the near future, but for now you would have to roll your own the way I mentioned.

1 Like
(Sioulis Nick) #8

I will try it and let you know!
Thank you for your help Nathan