Name | llama-index-tools-waii JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | llama-index tools waii integration |
upload_time | 2025-07-30 20:54:35 |
maintainer | wangdatan |
docs_url | None |
author | None |
requires_python | <4.0,>=3.9 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Waii Tool
This tool connects to database connections managed by Waii, which allows generic SQL queries, do performance analyze, describe a SQL query, and more.
## Usage
First you need to create a waii.ai account, you request an account from [here](https://waii.ai/).
Initialize the tool with your account credentials:
```python
from llama_index.tools.waii import WaiiToolSpec
waii_tool = WaiiToolSpec(
url="https://tweakit.waii.ai/api/",
# API Key of Waii (not OpenAI API key)
api_key="...",
# Connection key of WAII connected database, see https://github.com/waii-ai/waii-sdk-py#get-connections
database_key="...",
)
```
## Tools
The tools available are:
- `get_answer`: Get answer to natural language question (which generate a SQL query, run it, explain the result)
- `describe_query`: Describe a SQL query
- `performance_analyze`: Analyze performance of a SQL query (by query_id)
- `diff_query`: Compare two SQL queries
- `describe_dataset`: Describe dataset, such as table, schema, etc.
- `transcode`: Transcode SQL query to another SQL dialect
- `get_semantic_contexts`: Get semantic contexts of a SQL query
- `generate_query_only`: Generate SQL query only (not run it)
- `run_query`: Run a SQL query
You can also load the data directly call `load_data`
## Examples
### Load data
```python
documents = waii_tool.load_data("Get all tables with their number of columns")
index = VectorStoreIndex.from_documents(documents).as_query_engine()
print(index.query("Which table contains most columns?"))
```
### Use as a Tool
#### Initialize the agent:
```python
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
agent = FunctionAgent(
tools=waii_tool.to_tool_list(), llm=OpenAI(model="gpt-4-1106-preview")
)
```
#### Ask simple question
```python
from llama_index.core.workflow import Context
ctx = Context(agent)
print(
await agent.run(
"Give me top 3 countries with the most number of car factory", ctx=ctx
)
)
print(
await agent.run("What are the car factories of these countries", ctx=ctx)
)
```
#### Do performance analyze
```python
from llama_index.core.workflow import Context
ctx = Context(agent)
print(
await agent.run(
"Give me top 3 longest running queries, and their duration.", ctx=ctx
)
)
print(await agent.run("analyze the 2nd-longest running query", ctx=ctx))
```
#### Diff two queries
```python
previous_query = """
SELECT
employee_id,
department,
salary,
AVG(salary) OVER (PARTITION BY department) AS department_avg_salary,
salary - AVG(salary) OVER (PARTITION BY department) AS diff_from_avg
FROM
employees;
"""
current_query = """
SELECT
employee_id,
department,
salary,
MAX(salary) OVER (PARTITION BY department) AS department_max_salary,
salary - AVG(salary) OVER (PARTITION BY department) AS diff_from_avg
FROM
employees;
LIMIT 100;
"""
print(
await agent.run(
f"tell me difference between {previous_query} and {current_query}",
ctx=ctx,
)
)
```
#### Describe dataset
```python
print(await agent.run("Summarize the dataset", ctx=ctx))
print(
await agent.run(
"Give me questions which I can ask about this dataset", ctx=ctx
)
)
```
#### Describe a query
```python
q = """
SELECT
employee_id,
department,
salary,
AVG(salary) OVER (PARTITION BY department) AS department_avg_salary,
salary - AVG(salary) OVER (PARTITION BY department) AS diff_from_avg
FROM
employees;
"""
print(await agent.run(f"what this query can do? {q}", ctx=ctx))
```
#### Migrate query to another dialect
```python
q = """
from pyspark.sql import SparkSession
from pyspark.sql.functions import avg, col
from pyspark.sql.window import Window
# Initialize Spark session
spark = SparkSession.builder.appName("example").getOrCreate()
# Assuming you have a DataFrame called 'employees'
# If not, you need to read your data into a DataFrame first
# Define window specification
windowSpec = Window.partitionBy("department")
# Perform the query
result = (employees
.select(
col("employee_id"),
col("department"),
col("salary"),
avg("salary").over(windowSpec).alias("department_avg_salary"),
(col("salary") - avg("salary").over(windowSpec)).alias("diff_from_avg")
))
# Show the result
result.show()
"""
print(
await agent.run(f"translate this pyspark query {q}, to Snowflake", ctx=ctx)
)
```
### Use Waii API directly
You can also use Waii API directly, see [here](https://github.com/waii-ai/waii-sdk-py)
Raw data
{
"_id": null,
"home_page": null,
"name": "llama-index-tools-waii",
"maintainer": "wangdatan",
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Your Name <you@example.com>",
"download_url": "https://files.pythonhosted.org/packages/34/ec/72bd1c25c574162fa34e73984e97dcdc36a1cce4ac324565b11e0be610bc/llama_index_tools_waii-0.4.0.tar.gz",
"platform": null,
"description": "# Waii Tool\n\nThis tool connects to database connections managed by Waii, which allows generic SQL queries, do performance analyze, describe a SQL query, and more.\n\n## Usage\n\nFirst you need to create a waii.ai account, you request an account from [here](https://waii.ai/).\n\nInitialize the tool with your account credentials:\n\n```python\nfrom llama_index.tools.waii import WaiiToolSpec\n\nwaii_tool = WaiiToolSpec(\n url=\"https://tweakit.waii.ai/api/\",\n # API Key of Waii (not OpenAI API key)\n api_key=\"...\",\n # Connection key of WAII connected database, see https://github.com/waii-ai/waii-sdk-py#get-connections\n database_key=\"...\",\n)\n```\n\n## Tools\n\nThe tools available are:\n\n- `get_answer`: Get answer to natural language question (which generate a SQL query, run it, explain the result)\n- `describe_query`: Describe a SQL query\n- `performance_analyze`: Analyze performance of a SQL query (by query_id)\n- `diff_query`: Compare two SQL queries\n- `describe_dataset`: Describe dataset, such as table, schema, etc.\n- `transcode`: Transcode SQL query to another SQL dialect\n- `get_semantic_contexts`: Get semantic contexts of a SQL query\n- `generate_query_only`: Generate SQL query only (not run it)\n- `run_query`: Run a SQL query\n\nYou can also load the data directly call `load_data`\n\n## Examples\n\n### Load data\n\n```python\ndocuments = waii_tool.load_data(\"Get all tables with their number of columns\")\nindex = VectorStoreIndex.from_documents(documents).as_query_engine()\n\nprint(index.query(\"Which table contains most columns?\"))\n```\n\n### Use as a Tool\n\n#### Initialize the agent:\n\n```python\nfrom llama_index.core.agent.workflow import FunctionAgent\nfrom llama_index.llms.openai import OpenAI\n\nagent = FunctionAgent(\n tools=waii_tool.to_tool_list(), llm=OpenAI(model=\"gpt-4-1106-preview\")\n)\n```\n\n#### Ask simple question\n\n```python\nfrom llama_index.core.workflow import Context\n\nctx = Context(agent)\n\nprint(\n await agent.run(\n \"Give me top 3 countries with the most number of car factory\", ctx=ctx\n )\n)\nprint(\n await agent.run(\"What are the car factories of these countries\", ctx=ctx)\n)\n```\n\n#### Do performance analyze\n\n```python\nfrom llama_index.core.workflow import Context\n\nctx = Context(agent)\n\nprint(\n await agent.run(\n \"Give me top 3 longest running queries, and their duration.\", ctx=ctx\n )\n)\nprint(await agent.run(\"analyze the 2nd-longest running query\", ctx=ctx))\n```\n\n#### Diff two queries\n\n```python\nprevious_query = \"\"\"\nSELECT\n employee_id,\n department,\n salary,\n AVG(salary) OVER (PARTITION BY department) AS department_avg_salary,\n salary - AVG(salary) OVER (PARTITION BY department) AS diff_from_avg\nFROM\n employees;\n\"\"\"\ncurrent_query = \"\"\"\nSELECT\n employee_id,\n department,\n salary,\n MAX(salary) OVER (PARTITION BY department) AS department_max_salary,\n salary - AVG(salary) OVER (PARTITION BY department) AS diff_from_avg\nFROM\n employees;\nLIMIT 100;\n\"\"\"\nprint(\n await agent.run(\n f\"tell me difference between {previous_query} and {current_query}\",\n ctx=ctx,\n )\n)\n```\n\n#### Describe dataset\n\n```python\nprint(await agent.run(\"Summarize the dataset\", ctx=ctx))\nprint(\n await agent.run(\n \"Give me questions which I can ask about this dataset\", ctx=ctx\n )\n)\n```\n\n#### Describe a query\n\n```python\nq = \"\"\"\nSELECT\n employee_id,\n department,\n salary,\n AVG(salary) OVER (PARTITION BY department) AS department_avg_salary,\n salary - AVG(salary) OVER (PARTITION BY department) AS diff_from_avg\nFROM\n employees;\n\"\"\"\nprint(await agent.run(f\"what this query can do? {q}\", ctx=ctx))\n```\n\n#### Migrate query to another dialect\n\n```python\nq = \"\"\"\nfrom pyspark.sql import SparkSession\nfrom pyspark.sql.functions import avg, col\nfrom pyspark.sql.window import Window\n\n# Initialize Spark session\nspark = SparkSession.builder.appName(\"example\").getOrCreate()\n\n# Assuming you have a DataFrame called 'employees'\n# If not, you need to read your data into a DataFrame first\n\n# Define window specification\nwindowSpec = Window.partitionBy(\"department\")\n\n# Perform the query\nresult = (employees\n .select(\n col(\"employee_id\"),\n col(\"department\"),\n col(\"salary\"),\n avg(\"salary\").over(windowSpec).alias(\"department_avg_salary\"),\n (col(\"salary\") - avg(\"salary\").over(windowSpec)).alias(\"diff_from_avg\")\n ))\n\n# Show the result\nresult.show()\n\"\"\"\nprint(\n await agent.run(f\"translate this pyspark query {q}, to Snowflake\", ctx=ctx)\n)\n```\n\n### Use Waii API directly\n\nYou can also use Waii API directly, see [here](https://github.com/waii-ai/waii-sdk-py)\n",
"bugtrack_url": null,
"license": null,
"summary": "llama-index tools waii integration",
"version": "0.4.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "21590afef41771be1f2ee6116dd690fac4a02cef45dc7e22bcf90e6a18db1f44",
"md5": "6f168781a8fd3660ff980b791853ebe9",
"sha256": "1d522c2384ae0d5265569b812f912810db237fb89d90c56c361c2e73bfbdf139"
},
"downloads": -1,
"filename": "llama_index_tools_waii-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f168781a8fd3660ff980b791853ebe9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 6288,
"upload_time": "2025-07-30T20:54:34",
"upload_time_iso_8601": "2025-07-30T20:54:34.997886Z",
"url": "https://files.pythonhosted.org/packages/21/59/0afef41771be1f2ee6116dd690fac4a02cef45dc7e22bcf90e6a18db1f44/llama_index_tools_waii-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "34ec72bd1c25c574162fa34e73984e97dcdc36a1cce4ac324565b11e0be610bc",
"md5": "28b59567944e3275d0f4b9e2ec888341",
"sha256": "acbfb925408c11bdacdc47ae483a03536d48b8c1287d0732bd39f182299d4864"
},
"downloads": -1,
"filename": "llama_index_tools_waii-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "28b59567944e3275d0f4b9e2ec888341",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 6643,
"upload_time": "2025-07-30T20:54:35",
"upload_time_iso_8601": "2025-07-30T20:54:35.827576Z",
"url": "https://files.pythonhosted.org/packages/34/ec/72bd1c25c574162fa34e73984e97dcdc36a1cce4ac324565b11e0be610bc/llama_index_tools_waii-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-30 20:54:35",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-tools-waii"
}