Skip to content

Commit

Permalink
backwards compatibility with manual installs
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpfeiffer committed Jun 30, 2024
1 parent b5f8ca6 commit fef692a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
9 changes: 5 additions & 4 deletions viz/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ COPY . .

EXPOSE 5000

ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
OPENAI_KEY=${OPENAI_KEY}

CMD ["python3", "-m", "flask", "--app", "server.py", "run", "--host=0.0.0.0"]
ENV OPENAI_KEY=${OPENAI_KEY} \
POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
POSTGRES_DB=${POSTGRES_DB}

CMD ["python3", "-m", "flask", "--app", "server.py", "run", "--host=0.0.0.0"]
13 changes: 10 additions & 3 deletions viz/backend/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import os

database_name = "postgres"
sql_key = os.getenv("POSTGRES_PASSWORD")
openai_key = os.getenv("OPENAI_KEY")
sql_key = "YOUR_DATABASE_PASSWORD"
database_name = "YOUR_DATABASE_NAME"
openai_key = "YOUR_OPENAI_KEY"

try:
sql_key = os.getenv("POSTGRES_PASSWORD")
database_name = os.getenv("POSTGRES_DB")
openai_key = os.getenv("OPENAI_KEY")
except:
pass
19 changes: 15 additions & 4 deletions viz/backend/sqlchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@
from langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate
import sqlalchemy as sqldb
from sqlalchemy import text
from sqlalchemy.exc import OperationalError
from geoalchemy2 import Geometry


def sqlchain(input_text):
llm = ChatOpenAI(openai_api_key=config.openai_key,
model_name="gpt-3.5-turbo", temperature=0, verbose=True)
db = SQLDatabase.from_uri(
f"postgresql+psycopg2://postgres:{config.sql_key}@database:5432/{config.database_name}")
mydb = sqldb.create_engine(
f"postgresql+psycopg2://postgres:{config.sql_key}@database:5432/{config.database_name}")

# Manual installation
try:
db = SQLDatabase.from_uri(
f"postgresql+psycopg2://postgres:{config.sql_key}@localhost:5432/{config.database_name}")
mydb = sqldb.create_engine(
f"postgresql+psycopg2://postgres:{config.sql_key}@localhost:5432/{config.database_name}")
# Docker installation
except OperationalError as op_err:
db = SQLDatabase.from_uri(
f"postgresql+psycopg2://postgres:{config.sql_key}@database:5432/{config.database_name}")
mydb = sqldb.create_engine(
f"postgresql+psycopg2://postgres:{config.sql_key}@database:5432/{config.database_name}")

myconnection = mydb.connect()

_CUSTOMIZE__TEMPLATE = """You are a PostgreSQL expert. Given an input question, first create a syntactically correct PostgreSQL query to run then look at the results of the query and return the answer to the input question.
Expand Down
2 changes: 2 additions & 0 deletions viz/setup.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Edit these variables to connect with the ChatGPT API and improve your database security.

OPENAI_KEY=YOUR_OPENAI_API_KEY_HERE

POSTGRES_PASSWORD=CHANGEME
POSTGRES_DB=postgres

PGADMIN_DEFAULT_EMAIL=[email protected]
PGADMIN_DEFAULT_PASSWORD=CHANGEME

0 comments on commit fef692a

Please sign in to comment.