I am a retool newbie and I created a chat app on retool where users can ask questions and using vectors and Ai the chat answers back. This works fine.
But I want to create a database where the Q&A any user asks is recorded. So I was thinking of utilising a workflow to help me get it done, but seem to be having a problem firstly connecting to the app and second making sure the Q&A are captured and populated in a retool database.
Below is an example of me trying and failing to build a workflow.
I see a couple problems in the workflow to start with:
when this block runs, the first thing it does is use the URL and request Method to send a REST Request. to do this, it has to first evaluate what the url is. the Resource you've made (TechBot API) sets the base url as ...Bot/.... which is probably something like https://api.openai.com/v1/. the 2nd half the URL, which describes the Endpoint, is provided by reading the value of {{ restQuery.data }}? and at this point in time the workflow block doesn't have the result from sending the GET request so restQuery.data evaluates to null or undefined 100% of the time. instead, you should check the docs for the API you're using and use one of those. for me, I'd use something like assistants or {{ "assistants" }} as the Endpoint, which would result in a GET request being sent to the URL of https://api.openai.com/v1/assistants.
the ? you have in the restQuery is probably not parsing/linting as valid syntax and if not, the result might not be what you expected. if you want to add a ? onto the end of a string I'd suggest either using .concat or the + operator: {{ myPreviousBlock.data.concat('?') }} or {{ myPreviousBlock.data + '?' }}
the same problem is occurring here. the block named code hasn't ran to completion yet so code and code.data don't exist yet. however, here I think you want to use const chatData = restQuery.data.
the last issue I can see right now is in the sqlQuery block. blocks only have 3 properties you can access (.data, .error and .metadata) all of which can only be used AFTER the block completes. this means instead of trying to reference the input directly with $BLOCK_INPUT_3.question try referencing the output of the block that has the value you want:
don't forget to click 'deploy' in the top right corner before testing from an app or anything outside that workflow. the workflow still won't work, but if you open the browsers dev tools (in chrome its ctrl + shift + i) you should see 4 lines of text somewhere in the console... depending on when you call the workflow and how many queries/REST requests are sent after running it, you might need to scroll up a bit. if those 4 debug lines don't help point you in the right direction or the console shows null for any of those and are no help at all, just let me know what the console output was so i can try and narrow down what's going on