Skip to content

Commit 26b8341

Browse files
committed
llm: Add Text-to-SQL example with Gemma3 via Ollama
Gemma3 works well for basic Text-to-SQL at least.
1 parent b8448e4 commit 26b8341

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
llm<0.27
22
llm-anthropic<0.18
3+
llm-ollama<0.14
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Given an input question, first create a syntactically correct CrateDB query to run,
2+
then look at the results of the query and return the answer. You can order the
3+
results by a relevant column to return the most interesting examples in the database.
4+
5+
Never query for all the columns from a specific table, only ask for a few relevant
6+
columns given the question.
7+
8+
Pay attention to use only the column names that you can see in the schema description.
9+
Be careful to not query for columns that do not exist. Pay attention to which column
10+
is in which table. Also, qualify column names with the table name when needed. You
11+
are required to use the following format, each taking one line:
12+
13+
Question: Question here
14+
SQLQuery: SQL Query to run
15+
Only use tables listed below.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Given an input question, synthesize a response from the query results.
2+
Query:

topic/machine-learning/llm/test.xsh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ $XONSH_SHOW_TRACEBACK = True
1010
# OpenAI GPT
1111
# ----------
1212
response=$(
13-
1413
llm prompt --model gpt-4.1 --option temperature 0.0 --no-stream \
1514
--fragment https://cdn.crate.io/about/v1/llms-full.txt \
1615
--system-fragment https://cdn.crate.io/about/v1/instructions-general.md \
@@ -24,11 +23,26 @@ assert "UUIDv7" in response, "GPT: UUIDv7 was not in response"
2423
# Anthropic Claude Sonnet
2524
# -----------------------
2625
response=$(
27-
2826
llm prompt --model claude-4-sonnet --option temperature 0.0 --no-stream \
2927
--fragment https://cdn.crate.io/about/v1/llms-full.txt \
3028
--system-fragment https://cdn.crate.io/about/v1/instructions-general.md \
3129
"CrateDB does not seem to provide an AUTOINCREMENT feature?"
3230
)
3331
print(response)
3432
assert "UUIDv7" in response, "Sonnet: UUIDv7 was not in response"
33+
34+
35+
# ------------
36+
# Google Gemma
37+
# ------------
38+
# - Gemma3 works well for basic Text-to-SQL.
39+
if False:
40+
$OLLAMA_HOST="http://100.127.86.113:11434/"
41+
response=$(
42+
llm prompt --model gemma3:1b --option temperature 0.0 --no-stream \
43+
--fragment sql-request.txt \
44+
--system "Table 'time_series_data' has columns: timestamp (TIMESTAMP), value (DOUBLE PRECISION), location (VARCHAR), sensor_id (INTEGER)" \
45+
"Question: What is the average value for sensor 1?"
46+
)
47+
print(response)
48+
assert "SQLQuery: SELECT AVG(value) FROM time_series_data WHERE sensor_id = 1" in response

0 commit comments

Comments
 (0)