Skip to content

Commit 939b96e

Browse files
authored
Update AI Assistants To Send Files As Attachments.md
1 parent 843d927 commit 939b96e

File tree

1 file changed

+99
-43
lines changed

1 file changed

+99
-43
lines changed
Lines changed: 99 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,66 @@
1-
> ### **4 minute read                                                                                                                         `Advanced`**
21

3-
## AI assistants to send files as attachment.
2+
<h3>
3+
<table>
4+
<tr>
5+
<td><b>6 minutes read</b></td>
6+
<td style={{ paddingLeft: 40 }}><b> Level: Advanced</b></td>
7+
<td style={{ paddingLeft: 40 }}><b>Last Updated: October 2025</b></td>
8+
</tr>
9+
</table>
10+
</h3>
11+
12+
13+
# AI Assistants to Send Files as Attachments
14+
15+
This guide outlines the steps to enable AI assistants in Glific to send file links or attachments along with text responses to user queries.The key is to provide the file search assistant with,
16+
- Well-structured and accessible knowledge base.
17+
- A simple and structured prompt with examples output expected.
418

5-
### Summary
6-
The blog captures steps to enable AI assistants in Glific to send links to the files along with the text which captures the answer/ response to a question by a contact. The trick lies in providing the files search assistant with: (a) appropriately structured knowledge base, (b) an simple and structured prompt with examples output expected.
719

820
### Premise
9-
Before you proceed ahead, read here to get the basic understanding of how to use filesearch assistants in Glific.
21+
Before you proceed ahead, [read here](https://glific.github.io/docs/docs/Integrations/Filesearch%20Using%20OpenAI%20Assistants) to get the basic understanding of how to use `File Search Assistants` in Glific.
22+
1023

11-
### The Use Case
12-
For orgs that have PDFs or any other files containing specific information, who want to accomplish the following:
13-
Deliver the answer from the information: This is a simple file search implementation, where all the files are added as the knowledge base in text/pdf form for an assistant to then generate answers from.
14-
But also, deliver the files where the information retrieved by LLM resides: this is a filesearch implementation where a separate assistant can be created which has been given only the links to the files along with some description on what the file contains.
24+
## The Use Case
25+
For organizations that store important information in PDFs or other files, there are often two needs:
26+
- Answer user questions using the content from these files.
27+
- Share the actual file where the information was found.
1528

16-
The blog details how to accomplish point 2 explained above.
29+
This setup is useful when users not only want an answer, but also access to the original source. For example, a teacher may ask about a specific lesson plan and also need the PDF for reference.
1730

18-
This can be done in two ways.
19-
1. Delivering the file as a link in the message
20-
2. Delivering the file as an attachment (a file sent over whatsapp)
31+
This guide focuses on enabling assistants to respond with both the answer and the corresponding file, using either:
32+
- A link to the source, or
33+
- A file attachment.
2134

22-
### Example Use Case
23-
Leadership for Equity has a large repository of compartmentalized lesson plans in form of PDF files. Based on the subject, grade and lesson plan number as selected or determined earlier in the conversation, a teacher needs to be supported either by answering questions about the lesson plan and/or providing the lesson plan PDF itself.
2435

36+
## Example Use Case
37+
Leadership for Equity has a large repository of compartmentalized lesson plans in the form of PDF files. Based on the subject, grade and lesson plan number as selected or determined earlier in the conversation, a teacher needs to be supported either by answering questions about the lesson plan and/or providing the lesson plan PDF itself.
2538

26-
## Delivering files as a link in the message:
39+
---
2740

41+
## Delivering File as a Link in the Message
42+
This method shares a clickable link to the file along with the AI Assistant’s response. The screenshot below shows a response where the link to the video file is shared directly in the message.
2843

2944
<img width="467" alt="Screenshot 2025-03-05 at 5 17 03 PM" src="https://github.com/user-attachments/assets/0cda9835-1364-4513-8aad-842f206de5f9" />
3045

31-
Screenshot of an response which shares the link to the file in the message itself.
3246

47+
### Steps to Deliver File Links in the Messages
3348

34-
**Steps**:
49+
#### Step 1: Prepare the Knowledge Base
50+
Curate the knowledge base so that it includes links to the relevant files, along with brief descriptions indicating the type of information each file contains.
51+
- Ensure the files added in the knowledge base are universally accessible.
52+
- Write the prompt and include a few examples of how the answer should be generated and structured.
3553

36-
1. Curate the knowledge base in such a way that link to the files are part of the knowledge base document and also which there is a brief description provided as to what kind of information the file actually contains.
54+
Example shown below the screenshot of the knowledge base document, displaying the file title and its corresponding link for the Large Language Model (LLM)
3755

3856
<img width="393" alt="Screenshot 2025-03-05 at 5 18 33 PM" src="https://github.com/user-attachments/assets/39e87206-dd79-4f06-a231-61f7f1289c2e" />
3957

40-
Screenshot from the knowledge base file, showing the title and the link to the file for the LLM.
58+
#### Step 2: Create an AI Assistant
59+
[Click here](https://glific.github.io/docs/docs/Integrations/Filesearch%20Using%20OpenAI%20Assistants) to understand how to create an AI Assistant.
60+
While creating an AI Assistant prompt should be clear and include a few examples of how the answer should be generated and structured.
4161

42-
2. Ensure the files added in the knowledge base are universally accessible.
43-
3. Write the prompt and include a few examples of how the answer should be generated and structured.
62+
Prompt example: Courtesy - Leadership for Equity
4463

45-
PROMPT (curtsey Leadership for Eqquity)
4664
```
4765
You're a chatbot who is an empathetic responder to queries of teachers, teacher mentors and officials engaged with NGO called Leadership for Equity. Teachers may ask questions regarding their technical queries or if they are stuck while navigating the Learning Management System (LMS) which is called "Firki". The teachers who ask you questions will need responses in the simplest language possible and in maximum 5-7lines
4866
@@ -61,38 +79,47 @@ Instructions for you to respond to a question
6179
6. DO NOT HALLUCINATE the video link. Share only the links that are present in the document.
6280
```
6381

82+
6483
This is the simplest and the fastest way to deliver files, if there is a large number of files involved, and they are already stored in a shared drive. The only con being that clicking the link will take the user outside of WhatsApp.
6584

66-
## Delivering the file as an attachment (a file sent over whatsapp)
85+
86+
#### Step 3: Configure in the flow
87+
- Users can add the `AI Assistants` to the flow where the end user interacts with them.
88+
- Refer to `Filesearch Assistants` documentation to know how to configure assistants in the flow.
89+
90+
91+
92+
## Delivering File as an Attachment
93+
This method sends the file directly as a downloadable attachment in the chat. The screenshot below shows a response where a PDF attachment is shared directly in the message.
94+
6795
<img width="679" alt="Screenshot 2025-03-05 at 5 19 53 PM" src="https://github.com/user-attachments/assets/07e851e3-8ab1-4a66-953e-c37731aecd5d" />
6896

6997
Screenshot showing the file delivered as an attachment.
7098

71-
**Steps:**
7299

73-
1. Curate the knowledge base which has the required headings, structure as well as links to all the Google Cloud Storage URLs
74-
2. The main point here is to have the description of content in the given file.
75-
3. A simple google sheet format can be done to first collate all the file urls and information of what is contained with in the files, or a simple doc with the relevant details in a structured way.
76-
4. This can be provided to chatGPT to convert into a JSON format.
77-
5. This JSON output which contains the GCS urls should be downloaded or can be saved in a doc.
78-
6. Use this as the knolwedge base.
79-
<img width="514" alt="Screenshot 2025-03-05 at 5 20 27 PM" src="https://github.com/user-attachments/assets/c633fed5-5929-46dc-a2fe-aeb1c3e801bf" />
100+
### Steps to Deliver Attachments in Messages
101+
102+
#### Step 1: Prepare the Knowledge Base
103+
Curate the knowledge base which has the required headings, structure as well as links to all the Google Cloud Storage URLs
104+
- Use a Google Sheet or doc listing all file URLs (from Google Cloud Storage).
105+
- Add a short description of what each file contains.
106+
- Convert this into a structured JSON format using ChatGPT or a script.
107+
- This JSON output which contains the GCS urls should be downloaded or can be saved in a doc, this is used as a knowledge base.
108+
109+
Given below is the screenshot of how GCS urls can be structured as a database.
80110

81-
Screenshot of how the GCS urls can be structured as a knowledge base.
111+
<img width="468" height="345" alt="Screenshot 2025-10-09 at 1 03 05 PM" src="https://github.com/user-attachments/assets/e22576dc-6c2e-4e8d-9152-7bc27ba2fdcb" />
82112

83-
7. Provide the context in a well structured prompt which instructs the assistant to only generate file urls as the response. Give it a few examples. (an example prompt shown below)
84-
8. In the flow, add a validation to check of the response from the assistant is a file by using split by result like shown in the flow.
85-
<img width="655" alt="Screenshot 2025-03-05 at 5 20 58 PM" src="https://github.com/user-attachments/assets/074bb485-2661-4904-8fa3-b6c5a4815da3" />
86113

87-
Screenshot explaining how a Glific flow can be structured to ensure that the file generated are validated before being sent as attachments.
88114

89-
Screenshot of how flow or contact variables like subject, grade, week, day can be passed as an additional parameters to the assistant
90115

91-
Send it as an attachment by using the “expression” option in the attachments section.
92116

93-
Screenshot showing how to use webhook response to send the file as an attachment.
117+
#### Step 2: Create an AI Assistant
118+
- Create an AI Assistant by going to AI Assistants pane.
119+
- Users are advised to write a targeted prompt instructing the assistant to return the file attachment in the response.
120+
121+
Prompt example:
94122

95-
PROMPT:
96123
```
97124
You are an AI assistant with access to a structured knowledge base of lesson plan links for different grades and weeks and days. Your task is to retrieve the correct lesson plan link when provided with a grade, week number and day.
98125
@@ -120,6 +147,35 @@ Output: "No lesson plan found for the given grade and week."
120147
Return only the valid link or the specified error message—no additional text or assumptions
121148
```
122149

123-
## Credits
124-
The above flows and screenshots taken from chatbot developed in collaboration with Leadership for Equity.
150+
#### Step 3: Add AI Assistant to the flow editor
151+
- Refer to `Filesearch Assistants` documentation to know how to configure assistants in the flow.
152+
153+
154+
#### Step 4: Add Save result and Splitby node
155+
Add a `Save Flow result` node after the `webhook call` and provide details as shown in the screenshot below.
156+
157+
<img width="465" height="393" alt="Screenshot 2025-10-09 at 1 09 18 PM" src="https://github.com/user-attachments/assets/39b77048-ceff-42a5-870e-6734f459288d" />
158+
159+
In the given example `lessonplanfile` is the result name of webhook node.
160+
161+
- Add Split by result node to check whether the response has GCS url or not.
162+
163+
<img width="471" height="321" alt="Screenshot 2025-10-09 at 1 11 07 PM" src="https://github.com/user-attachments/assets/caa6f6de-4fbe-4fac-af32-412065889b45" />
164+
165+
166+
167+
#### Step 5: Send File as Attachment
168+
- Add Send Message node
169+
- Click on attachments and select expression from dropdown and pass the the variable as shown in the screenshot below.
170+
171+
<img width="466" height="193" alt="Screenshot 2025-10-09 at 1 21 23 PM" src="https://github.com/user-attachments/assets/811ea6f3-d05f-488a-8559-6b70d360c64c" />
172+
173+
174+
---
175+
### Credits
176+
The above flows and screenshots taken from chatbot developed in collaboration with Leadership for Equity.
177+
178+
179+
180+
125181

0 commit comments

Comments
 (0)