use local connection only
Browse files- app/app.py +3 -14
app/app.py
CHANGED
@@ -538,17 +538,6 @@ def get_pmtiles_style_llm(paint, ids):
|
|
538 |
|
539 |
##### Chatbot stuff
|
540 |
|
541 |
-
|
542 |
-
# create sharable low-level connection, see: https://github.com/Mause/duckdb_engine
|
543 |
-
import sqlalchemy
|
544 |
-
|
545 |
-
connect_args = {'preload_extensions':['spatial']}
|
546 |
-
eng = sqlalchemy.create_engine("duckdb:///:memory:",connect_args = connect_args)
|
547 |
-
|
548 |
-
# ibis can talk to this connection and create the VIEW
|
549 |
-
con = ibis.duckdb.from_connection(eng.raw_connection())
|
550 |
-
tbl = con.read_parquet(ca_parquet, "mydata")
|
551 |
-
|
552 |
# langchain can also talk to this connection and see the table:
|
553 |
from langchain_community.utilities import SQLDatabase
|
554 |
db = SQLDatabase(eng, view_support=True)
|
@@ -710,8 +699,8 @@ from langchain_openai import ChatOpenAI
|
|
710 |
|
711 |
llm = ChatOpenAI(model="gpt-4", temperature=0)
|
712 |
|
713 |
-
managers =
|
714 |
-
names =
|
715 |
|
716 |
from langchain_core.prompts import ChatPromptTemplate
|
717 |
prompt = ChatPromptTemplate.from_messages([
|
@@ -740,7 +729,7 @@ def run_sql(query,color_choice):
|
|
740 |
return pd.DataFrame({'id' : []})
|
741 |
|
742 |
|
743 |
-
result =
|
744 |
if result.empty :
|
745 |
explanation = "This query did not return any results. Please try again with a different query."
|
746 |
st.warning(explanation, icon="⚠️")
|
|
|
538 |
|
539 |
##### Chatbot stuff
|
540 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
# langchain can also talk to this connection and see the table:
|
542 |
from langchain_community.utilities import SQLDatabase
|
543 |
db = SQLDatabase(eng, view_support=True)
|
|
|
699 |
|
700 |
llm = ChatOpenAI(model="gpt-4", temperature=0)
|
701 |
|
702 |
+
managers = ca.sql("SELECT DISTINCT manager FROM mydata;").execute()
|
703 |
+
names = ca.sql("SELECT name FROM mydata GROUP BY name HAVING SUM(acres) >10000;").execute()
|
704 |
|
705 |
from langchain_core.prompts import ChatPromptTemplate
|
706 |
prompt = ChatPromptTemplate.from_messages([
|
|
|
729 |
return pd.DataFrame({'id' : []})
|
730 |
|
731 |
|
732 |
+
result = ca.sql(sql_query).execute()
|
733 |
if result.empty :
|
734 |
explanation = "This query did not return any results. Please try again with a different query."
|
735 |
st.warning(explanation, icon="⚠️")
|