Skip to content

Commit

Permalink
Slim/sql (#31)
Browse files Browse the repository at this point in the history
* setup sql agent graph

* Refactor the sub-graph prompt injection

* Move prompts over to examples

* Update graph for sql agent
  • Loading branch information
slimslenderslacks authored Nov 11, 2024
1 parent 487e16c commit f908bc8
Show file tree
Hide file tree
Showing 28 changed files with 422 additions and 196 deletions.
8 changes: 5 additions & 3 deletions graphs/prompts/journals/2024_09_03.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
- if the project being analyzed is located somewhere other than $PWD then the `--host-dir` will need to be updated.
- [[Running the Prompt Engine]]
- [[Authoring Prompts]]
- ---
id:: 66d7f3ff-8769-40b3-b6b5-fc4fceea879e
- id:: 66d7f3ff-8769-40b3-b6b5-fc4fceea879e
```
---
extractors:
- name: linguist
image: vonwig/go-linguist:latest
Expand Down Expand Up @@ -84,4 +85,5 @@
This project contains {{language}} code.
{{/linguist}}
Can you find any language specific project files and list them?
Can you find any language specific project files and list them?
```
4 changes: 3 additions & 1 deletion graphs/prompts/pages/Authoring Prompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ A prompt file can also contain metadata about how to generate and run the prompt
{{embed ((66d7f3ff-8769-40b3-b6b5-fc4fceea879e)) }}
The example above defines a lot of metadata. A prompt file might also be very simple.
{{embed ((66d8a396-9268-4917-882f-da4c52b7b5dd)) }}
Use the [prompt engine]([[Running the Prompt Engine]]) to run this prompt file against an LLM.
Use the [prompt engine]([[Running the Prompt Engine]]) to run this prompt file against an LLM.
- ## Prompt Metadata
-
37 changes: 37 additions & 0 deletions graphs/prompts/pages/interpolation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- When defining tools in prompt metadata, users can _interpolate_ tool parameters into the `commands` section of a container definition. For example, in the following definition of a sqlite tool, the `database` and `sql` parameters from the tool definition will be used to create the container.
```
- name: sqlite
description: run the sqlite command
parameters:
type: object
properties:
database:
type: string
description: the path to the database
sql:
type: string
description: the sql statement to run
container:
image: vonwig/sqlite:latest
command:
- "{{database}}"
- "{{sql|safe}}"
```
- You can also splice array parameters into the command definition using the `into` filter keyword:
```
- name: docker
description: run any docker command with arguments
parameters:
type: object
properties:
args:
type: array
items:
type: string
description: arguments to pass to the docker CLI
container:
image: docker:cli
command:
- "{{args|into}}"
```
In this example, the array of strings passed to the `args` parameter of the function will be spliced into the `command` parameter of the container definition.
18 changes: 0 additions & 18 deletions prompts/dockerfiles/npm-best-practices.md

This file was deleted.

2 changes: 0 additions & 2 deletions prompts/dockerfiles_llama3.1/010_system_prompt.md

This file was deleted.

21 changes: 0 additions & 21 deletions prompts/dockerfiles_llama3.1/100_user_prompt.md

This file was deleted.

24 changes: 0 additions & 24 deletions prompts/dockerfiles_llama3.1/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions prompts/dockerfiles_mistral-nemo/010_system_prompt.md

This file was deleted.

19 changes: 0 additions & 19 deletions prompts/dockerfiles_mistral-nemo/100_user_prompt.md

This file was deleted.

24 changes: 0 additions & 24 deletions prompts/dockerfiles_mistral-nemo/README.md

This file was deleted.

File renamed without changes.
8 changes: 5 additions & 3 deletions prompts/examples/dood.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ tools:
type: object
properties:
args:
type: string
type: array
items:
type: string
description: arguments to pass to the docker CLI
container:
image: docker:cli
command:
- "{{args|safe}}"
- "{{args|into}}"
---

# prompt user

1. run the docker command to figure out which images have been pulled
1. use the docker command to start up a mysql server running on port 8080

File renamed without changes.
9 changes: 9 additions & 0 deletions prompts/qrencode/README.md → prompts/examples/qrencode.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ Generate a QR code for the content
Save the generated image to `qrcode.png`.
If the command fails, read the man page and try again.
If successful, output the path to the generated image in markdown syntax.

# Testing

After running the above prompt, there should be a file named `qrcode.png` in the current project's host directory.

```bash
open qrcode.png
```

Binary file added prompts/sql/Chinook.db
Binary file not shown.
7 changes: 7 additions & 0 deletions prompts/sql/prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
agent: sql
---

# prompt user

find all artists in database ./Chinook.db
37 changes: 37 additions & 0 deletions prompts/sql/query-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
tools:
- name: sqlite3
description: execute the DB query
parameters:
type: object
properties:
sql:
type: string
description: the sql statement to run
container:
image: vonwig/sqlite:latest
command:
- "./Chinook.db"
- "{{sql}}"
---

# prompt system

You are a SQL expert with a strong attention to detail.
Double check the SQLite query for common mistakes, including:
- Using NOT IN with NULL values
- Using UNION when UNION ALL should have been used
- Using BETWEEN for exclusive ranges
- Data type mismatch in predicates
- Properly quoting identifiers
- Using the correct number of arguments for functions
- Casting to the correct data type
- Using the proper columns for joins

If there are any of the above mistakes, rewrite the query. If there are no mistakes, just reproduce the original query.

You will call the appropriate tool to execute the query after running this check.

# prompt user

SELECT * FROM Artist LIMIT 10;
27 changes: 27 additions & 0 deletions prompts/sql/query-gen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
---

# prompt system

You are a SQL expert with a strong attention to detail.

Given an input question, output a syntactically correct SQLite query to run, then look at the results of the query and return the answer.

DO NOT call any tool besides SubmitFinalAnswer to submit the final answer.

When generating the query:

Output the SQL query that answers the input question without a tool call.

Unless the user specifies a specific number of examples they wish to obtain, always limit your query to at most 5 results.
You can order the results by a relevant column to return the most interesting examples in the database.
Never query for all the columns from a specific table, only ask for the relevant columns given the question.

If you get an error while executing a query, rewrite the query and try again.

If you get an empty result set, you should try to rewrite the query to get a non-empty result set.
NEVER make stuff up if you don't have enough information to answer the query... just say you don't have enough information.

If you have enough information to answer the input question, simply invoke the appropriate tool to submit the final answer to the user.

DO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database.
48 changes: 48 additions & 0 deletions prompts/sql/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

# SQLite

## sqlite list tables

With sqlite, how do I figure out what tables are present?
How do I run sqlite with a file and a sql command?

```
docker run --rm -v $PWD:/workdir --workdir /workdir vonwig/sqlite:latest ./Chinook.db ".tables"
```

```
Album Employee InvoiceLine PlaylistTrack
Artist Genre MediaType Track
Customer Invoice Playlist
[Process exited 0]
```

## sqlite get db schema for table

How do I get the schema for a table in sqlite?

```
docker run --rm -v $PWD:/workdir --workdir /workdir vonwig/sqlite:latest ./Chinook.db ".schema Album"
```

```
CREATE TABLE [Album]
(
[AlbumId] INTEGER NOT NULL,
[Title] NVARCHAR(160) NOT NULL,
[ArtistId] INTEGER NOT NULL,
CONSTRAINT [PK_Album] PRIMARY KEY ([AlbumId]),
FOREIGN KEY ([ArtistId]) REFERENCES [Artist] ([ArtistId])
ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX [IFK_AlbumArtistId] ON [Album] ([ArtistId]);
```

## sqlite execute query

```
docker run --rm -v $PWD:/workdir --workdir /workdir vonwig/sqlite:latest ./Chinook.db "SELECT * FROM Album LIMIT 5"
```


Loading

0 comments on commit f908bc8

Please sign in to comment.