1414@pytest .fixture
1515def provision_db (cratedb ):
1616 sql_ddl = """
17- CREATE TABLE IF NOT EXISTS time_series_data (
17+ CREATE TABLE IF NOT EXISTS testdrive. time_series_data (
1818 timestamp TIMESTAMP,
1919 value DOUBLE,
2020 location STRING,
2121 sensor_id INT
2222);
2323"""
2424 sql_dml = """
25- INSERT INTO time_series_data (timestamp, value, location, sensor_id)
25+ INSERT INTO testdrive. time_series_data (timestamp, value, location, sensor_id)
2626VALUES
2727 ('2023-09-14T00:00:00', 10.5, 'Sensor A', 1),
2828 ('2023-09-14T01:00:00', 15.2, 'Sensor A', 1),
@@ -42,14 +42,15 @@ def provision_db(cratedb):
4242
4343
4444@pytest .mark .skipif ("OPENAI_API_KEY" not in os .environ , reason = "OPENAI_API_KEY not set" )
45- def test_query_llm (cratedb , provision_db ):
45+ def test_query_nlsql_openai (cratedb , provision_db ):
4646 """
47- Verify `ctk query nlsql ...`.
47+ Verify `ctk query nlsql ...` with Open AI .
4848 """
4949
5050 runner = CliRunner (
5151 env = {
5252 "CRATEDB_CLUSTER_URL" : cratedb .get_connection_url (),
53+ "CRATEDB_SCHEMA" : "testdrive" ,
5354 "LLM_PROVIDER" : "openai" ,
5455 }
5556 )
@@ -64,3 +65,29 @@ def test_query_llm(cratedb, provision_db):
6465 output = json .loads (result .output )
6566 assert output ["answer" ] == "The average value for sensor 1 is approximately 17.03."
6667 assert output ["sql_query" ] == "SELECT AVG(value) FROM time_series_data WHERE sensor_id = 1"
68+
69+
70+ @pytest .mark .skipif ("ANTHROPIC_API_KEY" not in os .environ , reason = "ANTHROPIC_API_KEY not set" )
71+ def test_query_nlsql_anthropic (cratedb , provision_db ):
72+ """
73+ Verify `ctk query nlsql ...` with Anthropic.
74+ """
75+
76+ runner = CliRunner (
77+ env = {
78+ "CRATEDB_CLUSTER_URL" : cratedb .get_connection_url (),
79+ "CRATEDB_SCHEMA" : "testdrive" ,
80+ "LLM_PROVIDER" : "anthropic" ,
81+ }
82+ )
83+
84+ result = runner .invoke (
85+ cli ,
86+ input = "What is the average value for sensor 1?" ,
87+ args = "nlsql -" ,
88+ catch_exceptions = False ,
89+ )
90+ assert result .exit_code == 0 , result .output
91+ output = json .loads (result .output )
92+ assert "the average value for sensor 1 is approximately **17.03**" in output ["answer" ]
93+ assert output ["sql_query" ] == "SELECT AVG(value) as average_value FROM time_series_data WHERE sensor_id = 1;"
0 commit comments