forked from llmware-ai/llmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text2sql-getting-started-1.py
53 lines (28 loc) · 1.55 KB
/
text2sql-getting-started-1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
""" This 'getting started' example shows the basics of how to start using text2sql model:
1. Loading "slim-sql-tool" and running initial tests to confirm installation.
2. 'Hello World' demonstration of how to 'package' a text2sql prompt combining a
natural language query with a SQL table schema and run a basic inference to generate SQL output
"""
from llmware.agents import LLMfx
from llmware.models import ModelCatalog
def load_slim_sql_tool():
""" First step is to install the slim-sql-tool locally """
# to cache locally the slim-sql-tool with config and test files
ModelCatalog().get_llm_toolkit(["sql"])
# to run tests to confirm correct installation and see the model in action
# note: the test results will include some minor errors - useful to learn how to sharpen prompts
ModelCatalog().tool_test_run("slim-sql-tool")
return 0
def hello_world_text_2_sql():
""" Illustrates a 'hello world' text-2-sql inference as part of an agent process. """
sample_table_schema = "CREATE TABLE customer_info (customer_name text, account_number integer, annual_spend integer)"
query = "What are the names of all customers with annual spend greater than $1000?"
agent = LLMfx(verbose=True)
response = agent.sql(query, sample_table_schema)
print("update: text-2-sql response - ", response)
return response
if __name__ == "__main__":
# first - load and test the tools
load_slim_sql_tool()
# second - 'hello world' demo of using text2sql model
hello_world_text_2_sql()