Al_B
Al_B3mo ago

Using Firestore Collection Query Output in OpenAI Assistant Prompt

Hi - I'm trying to use the output from a Firestore Collection Query in the prompt of a subsequent OpenAI assistant node. Unfortunately, if I input the query's 'Document Data' object directly in the assistant prompt, the value returns undefined at runtime 😢 . (The query itself is succesful, I've validated that). I assume the Query output needs to be transformed somehow in order to be used in the assistant prompt, but I'm not sure how? I've tried the Parse and Stringify JSON nodes and neither worked. Does anyone have insight into what I have to do to the object in order to utilize? Thanks in advance!
6 Replies
AI Support
AI Support3mo ago
It sounds like you need to transform the output from the Firestore Collection Query into a format that the OpenAI assistant node can understand. You may need to extract specific values from the 'Document Data' object and format them appropriately before passing them to the assistant prompt. To achieve this, you can use the "Set Variable" node to extract and format the data from the Firestore query result. Here's a general approach: 1. Firestore Collection Query Node: Ensure your query is correctly fetching the data. 2. Set Variable Node: Use this node to extract specific fields from the 'Document Data' object and format them as needed. 3. OpenAI Assistant Node: Use the formatted data from the "Set Variable" node in your prompt. For more detailed guidance, please refer to the BuildShip documentation on Firestore Collection Query and Set Variable Node. If you need further assistance, please submit your query via the in-app support button.
Gaurav Chadha
Gaurav Chadha3mo ago
@Al_B You can refer to this answer - You can make the query outside the Assistant node and then add an empty node inside the Assistant then store the variable output of the Firestore Collection Query node to make your workflow work, alternatively, you can add the use our Firestore Collection Video - https://www.youtube.com/watch?v=B0g0FWqWSLg. Also answered another workaround here as well - https://discord.com/channels/853498675484819476/1257809665484652686/1258085989167927319.
BuildShip
YouTube
Streaming AI Assistant on FlutterFlow with BuildShip Template
Learn how to get streaming response from AI Assistant connected to your database and tools on FlutterFlow with BuildShip. This is a full stack template. Cloneables here: BuildShip Template: https://buildship.app/remix?template=streaming-assistant-flutterflow FlutterFlow Marketplace App: https://marketplace.flutterflow.io/item/xvsvtzyflKhmxN7UVa...
Al_B
Al_B3mo ago
Hi @Gaurav Chadha - Thanks for the response. My request is different from the other workaround you referenced as I don't want to run Query Collection as a function of the Assistant. I already run the Query Collection as an independent node before the Assistant node; I instead want to use that Collection output directly in the Assistant prompt (see screenshot). Am I understanding correctly that in this case, the best practice is to store the output as an empty node within the Assistant, then provide the Assistant with instructions that it needs to run the empty node Function to grab that value?
No description
AI Support
AI Support3mo ago
Hi @699325537612726394, In your case, you can indeed use the output of the Query Collection node directly in the Assistant prompt. The best practice would be to store the output of the Query Collection node in a variable or a data store node, and then reference that variable or data store within your Assistant node. For detailed steps and best practices on how to achieve this, please refer to the BuildShip documentation on Using Variables and Data Stores. If you need further assistance, please submit your request via the in-app support button.
Al_B
Al_B3mo ago
In case someone else runs into this issue, I found the best solution in this case was to create an empty node with code to transform the Firestore output into JSON string. (I used ChatGPT to generate this code.) I then reference the empty node's output directly in the Assistant's user prompt. To me, this is much more preferable than storing the empty node as a function within the assistant. Functions require additional instructions to the Assistant to access, which can sometimes be unreliable and take additional processing time.
AI Support
AI Support3mo ago
It sounds like you're using a custom script node to transform Firestore output into a JSON string and then referencing this node's output directly in the Assistant's user prompt. This approach can indeed be more efficient and reliable. For more details on customizing nodes and working with script nodes in BuildShip, you can refer to the following documentation: - Script Node If you have further questions or need specific guidance, please submit your query via the in-app support button.
Script Node – BuildShip
A unified resource to start building your backend with low-code. Dive into triggers, nodes, and step-by-step guidance to jumpstart your workflow creation.