changes to add an sql-agent example/tutorial#428
Conversation
|
Preview ID generated: preview-geoffs-1757438045-6cc35aa |
|
Preview ID generated: preview-geoffs-1757439890-086d40f |
|
Preview ID generated: preview-geoffs-1757455150-bd18afa |
|
Preview ID generated: preview-geoffs-1757515721-3101d4b |
|
Preview ID generated: preview-geoffs-1757520005-6d096a8 |
| :::python | ||
| ```python | ||
| import requests, pathlib | ||
|
|
||
| url = "https://storage.googleapis.com/benchmarks-artifacts/chinook/Chinook.db" | ||
| local_path = pathlib.Path("Chinook.db") | ||
|
|
||
| if local_path.exists(): | ||
| print(f"{local_path} already exists, skipping download.") | ||
| else: | ||
| response = requests.get(url) | ||
| if response.status_code == 200: | ||
| local_path.write_bytes(response.content) | ||
| print(f"File downloaded and saved as {local_path}") | ||
| else: | ||
| print(f"Failed to download the file. Status code: {response.status_code}") | ||
| ``` | ||
| ::: | ||
| :::js | ||
| ```js | ||
| import { existsSync } from "node:fs"; | ||
| import fs from "node:fs/promises"; | ||
| import path from "node:path"; | ||
|
|
||
| const url = "https://storage.googleapis.com/benchmarks-artifacts/chinook/Chinook.db"; | ||
| const localPath = path.resolve("Chinook.db"); | ||
|
|
||
| if (existsSync(localPath)) { | ||
| console.log(`${localPath} already exists, skipping download.`); | ||
| } else { | ||
| console.log(`Downloading ${url} ...`); | ||
| const resp = await fetch(url); | ||
| if (!resp.ok) throw new Error(`Failed to download DB. Status code: ${resp.status}`); | ||
| const buf = Buffer.from(await resp.arrayBuffer()); | ||
| await fs.writeFile(localPath, buf); | ||
| console.log(`File downloaded and saved as ${localPath}`); | ||
| } | ||
| ``` | ||
| ::: |
There was a problem hiding this comment.
do we need these code examples? is it more intuitive to just tell them download the db and put it in the same directory as the script?
There was a problem hiding this comment.
That's a good point. Sort of distracting.
I'm inclined toward keeping it as it just takes care of one step for the user.
I could/should collapse it so that a reader won't be distracted - only the few that really dig into it will find it.
In general, I think we might want to think about having a git-repo for examples as opposed to this.
The doc would go over highlights and important points, but the repo would have all the details -including a 'utilities' file where you could store things like this.
| const datasource = new DataSource({ type: "sqlite", database: localPath }); | ||
| const db = await SqlDatabase.fromDataSourceParams({ appDataSource: datasource }); | ||
|
|
||
| const SCHEMA = await db.getTableInfo(); |
There was a problem hiding this comment.
for the record I don't think we've touched these sql primitives for a year or so
|
Preview ID generated: preview-geoffs-1757524592-dfda4b2 |
Documentation update
Overview
added sql-agent example.
Preview: https://langchain-5e9cc07a-preview-geoffs-1757520005-6d096a8.mintlify.app/oss/python/langchain/sql-agent
Type of change
Related issues/PRs
Checklist
docs devsrc/docs.jsonif neededAdditional notes