6 6
7# Getting started7# Getting started
8 8
9Some basic knowledge of Python and GitHub is helpful for this tutorial. Before diving in, make sure to [set up an OpenAI API key](https://developers.openai.com/api/reference/overview) and walk through the [quickstart tutorial](https://developers.openai.com/api/docs/quickstart). This will give a good intuition on how to use the API to its full potential.9Before starting, [set up an OpenAI API key](https://developers.openai.com/api/reference/overview) and work through the [quickstart tutorial](https://developers.openai.com/api/docs/quickstart).
10 10
11Use Python 3.11 or later. Create a virtual environment, install the packages used in the examples, and set `OPENAI_API_KEY` as described in the [quickstart](https://developers.openai.com/api/docs/quickstart).11
12
13
14Create a virtual environment and install the packages:
12 15
13```bash16```bash
14python -m venv env17python -m venv env
16python -m pip install openai pandas numpy requests beautifulsoup4 tiktoken matplotlib19python -m pip install openai pandas numpy requests beautifulsoup4 tiktoken matplotlib
17```20```
18 21
22Copy the Python examples into a file or notebook in the order shown.
19 23
20 24
21 25
22The Go examples use `github.com/openai/openai-go/v3` at `v3.98.0`, `github.com/tiktoken-go/tokenizer` at `v0.10.0`, and `golang.org/x/net/html` at `v0.63.0`. Use the complete programs in the [Go tutorial sample directory](https://github.com/openai/developers-website/tree/main/src/content/platform/go-examples/tutorial-crawl-website-embeddings). When running downloaded source files, replace `{{MODEL}}` with the model shown in the rendered example. Run each workflow step separately from the same working directory; don't concatenate their `main` functions. The hyperlink helpers share one program, and context retrieval, answering, and test questions share another.
23 26
24Replace `https://example.com` with your website's URL in the crawler, hyperlink, and scraped-data programs. Set `OPENAI_API_KEY` before the API steps. The Go crawler follows same-domain redirects and writes files under `text`; subsequent programs read and write `processed/scraped.csv`, `processed/chunks.json`, and `processed/embeddings.csv` in order. The histogram steps write `token-histogram.png` locally.27
28
29
30Download and extract the [TypeScript sample archive](https://developers.openai.com/api/docs/samples/typescript.tar.gz). From the extracted `typescript-examples` directory, run `pnpm install --ignore-workspace --frozen-lockfile`. The lockfile pins OpenAI, Cheerio, CSV, tokenizer, and canvas dependencies. Set `OPENAI_API_KEY` before the API steps.
31
32Run each complete program separately from the same working directory with `node --experimental-strip-types tutorial-crawl-website-embeddings/<filename>.ts`. Do not concatenate the excerpts: each file includes its own imports and setup. Run `crawl-website`, `build-scraped-dataframe`, `tokenize-scraped-text`, `split-long-text`, `visualize-chunk-token-counts`, `create-embeddings`, and `answer-question` in that order. The hyperlink helpers share one program; context retrieval, answering, and test questions share `answer-question.ts`.
33
34Replace `https://example.com` with your website's URL in the crawler, hyperlink, and scraped-data programs. Replace `{{MODEL}}` in the downloaded answering program with the model shown below. The crawler saves text under `text`; later stages produce `processed/scraped.csv`, `processed/chunks.json`, and `processed/embeddings.csv`. Run `create-embeddings` before answering questions; the package's synthetic CSV fixtures are only for local analysis tests.
35
25 36
26 37
27 38
28 39
29 40
30 41
42The Go examples use `github.com/openai/openai-go/v3`, `github.com/tiktoken-go/tokenizer`, and `golang.org/x/net/html`. Use the complete programs in the [Go tutorial sample directory](https://github.com/openai/developers-website/tree/main/src/content/platform/go-examples/tutorial-crawl-website-embeddings). When running downloaded source files, replace `{{MODEL}}` with the model shown in the rendered example. Run each workflow step separately from the same working directory; don't concatenate their `main` functions. The hyperlink helpers share one program, and context retrieval, answering, and test questions share another.
43
44Replace `https://example.com` with your website's URL in the crawler, hyperlink, and scraped-data programs. Set `OPENAI_API_KEY` before the API steps. The Go crawler follows same-domain redirects and writes files under `text`; subsequent programs read and write `processed/scraped.csv`, `processed/chunks.json`, and `processed/embeddings.csv` in order. The histogram steps write `token-histogram.png` locally.
45
46
47
31 48
32For Ruby, use Ruby 3.3 with the `openai`, `nokogiri`, `tiktoken_ruby`, and `chunky_png` gems. The [sample dependencies](https://github.com/openai/developers-website/blob/main/src/content/platform/ruby-examples/Gemfile) list tested versions.
33 49
34 50
35 51
52For Ruby, install the `openai`, `nokogiri`, `tiktoken_ruby`, and `chunky_png` gems. The [sample dependencies](https://developers.openai.com/api/docs/samples/ruby-Gemfile) list tested versions.
36 53
37Set `OPENAI_API_KEY` for either language.
38 54
39Copy the examples into a file or notebook for the selected language in the order shown.55
56
57Set `OPENAI_API_KEY` before running examples in your selected language.
40 58
41 59
42 60
76 94
77Set up the web crawler95Set up the web crawler
78 96
97```typescript
98import { load } from "cheerio";
99
100function getHTMLHyperlinks(html: string): string[] {
101 const document = load(html);
102 return document("a[href]")
103 .map((_, node) => document(node).attr("href")!)
104 .get();
105}
106```
107
79```python108```python
80import requests109import requests
81import re110import re
190 219
191Extract links from a page220Extract links from a page
192 221
222```typescript
223import { load } from "cheerio";
224
225function parseHTML(html: string): { links: string[]; text: string } {
226 const document = load(html);
227 document("script, style").remove();
228 return {
229 links: document("a[href]")
230 .map((_, node) => document(node).attr("href")!)
231 .get(),
232 text: document.root().text(),
233 };
234}
235
236function validURL(url: URL): boolean {
237 return (
238 ["http:", "https:"].includes(url.protocol) && !url.username && !url.password
239 );
240}
241
242async function fetchPage(address: string, domain: string) {
243 let url = new URL(address);
244 const signal = AbortSignal.timeout(10_000);
245 for (let redirects = 0; ; redirects++) {
246 if (!validURL(url) || url.host !== domain) {
247 throw new Error("Expected a same-domain HTTP or HTTPS URL");
248 }
249 url.hash = "";
250 const response = await fetch(url, { redirect: "manual", signal });
251 if ([301, 302, 303, 307, 308].includes(response.status)) {
252 await response.body?.cancel();
253 const location = response.headers.get("location");
254 if (!location) return null;
255 if (redirects >= 5) throw new Error("Too many redirects");
256 url = new URL(location, url);
257 continue;
258 }
259 if (
260 !response.ok ||
261 response.headers
262 .get("content-type")
263 ?.split(";")[0]
264 .trim()
265 .toLowerCase() !== "text/html"
266 ) {
267 await response.body?.cancel();
268 return null;
269 }
270 const reader = response.body?.getReader();
271 if (!reader) return null;
272 const buffers: Uint8Array[] = [];
273 let bytes = 0;
274 try {
275 while (true) {
276 const { done, value } = await reader.read();
277 if (done) break;
278 bytes += value.length;
279 if (bytes > 8 * 1024 * 1024) throw new Error("HTML page exceeds 8 MiB");
280 buffers.push(value);
281 }
282 } finally {
283 await reader.cancel();
284 }
285 return { url, ...parseHTML(Buffer.concat(buffers).toString("utf8")) };
286 }
287}
288
289async function getHyperlinks(address: string): Promise<string[]> {
290 const page = await fetchPage(address, new URL(address).host);
291 if (!page) return [];
292 return page.links.flatMap((link) => {
293 if (!link || link.startsWith("#")) return [];
294 try {
295 return [new URL(link, page.url).href];
296 } catch {
297 return [];
298 }
299 });
300}
301```
302
193```python303```python
194# Function to get the hyperlinks from a URL304# Function to get the hyperlinks from a URL
195def get_hyperlinks(url):305def get_hyperlinks(url):
370 480
371Keep links within the target domain481Keep links within the target domain
372 482
483```typescript
484async function getDomainHyperlinks(
485 domain: string,
486 address: string
487): Promise<string[]> {
488 const links = await getHyperlinks(address);
489 const result = new Set<string>();
490 for (const link of links) {
491 const url = new URL(link);
492 if (!validURL(url) || url.host !== domain) continue;
493 url.hash = "";
494 result.add(url.href);
495 }
496 return [...result];
497}
498const address = "https://example.com";
499console.log(
500 JSON.stringify(await getDomainHyperlinks(new URL(address).host, address))
501);
502```
503
373```python504```python
374# Function to get the hyperlinks from a URL that are within the same domain505# Function to get the hyperlinks from a URL that are within the same domain
375def get_domain_hyperlinks(local_domain, url):506def get_domain_hyperlinks(local_domain, url):
448 579
449Crawl the website580Crawl the website
450 581
582```typescript
583import { createHash } from "node:crypto";
584import { mkdir, writeFile } from "node:fs/promises";
585import path from "node:path";
586
587async function crawl(address: string): Promise<void> {
588 const initial = new URL(address);
589 if (!validURL(initial)) throw new Error("Expected an HTTP or HTTPS URL");
590 initial.hash = "";
591 const directory = path.join("text", initial.host);
592 await mkdir(directory, { recursive: true });
593 await mkdir("processed", { recursive: true });
594 const queue = [initial.href];
595 const queued = new Set(queue);
596 const visited = new Set<string>();
597 while (queue.length) {
598 const current = queue.pop()!;
599 const page = await fetchPage(current, initial.host);
600 if (!page || visited.has(page.url.href)) continue;
601 visited.add(page.url.href);
602 console.log(page.url.href);
603 const digest = createHash("sha256").update(page.url.href).digest("hex");
604 // URL-encoded paths keep filenames ASCII; the digest prevents collisions.
605 const prefix = `${initial.host}${page.url.pathname}`
606 .replaceAll("/", "_")
607 .slice(0, 186);
608 await writeFile(path.join(directory, `${prefix}#${digest}.txt`), page.text);
609 for (const link of page.links) {
610 if (!link || link.startsWith("#")) continue;
611 let next: URL;
612 try {
613 next = new URL(link, page.url);
614 } catch {
615 continue;
616 }
617 next.hash = "";
618 if (
619 !validURL(next) ||
620 next.host !== initial.host ||
621 queued.has(next.href) ||
622 visited.has(next.href)
623 )
624 continue;
625 queued.add(next.href);
626 queue.push(next.href);
627 }
628 }
629}
630
631await crawl("https://example.com");
632```
633
451```python634```python
452from hashlib import sha256635from hashlib import sha256
453 636
813 996
814Clean the scraped text997Clean the scraped text
815 998
999```typescript
1000function removeNewlines(texts: string[]): string[] {
1001 return texts.map((text) =>
1002 text.replaceAll("\n", " ").replaceAll("\\n", " ").replace(/ {2,}/g, " ")
1003 );
1004}
1005```
1006
816```python1007```python
817def remove_newlines(serie):1008def remove_newlines(serie):
818 serie = serie.str.replace("\n", " ")1009 serie = serie.str.replace("\n", " ")
871 1062
872Save scraped pages as a dataset1063Save scraped pages as a dataset
873 1064
1065```typescript
1066import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
1067import path from "node:path";
1068import { stringify } from "csv-stringify/sync";
1069
1070const address = new URL("https://example.com");
1071const directory = path.join("text", address.host);
1072const rows: { fname: string; text: string }[] = [];
1073const entries = await readdir(directory, { withFileTypes: true });
1074entries.sort((a, b) => a.name.localeCompare(b.name));
1075for (const entry of entries) {
1076 if (!entry.isFile() || !entry.name.endsWith(".txt")) continue;
1077 let title = entry.name.slice(0, -4).replace(/#[a-f0-9]{64}$/, "");
1078 if (title === address.host || title === `${address.host}_`) title = "index";
1079 else if (title.startsWith(`${address.host}_`))
1080 title = title.slice(address.host.length + 1);
1081 title = title.replaceAll("#update", "").replace(/[-_]/g, " ");
1082 const content = await readFile(path.join(directory, entry.name), "utf8");
1083 const text = content
1084 .replaceAll("\n", " ")
1085 .replaceAll("\\n", " ")
1086 .replace(/ {2,}/g, " ");
1087 rows.push({ fname: title, text: `${title}. ${text}` });
1088}
1089await mkdir("processed", { recursive: true });
1090await writeFile(
1091 "processed/scraped.csv",
1092 stringify(rows, {
1093 header: true,
1094 columns: ["fname", "text"],
1095 })
1096);
1097```
1098
874```python1099```python
875from pathlib import Path1100from pathlib import Path
876 1101
1040 1265
1041Count tokens in scraped pages1266Count tokens in scraped pages
1042 1267
1268```typescript
1269import { readFile, writeFile } from "node:fs/promises";
1270import { createCanvas } from "@napi-rs/canvas";
1271import { getEncoding } from "js-tiktoken";
1272const encoding = getEncoding("cl100k_base");
1273import { parse } from "csv-parse/sync";
1274const rows: { text: string }[] = parse(
1275 await readFile("processed/scraped.csv", "utf8"),
1276 { columns: true, skip_empty_lines: true }
1277);
1278const texts = rows.map((row) => row.text);
1279const counts = texts.map((text) => encoding.encode(text).length);
1280const bins = Array<number>(10).fill(0);
1281const maximum = Math.max(1, ...counts);
1282for (const count of counts)
1283 bins[Math.min(9, Math.floor((count / maximum) * 10))]++;
1284const canvas = createCanvas(800, 600);
1285const context = canvas.getContext("2d");
1286context.fillStyle = "white";
1287context.fillRect(0, 0, 800, 600);
1288context.fillStyle = "black";
1289context.font = "20px sans-serif";
1290context.fillText("Token counts", 40, 30);
1291const largestBin = Math.max(1, ...bins);
1292context.fillStyle = "steelblue";
1293for (const [index, count] of bins.entries()) {
1294 const height = (count / largestBin) * 480;
1295 context.fillRect(40 + index * 72, 540 - height, 68, height);
1296}
1297context.fillStyle = "black";
1298context.fillText("0", 40, 575);
1299context.fillText(String(maximum), 740, 575);
1300await writeFile("token-histogram.png", await canvas.encode("png"));
1301```
1302
1043```python1303```python
1044import tiktoken1304import tiktoken
1045 1305
1202 1462
1203Split long pages into chunks1463Split long pages into chunks
1204 1464
1465```typescript
1466import { readFile, writeFile } from "node:fs/promises";
1467import { parse } from "csv-parse/sync";
1468import { getEncoding } from "js-tiktoken";
1469
1470const encoding = getEncoding("cl100k_base");
1471function splitIntoMany(text: string, maxTokens = 500): string[] {
1472 if (!Number.isInteger(maxTokens) || maxTokens <= 0) {
1473 throw new Error("maxTokens must be a positive integer");
1474 }
1475 if (!text.trim()) return [];
1476 const sentences = text.split(". ");
1477 const chunks: string[] = [];
1478 let chunk = "";
1479 for (const [index, part] of sentences.entries()) {
1480 const sentence = index < sentences.length - 1 ? `${part}.` : part;
1481 if (encoding.encode(sentence).length > maxTokens) {
1482 throw new Error("Split the oversized sentence before chunking");
1483 }
1484 const candidate = chunk ? `${chunk} ${sentence}` : sentence;
1485 if (encoding.encode(candidate).length > maxTokens) {
1486 chunks.push(chunk);
1487 chunk = sentence;
1488 } else chunk = candidate;
1489 }
1490 if (chunk) chunks.push(chunk);
1491 return chunks;
1492}
1493
1494const rows: { text: string }[] = parse(
1495 await readFile("processed/scraped.csv", "utf8"),
1496 { columns: true, skip_empty_lines: true }
1497);
1498const chunks = rows.flatMap((row) => splitIntoMany(row.text));
1499await writeFile("processed/chunks.json", JSON.stringify(chunks));
1500```
1501
1205```python1502```python
1206max_tokens = 5001503max_tokens = 500
1207 1504
1411 1708
1412Visualize token counts after splitting1709Visualize token counts after splitting
1413 1710
1711```typescript
1712import { readFile, writeFile } from "node:fs/promises";
1713import { createCanvas } from "@napi-rs/canvas";
1714import { getEncoding } from "js-tiktoken";
1715const encoding = getEncoding("cl100k_base");
1716const texts: string[] = JSON.parse(
1717 await readFile("processed/chunks.json", "utf8")
1718);
1719const counts = texts.map((text) => encoding.encode(text).length);
1720const bins = Array<number>(10).fill(0);
1721const maximum = Math.max(1, ...counts);
1722for (const count of counts)
1723 bins[Math.min(9, Math.floor((count / maximum) * 10))]++;
1724const canvas = createCanvas(800, 600);
1725const context = canvas.getContext("2d");
1726context.fillStyle = "white";
1727context.fillRect(0, 0, 800, 600);
1728context.fillStyle = "black";
1729context.font = "20px sans-serif";
1730context.fillText("Token counts", 40, 30);
1731const largestBin = Math.max(1, ...bins);
1732context.fillStyle = "steelblue";
1733for (const [index, count] of bins.entries()) {
1734 const height = (count / largestBin) * 480;
1735 context.fillRect(40 + index * 72, 540 - height, 68, height);
1736}
1737context.fillStyle = "black";
1738context.fillText("0", 40, 575);
1739context.fillText(String(maximum), 740, 575);
1740await writeFile("token-histogram.png", await canvas.encode("png"));
1741```
1742
1414```python1743```python
1415df = pd.DataFrame(shortened, columns=["text"])1744df = pd.DataFrame(shortened, columns=["text"])
1416df["n_tokens"] = df.text.apply(lambda x: len(tokenizer.encode(x)))1745df["n_tokens"] = df.text.apply(lambda x: len(tokenizer.encode(x)))
1531 1860
1532Create embeddings for the scraped text1861Create embeddings for the scraped text
1533 1862
1863```typescript
1864import OpenAI from "openai";
1865import { readFile, writeFile } from "node:fs/promises";
1866import { stringify } from "csv-stringify/sync";
1867
1868const client = new OpenAI();
1869const chunks: string[] = JSON.parse(
1870 await readFile("processed/chunks.json", "utf8")
1871);
1872if (
1873 !Array.isArray(chunks) ||
1874 !chunks.every((text) => typeof text === "string")
1875) {
1876 throw new Error("Expected an array of text chunks");
1877}
1878const rows: (string | number)[][] = [["text", "n_tokens", "embeddings"]];
1879for (const text of chunks) {
1880 const response = await client.embeddings.create({
1881 model: "text-embedding-3-small",
1882 input: text,
1883 });
1884 if (
1885 response.data.length !== 1 ||
1886 response.data[0].index !== 0 ||
1887 !response.data[0].embedding.length
1888 ) {
1889 throw new Error("Expected one embedding per chunk");
1890 }
1891 rows.push([
1892 text,
1893 response.usage.prompt_tokens,
1894 JSON.stringify(response.data[0].embedding),
1895 ]);
1896}
1897await writeFile("processed/embeddings.csv", stringify(rows));
1898```
1899
1534```python1900```python
1535from openai import OpenAI1901from openai import OpenAI
1536 1902
1652 2018
1653Load the saved embeddings2019Load the saved embeddings
1654 2020
2021```typescript
2022import { readFile } from "node:fs/promises";
2023import { parse } from "csv-parse/sync";
2024
2025const records: { text: string; embeddings: string }[] = parse(
2026 await readFile("processed/embeddings.csv", "utf8"),
2027 { columns: true, skip_empty_lines: true }
2028);
2029const rows = records.map((row) => ({
2030 text: row.text,
2031 embedding: JSON.parse(row.embeddings) as number[],
2032}));
2033if (!rows.length) throw new Error("No embeddings");
2034const dimensions = rows[0].embedding.length;
2035for (const row of rows) {
2036 if (
2037 !Array.isArray(row.embedding) ||
2038 !dimensions ||
2039 row.embedding.length !== dimensions ||
2040 !row.embedding.every(Number.isFinite)
2041 ) {
2042 throw new Error("Expected finite embeddings with consistent dimensions");
2043 }
2044}
2045console.log(rows[0].embedding);
2046```
2047
1655```python2048```python
1656from ast import literal_eval2049from ast import literal_eval
1657import numpy as np2050import numpy as np
1755 2148
1756Build context for a question2149Build context for a question
1757 2150
2151```typescript
2152import OpenAI from "openai";
2153import { readFile } from "node:fs/promises";
2154import { parse } from "csv-parse/sync";
2155
2156interface EmbeddedRow {
2157 text: string;
2158 nTokens: number;
2159 embedding: number[];
2160}
2161async function loadEmbeddings(path: string): Promise<EmbeddedRow[]> {
2162 const records: { text: string; n_tokens: string; embeddings: string }[] =
2163 parse(await readFile(path, "utf8"), {
2164 columns: true,
2165 skip_empty_lines: true,
2166 });
2167 const rows = records.map((row) => ({
2168 text: row.text,
2169 nTokens: Number(row.n_tokens),
2170 embedding: JSON.parse(row.embeddings) as number[],
2171 }));
2172 if (!rows.length) throw new Error("No embeddings");
2173 const dimensions = rows[0].embedding.length;
2174 for (const row of rows) {
2175 if (
2176 typeof row.text !== "string" ||
2177 !Number.isInteger(row.nTokens) ||
2178 row.nTokens < 0 ||
2179 !Array.isArray(row.embedding) ||
2180 !dimensions ||
2181 row.embedding.length !== dimensions ||
2182 !row.embedding.every(Number.isFinite)
2183 ) {
2184 throw new Error("Invalid embedded row");
2185 }
2186 }
2187 return rows;
2188}
2189function cosineSimilarity(a: number[], b: number[]): number {
2190 if (a.length !== b.length || !a.length || !a.every(Number.isFinite))
2191 throw new Error("Invalid embedding dimensions or values");
2192 const dot = a.reduce((sum, value, i) => sum + value * b[i], 0);
2193 const norm = Math.sqrt(
2194 a.reduce((sum, value) => sum + value * value, 0) *
2195 b.reduce((sum, value) => sum + value * value, 0)
2196 );
2197 if (!(norm > 0)) throw new Error("Embedding must have a nonzero norm");
2198 return dot / norm;
2199}
2200async function createContext(
2201 client: OpenAI,
2202 question: string,
2203 rows: EmbeddedRow[],
2204 maxTokens = 1800
2205): Promise<string> {
2206 const response = await client.embeddings.create({
2207 model: "text-embedding-3-small",
2208 input: question,
2209 });
2210 if (response.data.length !== 1)
2211 throw new Error("Expected one query embedding");
2212 const ranked = rows
2213 .map((row) => ({
2214 row,
2215 similarity: cosineSimilarity(response.data[0].embedding, row.embedding),
2216 }))
2217 .sort((a, b) => b.similarity - a.similarity);
2218 const parts: string[] = [];
2219 let tokens = 0;
2220 for (const { row } of ranked) {
2221 tokens += row.nTokens + 4;
2222 if (tokens > maxTokens) break;
2223 parts.push(row.text);
2224 }
2225 return parts.join("\n\n###\n\n");
2226}
2227```
2228
1758```python2229```python
1759def distances_from_embeddings(query, embeddings, distance_metric="cosine"):2230def distances_from_embeddings(query, embeddings, distance_metric="cosine"):
1760 if distance_metric != "cosine":2231 if distance_metric != "cosine":
1964 2435
1965Answer a question from the website2436Answer a question from the website
1966 2437
2438```typescript
2439async function answerQuestion(
2440 client: OpenAI,
2441 rows: EmbeddedRow[],
2442 question: string
2443): Promise<string> {
2444 const context = await createContext(client, question, rows);
2445 const response = await client.responses.create({
2446 model: "gpt-6-luna",
2447 instructions:
2448 'Answer the question using only the supplied context. If the context does not answer the question, say "I don\'t know."',
2449 input: `Context: ${context}\n\nQuestion: ${question}`,
2450 });
2451 if (response.status !== "completed")
2452 throw new Error(`Response ended with status ${response.status}`);
2453 return response.output_text.trim();
2454}
2455```
2456
1967```python2457```python
1968def answer_question(df, question, max_len=1800):2458def answer_question(df, question, max_len=1800):
1969 context = create_context(question, df, max_len=max_len)2459 context = create_context(question, df, max_len=max_len)
2013 2503
2014Try example questions2504Try example questions
2015 2505
2506```typescript
2507const client = new OpenAI();
2508const rows = await loadEmbeddings("processed/embeddings.csv");
2509for (const question of [
2510 "What is ChatGPT?",
2511 "What did I have for breakfast today?",
2512]) {
2513 console.log(await answerQuestion(client, rows, question));
2514}
2515```
2516
2016```python2517```python
2017print(answer_question(df, "What is ChatGPT?"))2518print(answer_question(df, "What is ChatGPT?"))
2018print(answer_question(df, "What did I have for breakfast today?"))2519print(answer_question(df, "What did I have for breakfast today?"))