Skip to content

Commit ba8263c

Browse files
committed
Add local files example
Signed-off-by: Craig Jellick <[email protected]>
1 parent 230c275 commit ba8263c

File tree

4 files changed

+248
-7
lines changed

4 files changed

+248
-7
lines changed

docs/docs/01-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Here are some sample use cases of GPTScript:
1515
1. Chat with a local CLI - [Try it!](examples/cli)
1616
2. Chat with an OpenAPI compliant endpoint - [Try it!](examples/api)
1717
3. Chat with a RAG based solution - [Try it!](examples/rag)
18-
4. Chat with local files and directories - [Try it!](examples/local-data)
18+
4. Chat with local files and directories - [Try it!](examples/local-files)
1919
5. Run an automated workflow - [Try it!](examples/workflow)
2020

2121

docs/docs/02-examples/01-cli.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This script **does not install** or configure gh or kubectl. We assume you've do
1313

1414
:::
1515

16-
## Too long; didn't read
16+
## Too Long; Didn't Read
1717

1818
Want to start using this script now? Just run:
1919

@@ -282,5 +282,5 @@ You can drop in your task and CLI and have a fairly functional CLI-based chat ag
282282

283283
Hopefully you've found this guide helpful. From here, you have several options:
284284

285-
- You can checkout out some of our other guides for other types of scripts you can build
286-
- You can dive deeper into the options available when writing script
285+
- You can checkout out some of our other guides available in this section of the docs
286+
- You can dive deeper into the options available when [writing script](/tools/gpt-file-reference)

docs/docs/02-examples/04-local-data.md

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# Chat with a Local Files
2+
3+
With GPTScript interacting with local files is simple and powerful. This can help you streamline repetitive or data-intensive tasks. In this guide, we'll build a script that can query Excel files, CSVs, and PDFs. We'll then use the script to read, transform, and utilize the data in these files.
4+
5+
## Too Long; Didn't Read
6+
7+
:::warning
8+
The below command will allow GPTScript to work with the files in your ~/Documents directory. Change the directory if you want to restrict it.
9+
:::
10+
11+
Want to start using this script now? Just run:
12+
```
13+
gptscript --workspace=~/Documents github.com/gptscript-ai/local-files-demo
14+
```
15+
16+
## Getting Started
17+
The rest of this guide will walk you through building and using a data processing assistant. We'll be explaining the how, what, and why along the way.
18+
19+
First, let's get some sample data to work with. You can clone our repo with our sample data:
20+
```
21+
git clone https://github.com/gptscript-ai/local-files-demo.git
22+
cd local-files-demo
23+
```
24+
25+
Next, open up a new gptscript file in your favorite editor. We'll call the file data-assistant.gpt.
26+
```
27+
vim data-assistant.gpt
28+
```
29+
All edits below are assumed to be in this file.
30+
31+
### Create the Assistant
32+
Put this in the gpt file:
33+
```
34+
Name: Your Data Processing Assitant
35+
Description: An asistant to help you with processing data found in files on your workstation. Helpful for querying spreadsheets, CSVs, JSON files, and pdfs.
36+
Tools: github.com/gptscript-ai/structured-data-querier, github.com/gptscript-ai/pdf-reader
37+
Context: github.com/gptscript-ai/context/workspace
38+
Chat: true
39+
40+
You are a helpful data processing assistant. Your goal is to help the user with data processing. Help the user accomplish their tasks using the tools you have. When the user starts this chat, just say hi, introduce yourself, and ask what you can help with.
41+
```
42+
This is actually the entirety of the script. We're packing a lot of power into just a handful of lines here. Let's talk through them.
43+
44+
**Name and Description** help the LLM understand the purpose of this tool. You should always have meaningful names and descriptions.
45+
46+
The **Tools: ...** stanza pulls two useful tools into this assistant.
47+
48+
The [structured-data-querier](https://github.com/gptscript-ai/structured-data-querier) makes it possible to query csv, xlsx, and json files as though they SQL databases (using an application called [DuckDB](https://duckdb.org/)). This is extremely powerful when combined with the power of LLMs because it let's you ask natural language questions that the LLM can then translate to SQL.
49+
50+
The [pdf-reader](https://github.com/gptscript-ai/pdf-reader) isn't quite as exciting, but still useful. It parses and reads PDFs and returns the contents to the LLM. This will put the entire contents in your chat context, so it's not appropriate for extremely large PDFs, but it's handy for smaller ones.
51+
52+
**Context: github.com/gptscript-ai/context/workspace** introduces a context tool makes this assistant "workspace" aware. It's description reads:
53+
> Adds the workspace and tools needed to access the workspace to the current context
54+
55+
That translates to telling the LLM what the workspace directory is and instructing it to use that directory for reading and writing files. As we saw above, you can specify a workspace like this:
56+
```
57+
gptscript --workspace=/Your/path/here ...
58+
```
59+
If you don't specify one, a temporary directory will be created and used for the workspace.
60+
61+
This context also shares the `sys.read`, `sys.write`, and `sys.ls` built-in tools with the assistant so that it automatically has access to them.
62+
63+
Next we have **Chat: true**, which you've seen if you looked at any of our other guides. This makes the current tool "chat-able". We refer to chatable tools as agents or assistants.
64+
65+
Finally, we have the prompt:
66+
> You are a helpful data processing assistant. Your goal is to help the user with data processing tasks. Help the user accomplish their tasks using the tools you have. When the user starts this chat, just say hi, introduce yourself, and ask what you can help with.
67+
68+
69+
## Using the Assistant
70+
Once again, that's all there is to this assistant. You can start using it by specifying your own workspace or using our sample-data directory as the workspace. Assuming you're using our sample data and have followed these instructions, here's how you launch it:
71+
```
72+
gptscript --workspace=./sample-data data-assistant.gpt
73+
```
74+
75+
Here's a few sample interactions with these files.
76+
77+
### Cleaning up data
78+
```
79+
> whats in the key contacts file?
80+
81+
The key_contacts.txt file contains the following information:
82+
83+
Contains location, name & email
84+
Scranton - Michael [email protected]
85+
Stamford Martin [email protected]
86+
Nashua - Rachael, [email protected]
87+
Utica,Ross - [email protected]
88+
Albany Allen [email protected]
89+
90+
Camden. Kali. [email protected]
91+
Yonkers - Meredith - [email protected]
92+
Rochester Kevin
93+
Syracuse William [email protected]
94+
95+
Is there anything specific you would like to do with this information?
96+
97+
> That looks bad. Can you make a cleaned up csv of it?
98+
99+
Sure, I'll clean up the data and create a CSV file for you. Here's the cleaned-up data in CSV format:
100+
101+
Location,Name,Email
102+
Scranton,Michael,[email protected]
103+
Stamford,Martin,[email protected]
104+
Nashua,Rachael,[email protected]
105+
Utica,Ross,[email protected]
106+
Albany,Allen,[email protected]
107+
108+
Camden,Kali,[email protected]
109+
Yonkers,Meredith,[email protected]
110+
Rochester,Kevin,
111+
Syracuse,William,[email protected]
112+
113+
I will now create a CSV file with this cleaned-up data.
114+
```
115+
116+
### Identifying and fixing data gaps
117+
```
118+
> is there any missing data in that csv?
119+
...
120+
Yes, there is missing data in the CSV file. Specifically, the email for Kevin in Rochester is missing.
121+
122+
Would you like to update this information or perform any other actions?
123+
> yes set his email to kev@ and use the same domain as the others
124+
125+
I will update Kevin's email to [email protected] in the CSV file.
126+
```
127+
128+
### Cross-referencing
129+
```
130+
> what were sales like for Kevin's location?
131+
132+
To find out sales for Kevin's location, I will need to check the yoy_sales.xlsx file for any relevant data. Let me take a
133+
look at the contents of that file.
134+
...
135+
The sales data for Rochester, where Kevin is located, is as follows:
136+
137+
LOCATION │ PRODUCT SKU │ MARCH 2023 SALES │ MARCH 2024 SALES │ YOY SALES GROWTH (%)
138+
────────────┼─────────────┼──────────────────┼──────────────────┼───────────────────────
139+
Rochester │ SKU_001 │ $803.91 │ $843.10 │ 12.12%
140+
Rochester │ SKU_002 │ $3,013.36 │ $3,159.02 │ 13.13%
141+
Rochester │ SKU_003 │ $1,879.24 │ $1,968.20 │ 12.15%
142+
Rochester │ SKU_004 │ $4,989.81 │ $5,239.30 │ 13.88%
143+
Rochester │ SKU_005 │ $4,334.03 │ $4,550.73 │ 12.70%
144+
Rochester │ SKU_006 │ $2,143.76 │ $2,251.95 │ 13.07%
145+
Rochester │ SKU_007 │ $7,976.54 │ $8,375.37 │ 12.23%
146+
Rochester │ SKU_008 │ $313.21 │ $328.87 │ 13.80%
147+
Rochester │ SKU_009 │ $671.70 │ $705.29 │ 12.91%
148+
Rochester │ SKU_010 │ $4,084.94 │ $4,289.19 │ 13.03%
149+
150+
Is there anything else you would like to know or do with this data?
151+
```
152+
### Pulling all the info together
153+
```
154+
> Let's help Kevin raise sales. What promotions do we have going on?
155+
...
156+
Here are the current promotions for office paper products:
157+
158+
1. Dunder Supreme Multi-Purpose Paper
159+
• Product SKU: SKU_001
160+
• Promotion Period: May 1 - May 31
161+
• Details: Buy two reams of Dunder Supreme and get one free. This paper is ideal for both professional and
162+
personal use, made from sustainably sourced forests.
163+
2. Scranton Elite Glossy Photo Paper
164+
• Product SKU: SKU_003
165+
• Promotion Period: May 1 - May 31
166+
• Details: Receive a 25% discount on every pack. This paper is designed for vibrant color reproduction and
167+
unrivaled photo quality, perfect for professional portfolios or family memories.
168+
3. MiSlin Premium Cardstock
169+
• Product SKU: SKU_005
170+
• Promotion Period: May 1 - May 31
171+
• Details: Buy one, get one 50% off on all cardstock purchases. This cardstock is ideal for presentations,
172+
report covers, and crafts, praised for its durability and smooth finish.
173+
174+
175+
These promotions can help Kevin boost sales in Rochester. Is there anything specific you would like to do with
176+
this information?
177+
178+
> craft an email summarizing performance at this location and these promotions
179+
180+
Here's a draft email summarizing the performance at Kevin's location and the current promotions:
181+
182+
--------
183+
184+
Subject: Sales Performance and Upcoming Promotions for Rochester
185+
186+
Dear Kevin,
187+
188+
I hope this email finds you well.
189+
190+
I wanted to take a moment to review the recent sales performance for Rochester and share some exciting promotions
191+
that can help boost our sales further.
192+
193+
Sales Performance: The sales data for Rochester has shown promising growth across various product SKUs. Here are
194+
the highlights:
195+
196+
• SKU_001: March 2023 Sales: $803.91 | March 2024 Sales: $843.10 | YoY Growth: 12.12%
197+
• SKU_002: March 2023 Sales: $3,013.36 | March 2024 Sales: $3,159.02 | YoY Growth: 13.13%
198+
• SKU_003: March 2023 Sales: $1,879.24 | March 2024 Sales: $1,968.20 | YoY Growth: 12.15%
199+
• SKU_004: March 2023 Sales: $4,989.81 | March 2024 Sales: $5,239.30 | YoY Growth: 13.88%
200+
• SKU_005: March 2023 Sales: $4,334.03 | March 2024 Sales: $4,550.73 | YoY Growth: 12.70%
201+
• SKU_006: March 2023 Sales: $2,143.76 | March 2024 Sales: $2,251.95 | YoY Growth: 13.07%
202+
• SKU_007: March 2023 Sales: $7,976.54 | March 2024 Sales: $8,375.37 | YoY Growth: 12.23%
203+
• SKU_008: March 2023 Sales: $313.21 | March 2024 Sales: $328.87 | YoY Growth: 13.80%
204+
• SKU_009: March 2023 Sales: $671.70 | March 2024 Sales: $705.29 | YoY Growth: 12.91%
205+
• SKU_010: March 2023 Sales: $4,084.94 | March 2024 Sales: $4,289.19 | YoY Growth: 13.03%
206+
207+
Upcoming Promotions: To further enhance our sales, we have some exciting promotions lined up for May:
208+
209+
1. Dunder Supreme Multi-Purpose Paper (SKU_001)
210+
• Promotion Period: May 1 - May 31
211+
• Details: Buy two reams and get one free. Ideal for both professional and personal use, made from sustainably
212+
sourced forests.
213+
2. Scranton Elite Glossy Photo Paper (SKU_003)
214+
• Promotion Period: May 1 - May 31
215+
• Details: Receive a 25% discount on every pack. Perfect for vibrant color reproduction and unrivaled photo
216+
quality.
217+
3. MiSlin Premium Cardstock (SKU_005)
218+
• Promotion Period: May 1 - May 31
219+
• Details: Buy one, get one 50% off on all cardstock purchases. Ideal for presentations, report covers, and
220+
crafts.
221+
222+
223+
These promotions are designed to attract more customers and increase our sales. Please ensure that these
224+
promotions are prominently displayed and communicated to our customers.
225+
226+
If you have any questions or need further assistance, feel free to reach out.
227+
228+
Best regards,
229+
230+
[Your Name] [Your Position] [Your Contact Information]
231+
232+
--------
233+
234+
Feel free to customize this email further to better suit your needs. Let me know if there's anything else I can
235+
assist you with!
236+
```
237+
Try it out yourself and see what you can come up with.
238+
239+
## Next steps
240+
241+
Hopefully you've found this guide helpful. From here, you have several options:
242+
243+
- You can checkout out some of our other guides available in this section of the docs
244+
- You can dive deeper into the options available when [writing script](/tools/gpt-file-reference)

0 commit comments

Comments
 (0)