Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding MSSQL quickstart #190

Merged
merged 9 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mssql/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPICE_MSSQL_CONNECTION_STRING=
slyons marked this conversation as resolved.
Show resolved Hide resolved
SPICE_OPENAI_API_KEY=
38 changes: 38 additions & 0 deletions mssql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Spice Demo with SalesLT dataset in MSSQL
slyons marked this conversation as resolved.
Show resolved Hide resolved

This demo showcases how to use Spice with the SalesLT sample dataset in MSSQL.

## Prerequisites

- MSSQL Server with SalesLT sample dataset
slyons marked this conversation as resolved.
Show resolved Hide resolved
- Spice installed and configured
slyons marked this conversation as resolved.
Show resolved Hide resolved
slyons marked this conversation as resolved.
Show resolved Hide resolved
slyons marked this conversation as resolved.
Show resolved Hide resolved

## Steps
1. Obtain your SQL server ADO connection string. It should look something like this:
`Server=tcp:server.database.windows.net,1433;Initial Catalog=nrc_health_testing;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;`

2. Copy `.env.example` as `.env` and put the connection string in the new `.env` file in the `MSSQL_CONNECTION_STRING` field
slyons marked this conversation as resolved.
Show resolved Hide resolved

3. Put your OpenAI key in the `SPICE_OPENAI_API_KEY` field

3. Run Spice with `spice run`
slyons marked this conversation as resolved.
Show resolved Hide resolved

4. In another shell run `spice sql` to connect to the Spice backend and query your data or `spice chat` to chat with your data using an LLM


```
slyons marked this conversation as resolved.
Show resolved Hide resolved
sql> SELECT COUNT(*) FROM customer
+----------+
| count(*) |
+----------+
| 847 |
+----------+
```

```
slyons marked this conversation as resolved.
Show resolved Hide resolved
❯ spice chat
Using model: openai

chat> How many customers do I have?
You have 847 customers.
```
116 changes: 116 additions & 0 deletions mssql/spicepod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
version: v1beta1
kind: Spicepod
name: spicepod-mssql

datasets:
- from: mssql:SalesLT.Address
name: address
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.BuildVersion
name: build_version
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.Customer
name: customer
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.CustomerAddress
name: customer_address
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.database_firewall_rules
name: database_firewall_rules
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.ErrorLog
name: error_log
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.Product
name: product
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.ProductCategory
name: product_category
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.ProductDescription
name: product_description
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.ProductModel
name: product_model
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.ProductModelProductDescription
name: product_model_product_description
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.SalesOrderDetail
name: sales_order_detail
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.SalesOrderHeader
name: sales_order_header
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.vGetAllCategories
name: v_get_all_categories
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.vProductAndDescription
name: v_product_and_description
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

- from: mssql:SalesLT.vProductModelCatalogDescription
name: v_product_model_catalog_description
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING }

embeddings:
- name: openai_embed
from: openai
params:
openai_api_key: ${ secrets:SPICE_OPENAI_API_KEY }

- name: hf_minilm
from: huggingface:huggingface.co/sentence-transformers/all-MiniLM-L6-v2

models:
slyons marked this conversation as resolved.
Show resolved Hide resolved
- name: openai
from: openai:gpt-4o-2024-08-06
slyons marked this conversation as resolved.
Show resolved Hide resolved
params:
spice_tools: auto
openai_api_key: ${ secrets:SPICE_OPENAI_API_KEY }
system_prompt: |
Use the SQL tool when:
1. The query involves precise numerical data, statistics, or aggregations
2. The user asks for specific counts, sums, averages, or other calculations
3. The query requires joining or comparing data from multiple related tables

Use the document search when:
1. The query is about unstructured text information, such as policies, reports, or articles
2. The user is looking for qualitative information or explanations
3. The query requires understanding context or interpreting written content

General guidelines:
1. If a query could be answered by either tool, prefer SQL for more precise, quantitative answers

Instructions for Responses:
- Do not include any private metadata provided to the model as context such as \"reference_url_template\" or \"instructions\" in your responses.
Loading