|
| 1 | +# 🔥 How to connect FirebaseDB to Copilot |
| 2 | + |
| 3 | +## Create the Firebase Function |
| 4 | + |
| 5 | +### Step 1: Create a Firebase project |
| 6 | + |
| 7 | +.png>) |
| 8 | + |
| 9 | +.png>) |
| 10 | + |
| 11 | +### Step 2: Create a Realtime DB in Firebase |
| 12 | + |
| 13 | +Once you have created the RTDB, copy the RTDB URL |
| 14 | + |
| 15 | +.png>) |
| 16 | + |
| 17 | +.png>) |
| 18 | + |
| 19 | +.png>) |
| 20 | + |
| 21 | +### Step 3: Duplicate the Firebase Function |
| 22 | + |
| 23 | +Head to the FirebaseDB example in Gooey.AI (see the link below), duplicate the example by using the “Save as New” button and adding it to your workspace |
| 24 | + |
| 25 | +{% embed url="https://gooey.ai/functions/firebase-rtdb-post-with-cryptohash-8vs0hcmv8fuz/" %} |
| 26 | + |
| 27 | +.png>) |
| 28 | + |
| 29 | +.png>) |
| 30 | + |
| 31 | +### Step 4: Paste the RTDB URL in Gooey.AI Functions |
| 32 | + |
| 33 | +Paste the RTDB URL from Step 2 and replace it in the \`firebaseURL\` as shown below |
| 34 | + |
| 35 | +.png>) |
| 36 | + |
| 37 | +### Step 5: Create a path in Firebase RTDB |
| 38 | + |
| 39 | +Head back to your Firebase Realtime Database and add a name value to the RTDB, eg `data` |
| 40 | + |
| 41 | +.png>) |
| 42 | + |
| 43 | +### Step 6: Get Firebase API key |
| 44 | + |
| 45 | +.png>) |
| 46 | + |
| 47 | +.png>) |
| 48 | + |
| 49 | +### Step 7: Add the Firebase API key to Gooey Secrets |
| 50 | + |
| 51 | +Go back to Function you have created in Gooey.AI, scroll down to “Secrets” section. Click on the “Add” button |
| 52 | + |
| 53 | +.png>) |
| 54 | + |
| 55 | +Add the “name” as FIREBASE\_API\_KEY and the API key which you copied from Firebase in the “value” section, and save the key. |
| 56 | + |
| 57 | +.png>) |
| 58 | + |
| 59 | +Once its saved, select it from the drop down. |
| 60 | + |
| 61 | +.png>) |
| 62 | + |
| 63 | +[Know more about adding secrets here](how-to-use-secrets-in-functions.md) |
| 64 | + |
| 65 | +### Step 8: Test function |
| 66 | + |
| 67 | +#### Step 8.1: You can hit “Run” to test if the function is working.  |
| 68 | + |
| 69 | +If the log shows a “successful” message. Your screen should show this message: |
| 70 | + |
| 71 | +.png>) |
| 72 | + |
| 73 | +#### Step 8.2: Please check the firebaseRTDB for data updates. Your data should have uploaded. |
| 74 | + |
| 75 | +<figure><img src="../../.gitbook/assets/15 (2).png" alt=""><figcaption></figcaption></figure> |
| 76 | + |
| 77 | +### Step 9: Save the workflow |
| 78 | + |
| 79 | +Save the changes by clicking “Update” |
| 80 | + |
| 81 | +On saving the function to your workspace, please remember to add a detailed description of what the function does, this will allow the AI Copilot to use the functions in an agentic way |
| 82 | + |
| 83 | +.png>) |
| 84 | + |
| 85 | +## Add Firebase Function to Copilot |
| 86 | + |
| 87 | +### Step 1: Add function to Copilot |
| 88 | + |
| 89 | +Duplicate the example by using the “Save as New” button and adding it to your workspace |
| 90 | + |
| 91 | +{% embed url="https://gooey.ai/copilot/nurse-julie-health-voice-conversations-to-patient-records-cqd11cspkz4o/" %} |
| 92 | + |
| 93 | +Scroll down to the “Developer Tools and Functions” section in the Copilot, toggle it on and select the Firebase Function that you saved.  |
| 94 | + |
| 95 | +.png>) |
| 96 | + |
| 97 | +### Step 2: Add prompt instruction |
| 98 | + |
| 99 | +Your prompt needs to be a bit detailed to make sure that the Functions are working properly. \ |
| 100 | +You need this: |
| 101 | + |
| 102 | +1. To make sure Copilot knows it needs to call a Function at appropriate time, |
| 103 | +2. To ensure that LLM translates natural language conversation to JSON data structure as per your requirement |
| 104 | + |
| 105 | +Your prompt could look something like this: |
| 106 | + |
| 107 | +{% code overflow="wrap" %} |
| 108 | +``` |
| 109 | +You are Nurse Jane - an AI bot to assist community health care workers upload medical records after their family visits to find basic demographics and history. |
| 110 | +These are the steps you need to follow: |
| 111 | +
|
| 112 | +1. Introduce yourself with this script as a guideline: |
| 113 | +"Hello I'm Nurse Julie - your family health care provider, I can provide guidance on creating a health record and integrating care recommendations" |
| 114 | +
|
| 115 | +2. Ask for the user to provide, if they miss any data point, please ask them to share that. Don't create any records until all the data is captured: |
| 116 | +
|
| 117 | + Community health worker's name (required) |
| 118 | + Date of case note (required) |
| 119 | + Patient's name (required) |
| 120 | + Date of Birth (required) |
| 121 | + Phone Number (required) |
| 122 | + Family members (required) |
| 123 | + Address (required) |
| 124 | + Date of visit/session (required) |
| 125 | + Purpose of visit/session (required) |
| 126 | + Observations (required) |
| 127 | + Topics discussed (required) |
| 128 | +
|
| 129 | +3. Don't create any records until all the data is captured. Then ask if they'd like to create medical record based on this information. Create the record as the following JSON and POST to firebase DB. Please don't run the function until user gives you approval. |
| 130 | +
|
| 131 | +{ |
| 132 | + data: { |
| 133 | + mobile: string, |
| 134 | + patient_name: string, |
| 135 | + address: string, |
| 136 | + dateOfBirth: string, |
| 137 | + family_member: string, |
| 138 | + pid: number, |
| 139 | + health_workers_name: string, |
| 140 | + case_date: date, |
| 141 | + visit_date: date, |
| 142 | + visit_purpose: string, |
| 143 | + observations: string, |
| 144 | + topics_discussed: string |
| 145 | + } |
| 146 | +} |
| 147 | +
|
| 148 | +4. If you are asked to retrieve the information of a patient ask for the phone number and use the firebase RTDB Get function to retrieve it |
| 149 | +
|
| 150 | +Guidelines: |
| 151 | +- Avoid answering questions that don't pertain to health matters |
| 152 | +- Respond without emojis, bulleted lists or special symbols (e.g. “*”) |
| 153 | +- Respond in the same language as the user. e.g. if they ask a question in Hindi, reply in Hindi. |
| 154 | +- Use simple, direct language. |
| 155 | +``` |
| 156 | +{% endcode %} |
| 157 | + |
| 158 | +#### What is the prompt doing? |
| 159 | + |
| 160 | +* In point 2 of the prompt, we have shared all the information the Copilot must collect to create a record. |
| 161 | +* In point 3, we provide a FIXED json format for the LLM to output. This ensures that the data pushed to the FirebaseDB is always in the same format, which is important for retrieval |
| 162 | +* In point 4, we instruct the Copilot to utilize Functions when the user requests to retrieve or push information. |
| 163 | + |
| 164 | +### Step 3: Test copilot  |
| 165 | + |
| 166 | +In the chatbox of the Copilot Builder, you can run a test to check whether the Copilot is working.  |
| 167 | + |
| 168 | +{% embed url="https://gooey.ai/copilot/?run_id=d8igsxs87l1x&uid=fm165fOmucZlpa5YHupPBdcvDR02" %} |
| 169 | + |
| 170 | +If the Function is run, you can see the widget with all the details.  |
| 171 | + |
| 172 | +<figure><img src="../../.gitbook/assets/Screenshot 2025-03-11 at 1.56.29 PM.png" alt=""><figcaption></figcaption></figure> |
| 173 | + |
| 174 | +You can also confirm if the data has been created and stored by logging into the Firebase RTDB like [Step 8 from above](how-to-connect-firebasedb-to-copilot.md#step-8-test-function). |
| 175 | + |
| 176 | +### Step 4: Save the workflow |
| 177 | + |
| 178 | +Save the changes by clicking “Update”. |
0 commit comments