Skip to content

Commit

Permalink
Merge pull request #3 from musketeers-br/example-selector
Browse files Browse the repository at this point in the history
Example selector
  • Loading branch information
jrpereirajr authored Aug 16, 2024
2 parents d1373b9 + 333a68c commit 85fbd94
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 95 deletions.
1 change: 1 addition & 0 deletions App.Installer.cls
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ XData setup
<Manifest>
<Default Name="Namespace" Value="IRISAPP"/>
<Default Name="database" Value="irisapp"/>
<Default Name="app" Value="irisapp"/>

<Namespace Name="${Namespace}" Code="${Namespace}-CODE" Data="${Namespace}-DATA" Create="yes" Ensemble="1">
<Configuration>
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ $ docker-compose up -d
4. Write SQL queries in the editor or chat window.
5. Click "Execute" to run queries and see results.

Some prompts you can try:

- For 'Aviation' schema:
- what was the most deadly year?
- incident histogram by month/year
- For 'HoleFoods' schema:
- income by group
- most sold foods
- sales by product
- sales by product and category


## See in action

Expand Down
6 changes: 6 additions & 0 deletions iris.script
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
do $SYSTEM.OBJ.Load("/home/irisowner/dev/App.Installer.cls", "ck")
set sc = ##class(App.Installer).setup()

// Change to working namespace
zn "IRISAPP"

// Creates and populates the examples table
Do ##class(%SYSTEM.SQL.Schema).ImportDDL("/home/irisowner/dev/sql/init.sql", "/tmp/log-sql.txt")

// Create /_vscode web app to support intersystems-community.testingmanager VS Code extension
zpm "install vscode-per-namespace-settings"
// Sample databases
zpm "install samples-aviation"
zpm "install samples-bi"

// Configure %UnitTest in IRISAPP to suit the VS Code extension
set ^UnitTestRoot="/usr/irissys/.vscode/IRISAPP/UnitTestRoot"
Expand Down
23 changes: 16 additions & 7 deletions python/sqlzilla/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
st.session_state.query_result = None
if 'code_text' not in st.session_state:
st.session_state.code_text = ''
if 'prompt' not in st.session_state:
st.session_state.prompt = ''

def db_connection_str():
user = st.session_state.user
Expand Down Expand Up @@ -96,6 +98,7 @@ def clean_response(response):
index=None,
placeholder="Select database schema...",
)
sqlzilla.schema_name = database_schema
except:
database_schema = st.text_input('Enter Database Schema')
st.warning('Was not possible to retrieve database schemas. Please provide it manually.')
Expand All @@ -120,11 +123,18 @@ def clean_response(response):

if editor_dict['type'] == "submit":
st.session_state.code_text = editor_dict['text']
data = sqlzilla.execute_query(st.session_state.code_text)
# Display query result as dataframe
if (data is not None):
st.session_state.query_result = pd.DataFrame(data)
st.dataframe(st.session_state.query_result)
try:
data = sqlzilla.execute_query(st.session_state.code_text)
# Display query result as dataframe
if (data is not None):
st.session_state.query_result = pd.DataFrame(data)
st.dataframe(st.session_state.query_result)
except Exception as e:
st.error(e)

if st.button("Save on library"):
sqlzilla.add_example(st.session_state.prompt, st.session_state.code_text)
st.success("Saved on library!")

with col2:
# Display chat history
Expand All @@ -133,6 +143,7 @@ def clean_response(response):

# React to user input
if prompt := st.chat_input("How can I assist you?"):
st.session_state.prompt = prompt
# Display user message in chat message container
st.chat_message("user").markdown(prompt)
# Add user message to chat history
Expand All @@ -145,8 +156,6 @@ def clean_response(response):
st.session_state.query = response
st.session_state.code_text = response
editor_dict['text'] = response
data = sqlzilla.execute_query(st.session_state.code_text)
st.session_state.query_result = pd.DataFrame(data)
st.rerun()
# Display assistant response in chat message container
with st.chat_message("assistant"):
Expand Down
Loading

0 comments on commit 85fbd94

Please sign in to comment.