Spaces:
Running
Running
Commit
•
15917f6
1
Parent(s):
d25a864
add more examples
Browse files- src/routes/+page.svelte +17 -17
- src/snippets/alpaca_to_chatml.md +88 -0
- src/snippets/show_tables.md +26 -0
- src/snippets/table_info.md +36 -0
- static/alpaca-to-conversation.png +0 -0
src/routes/+page.svelte
CHANGED
@@ -11,22 +11,22 @@
|
|
11 |
<meta name="description" content="A collection of snippets for DuckDB." />
|
12 |
</svelte:head>
|
13 |
|
14 |
-
<section class="max-w-2xl mx-auto px-4 py-8">
|
15 |
-
<h1 class="text-5xl mt-
|
16 |
<p class="text-base text-center text-slate-600 mb-8">{config.description}</p>
|
17 |
<ul class="space-y-12">
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
11 |
<meta name="description" content="A collection of snippets for DuckDB." />
|
12 |
</svelte:head>
|
13 |
|
14 |
+
<section class="max-w-2xl mx-auto px-4 py-8 pb-32">
|
15 |
+
<h1 class="text-5xl mt-10 font-bold text-center tracking-tight text-slate-800 mb-8">{config.title}</h1>
|
16 |
<p class="text-base text-center text-slate-600 mb-8">{config.description}</p>
|
17 |
<ul class="space-y-12">
|
18 |
+
{#each data.snippets as snippet}
|
19 |
+
<li class="bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow duration-300">
|
20 |
+
<div class="p-4">
|
21 |
+
<a href={`${snippet.slug}`} class="block mb-4 hover:underline transition-colors duration-300">
|
22 |
+
<h2 class="text-2xl font-bold transition-colors duration-300">{snippet.title}</h2>
|
23 |
+
</a>
|
24 |
+
<p class="text-sm text-slate-700 font-mono mb-6">{snippet.description}</p>
|
25 |
+
{#if snippet.code}
|
26 |
+
<CodeBlock code={snippet.code} language="sql" />
|
27 |
+
{/if}
|
28 |
+
</div>
|
29 |
+
</li>
|
30 |
+
{/each}
|
31 |
+
</ul>
|
32 |
+
</section>
|
src/snippets/alpaca_to_chatml.md
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
id: "alpaca-to-chatml"
|
3 |
+
title: "Convert Alpaca to Conversation Format"
|
4 |
+
slug: "alpaca-to-chatml"
|
5 |
+
description: "Convert Alpaca format to ChatML Conversation format"
|
6 |
+
code: |
|
7 |
+
-- Convert Alpaca format to Conversation format
|
8 |
+
WITH
|
9 |
+
source_view AS (
|
10 |
+
SELECT * FROM train -- Change 'train' to your desired view name here
|
11 |
+
)
|
12 |
+
SELECT
|
13 |
+
[
|
14 |
+
struct_pack(
|
15 |
+
"from" := 'system',
|
16 |
+
"value" := instruction
|
17 |
+
),
|
18 |
+
struct_pack(
|
19 |
+
"from" := 'user',
|
20 |
+
"value" := input
|
21 |
+
),
|
22 |
+
struct_pack(
|
23 |
+
"from" := 'assistant',
|
24 |
+
"value" := output
|
25 |
+
)
|
26 |
+
] AS conversation
|
27 |
+
FROM source_view
|
28 |
+
WHERE instruction IS NOT NULL
|
29 |
+
AND input IS NOT NULL
|
30 |
+
AND output IS NOT NULL;
|
31 |
+
---
|
32 |
+
|
33 |
+
# Converting Alpaca to ChatML Conversation Format
|
34 |
+
|
35 |
+
```sql
|
36 |
+
-- Convert Alpaca format to Conversation format
|
37 |
+
WITH
|
38 |
+
source_view AS (
|
39 |
+
SELECT * FROM train -- Change 'train' to your desired view name here
|
40 |
+
)
|
41 |
+
SELECT
|
42 |
+
[
|
43 |
+
struct_pack(
|
44 |
+
"from" := 'system',
|
45 |
+
"value" := instruction
|
46 |
+
),
|
47 |
+
struct_pack(
|
48 |
+
"from" := 'user',
|
49 |
+
"value" := input
|
50 |
+
),
|
51 |
+
struct_pack(
|
52 |
+
"from" := 'assistant',
|
53 |
+
"value" := output
|
54 |
+
)
|
55 |
+
] AS conversation
|
56 |
+
FROM source_view
|
57 |
+
WHERE instruction IS NOT NULL
|
58 |
+
AND input IS NOT NULL
|
59 |
+
AND output IS NOT NULL;
|
60 |
+
```
|
61 |
+
|
62 |
+
## Why?
|
63 |
+
|
64 |
+
Differences between Alpaca and ChatML Conversation Format:
|
65 |
+
|
66 |
+
1. **Alpaca Format**:
|
67 |
+
- The Alpaca format usually has three columns: `instruction`, `input`, and `output`.
|
68 |
+
|
69 |
+
2. **ChatML Conversation Format**:
|
70 |
+
- The ChatML Conversation format is a JSON format that contains a list of messages.
|
71 |
+
- Each message has a `from` field, which can be either `system`, `user`, or `assistant`.
|
72 |
+
- The `value` field contains the message content.
|
73 |
+
|
74 |
+
|
75 |
+
## Example
|
76 |
+
|
77 |
+
### `yahma/alpaca-cleaned`
|
78 |
+
|
79 |
+
<iframe
|
80 |
+
src="https://huggingface.co/datasets/yahma/alpaca-cleaned/embed/viewer/default/train"
|
81 |
+
frameborder="0"
|
82 |
+
width="100%"
|
83 |
+
height="560px"
|
84 |
+
></iframe>
|
85 |
+
|
86 |
+
You can run this query through via the `sql_console` in the Hugging Face Hub [here](https://huggingface.co/datasets/yahma/alpaca-cleaned?sql_console=true&sql=WITH+%0Asource_view+AS+%28%0A++SELECT+*+FROM+train++--+Change+%27train%27+to+your+desired+view+name+here%0A%29%0ASELECT+%0A++%5B%0A++++struct_pack%28%0A++++++%22from%22+%3A%3D+%27system%27%2C%0A++++++%22value%22+%3A%3D+instruction%0A++++%29%2C%0A++++struct_pack%28%0A++++++%22from%22+%3A%3D+%27user%27%2C%0A++++++%22value%22+%3A%3D+input%0A++++%29%2C%0A++++struct_pack%28%0A++++++%22from%22+%3A%3D+%27assistant%27%2C%0A++++++%22value%22+%3A%3D+output%0A++++%29%0A++%5D+AS+conversation%0AFROM+source_view%0AWHERE+instruction+IS+NOT+NULL+%0A++AND+input+IS+NOT+NULL+%0A++AND+output+IS+NOT+NULL%3B).
|
87 |
+
|
88 |
+
![Alpaca to ChatML](./alpaca-to-conversation.png)
|
src/snippets/show_tables.md
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
id: "duckdb-show-tables"
|
3 |
+
title: "Show Tables"
|
4 |
+
slug: "duckdb-show-tables-query"
|
5 |
+
description: "List all tables that are loaded using SHOW TABLES or PRAGMA show_tables."
|
6 |
+
code: |
|
7 |
+
-- List all tables using SQL command
|
8 |
+
SHOW TABLES;
|
9 |
+
|
10 |
+
-- List all tables using PRAGMA
|
11 |
+
PRAGMA show_tables;
|
12 |
+
---
|
13 |
+
|
14 |
+
# DuckDB Show Tables Query
|
15 |
+
|
16 |
+
This snippet demonstrates how to list all tables in the current DuckDB database using either the `SHOW TABLES` command or the `PRAGMA show_tables` function.
|
17 |
+
|
18 |
+
```sql
|
19 |
+
-- List all tables using SQL command
|
20 |
+
SHOW TABLES;
|
21 |
+
|
22 |
+
-- List all tables using PRAGMA
|
23 |
+
PRAGMA show_tables;
|
24 |
+
```
|
25 |
+
|
26 |
+
You can read more about this [here](https://duckdb.org/docs/configuration/pragmas.html#metadata).
|
src/snippets/table_info.md
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
id: "duckdb-table-info"
|
3 |
+
title: "Table Info"
|
4 |
+
slug: "duckdb-table-info-query"
|
5 |
+
description: "Get detailed information about a table's structure"
|
6 |
+
code: |
|
7 |
+
-- Returns detailed information about a table's structure
|
8 |
+
-- Use this to get the column names, types, and other details
|
9 |
+
PRAGMA table_info('table_name');
|
10 |
+
---
|
11 |
+
|
12 |
+
# DuckDB Table Info Query
|
13 |
+
|
14 |
+
This snippet demonstrates how to use the `PRAGMA table_info` function in DuckDB to get detailedinformation about a specific table's structure.
|
15 |
+
|
16 |
+
Try out this query [here](https://huggingface.co/datasets/NousResearch/hermes-function-calling-v1?sql_console=true&sql=pragma+table_info%28%27func_calling_singleturn%27%29)
|
17 |
+
|
18 |
+
```sql
|
19 |
+
-- Returns detailed information about a table's structure
|
20 |
+
-- Use this to get the column names, types, and other details
|
21 |
+
PRAGMA table_info('table_name');
|
22 |
+
```
|
23 |
+
|
24 |
+
# Example Output
|
25 |
+
|
26 |
+
| cid | name | type | notnull | dflt_value | pk |
|
27 |
+
|-----|---------------|------------------------------------------|---------|------------|-------|
|
28 |
+
| 0 | id | VARCHAR | false | null | false |
|
29 |
+
| 1 | conversations | STRUCT("from" VARCHAR, "value" VARCHAR)[] | false | null | false |
|
30 |
+
| 2 | category | VARCHAR | false | null | false |
|
31 |
+
| 3 | subcategory | VARCHAR | false | null | false |
|
32 |
+
| 4 | task | VARCHAR | false | null | false |
|
33 |
+
|
34 |
+
You can read more about this [here](https://duckdb.org/docs/configuration/pragmas.html#table-information).
|
35 |
+
|
36 |
+
|
static/alpaca-to-conversation.png
ADDED