https://discord.gg/botpress logo
Please help me with chat gpt generate content card
# 💻developers
w
Hello, please help me ASAP, What I am looking for in this project is so I can pass data from my webhook into an HTTP Request (which I have already done successfully) and then give it to Chat GPT to summarize the content in that webhook and then send that summary to the user. Currently I am using the generate content card, it is getting the HTTP card which holds the webhook but when it tries to summarize, it gives an error code, the error has something to do with the text response. The error code and my card are provided below:
Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: Converting circular structure to JSON\n --> starting at object with constructor 'ClientRequest'\n | property 'res' -> object with constructor 'IncomingMessage'\n --- property 'req' closes the circle","reason":{"errorType":"TypeError","errorMessage":"Converting circular structure to JSON\n --> starting at object with constructor 'ClientRequest'\n | property 'res' -> object with constructor 'IncomingMessage'\n --- property 'req' closes the circle","stack":["TypeError: Converting circular structure to JSON"," --> starting at object with constructor 'ClientRequest'"," | property 'res' -> object with constructor 'IncomingMessage'"," --- property 'req' closes the circle"," at JSON.stringify ()"," at isStateDirty (/var/task/customer_code.js:3154:10200)"," at save (/var/task/customer_code.js:3154:11918)"," at saveAllStates (/var/task/customer_code.js:3155:510)"," at saveState (/var/task/customer_code.js:3155:3988)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: Converting circular structure to JSON"," --> starting at object with constructor 'ClientRequest'"," | property 'res' -> object with constructor 'IncomingMessage'"," --- property 'req' closes the circle"," at process. (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:531:35)"," at emitUnhandledRejection (node:internal/process/promises:250:13)"," at throwUnhandledRejectionsMode (node:internal/process/promises:385:19)"," at processPromiseRejections (node:internal/process/promises:470:17)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
w
Use an AI card instead
w
Is
workflow.responseData
filled with the all response of an axios call? or the response.data ?
w
Yes, if I dont put any response format, it comes out really weird but it works with no error. In one part of the response, it says "content:" and it does what I ask it to (Summarizing it in 5 sentences or less) but it comes out in a really weird format with curly brackets and different information that is not needed, for example the bot, gpt 4.
w
Ok, try to save
response.data.content
, or the path to content, in
workflow.responseData
.
w
I changed it to this (in the screenshot attached), I added ".content". The response is now this (with no response format) Here's the summary: { "id": "chatcmpl-B4gMB5OREBbZ8OJoUWQAVyjsIXN09", "provider": "OpenAI", "model": "gpt-4o-mini-2024-07-18", "choices": [ { "role": "assistant", "type": "text", "content": "Please provide the company data you would like me to summarize.", "index": 0, "stopReason": "stop" } ], "usage": { "inputTokens": 37, "inputCost": 0.000005549999999999999, "outputTokens": 12, "outputCost": 0.0000072 }, "botpress": { "cost": 0.000012749999999999998 } } As you can see it doesen't do it right, if I do it without the ".content" and no response format, this is the response I get, focus on the content: Here's the summary: { "id": "chatcmpl-B4gRIQG7B4BdtMxz6ZqVkRbA40oCR", "provider": "OpenAI", "model": "gpt-4o-mini-2024-07-18", "choices": [ { "role": "assistant", "type": "text", "content": "Clienthut, owned by Roni Gurevich, is a prospect in the software application industry specializing in AI CRM. The company is located in Prosper, Texas, with a postal code of 75078. It has one employee and currently reports an annual revenue of $0. Clienthut operates in the America/Chicago time zone and can be contacted at (612) 461-2924. More information can be found on their website at http://Clienthut.co.", "index": 0, "stopReason": "stop" } ], "usage": { "inputTokens": 197, "inputCost": 0.00002955, "outputTokens": 96, "outputCost": 0.0000576 }, "botpress": { "cost": 0.00008715 } } https://cdn.discordapp.com/attachments/1342720167611994112/1343795318067826770/image.png?ex=67be926a&is=67bd40ea&hm=6acb910a5886e9cad2365a96a41d3d61ec319bed4e70ddc28af1d9303f5de5a7&
w
Ok, i wrote to use the path to
content
, so it'd be
response.data.choices[0].content
w
w
I need to see the values you entered in the HTTP card. The strange format you see should be in JSON.
w
try
Copy code
ts
const fetchCompanyData = JSON.parse(workflow.fetchCompanyData.response.data)
console.log("fetchCompanyData: ", fetchCompanyData)
workflow.responseData = fetchCompanyData.choices[0].content
w
Basically the same error code,
Copy code
[414dd65b3d]    [bot-action]    [flow:SummarizeFlow] [node:Standard5] [card:"Extract and Log Company Data from Workflow Response"]:     Error executing action "inline-card:"Extract and Log Company Data from Workflow Response".js" in flow:SummarizeFlow:node:Standard5
  [Error, "[object Object]" is not valid JSON

Transpiled Code:

  003 async function __ROOT__() {
  004   var __defProp = Object.defineProperty;
  005   var __name = (target, value) => __defProp(target, "name", {
  006     value,
  007     configurable: true
  008   });
  009   async function __ROOT__() {
> 010     const fetchCompanyData = JSON.parse(workflow.fetchCompanyData.response.data);
                                        ^^^^^^^^^^
  011     console.log("fetchCompanyData: ", fetchCompanyData);
  012     workflow.responseData = fetchCompanyData.choices[0].content;
  013   }
  014   __name(__ROOT__, "__ROOT__");
  015   ;
> 016   return await __ROOT__();
                     ^^^^^^^^^^
  017   ;
> 018 }; return await __ROOT__();
                      ^^^^^^^^^^
]
should I change the response format to anything else? Currently I have it as nothing but I dont think that is the issue
@white-nest-40686 , may I know if you are working on it?
w
Hi, I need to call the API and check the response. Does your API require an API key or any other form of authorization?
w
No, my API doesn't require an API key or any other form of authorization—it simply validates the incoming JSON payload for a companyId. In my website I have a dataset which a user creates for valid companyId's, if you want I can send you one that I use for testing.
w
yes thank you, send me the payload to post to api. If you prefer send it to me in DM
w
Yes, I will send it through DM
w
if this
workflow.fetchCompanyData.response.data
contains the response of axios call to your API then it has not choices because these are in
workflow.sessionSummary
I think you must pass
workflow.fetchCompanyData.response.data
to Generte content without
JSON.parse()
and after generation text get
workflow.sessionSummary.choices[0].content
10 Views