Commit
·
ef0ee7c
1
Parent(s):
bebdc42
refactor: replace .getenv with .environ
Browse files- app.py +6 -6
- langchain_mcp_client.py +6 -6
- postgre_mcp_server.py +9 -9
app.py
CHANGED
|
@@ -10,11 +10,11 @@ import base64
|
|
| 10 |
from memory_store import MemoryStore
|
| 11 |
import logging
|
| 12 |
|
| 13 |
-
load_dotenv()
|
| 14 |
-
dsn = os.
|
| 15 |
-
schema = os.
|
| 16 |
-
|
| 17 |
-
print("DEBUG: DB_URL =", os.
|
| 18 |
|
| 19 |
# ======================================= Load DB configs
|
| 20 |
def load_db_configs():
|
|
@@ -45,7 +45,7 @@ async def run_agent(request, history=None):
|
|
| 45 |
# Handle image processing
|
| 46 |
image_path = ""
|
| 47 |
load_dotenv()
|
| 48 |
-
PANDAS_EXPORTS_PATH = os.
|
| 49 |
|
| 50 |
# Ensure the exports directory exists
|
| 51 |
os.makedirs(PANDAS_EXPORTS_PATH, exist_ok=True)
|
|
|
|
| 10 |
from memory_store import MemoryStore
|
| 11 |
import logging
|
| 12 |
|
| 13 |
+
# load_dotenv()
|
| 14 |
+
# dsn = os.environ["DB_URL"]
|
| 15 |
+
# schema = os.environ["DB_SCHEMA"]
|
| 16 |
+
#
|
| 17 |
+
# print("DEBUG: DB_URL =", os.environ["DB_URL"])
|
| 18 |
|
| 19 |
# ======================================= Load DB configs
|
| 20 |
def load_db_configs():
|
|
|
|
| 45 |
# Handle image processing
|
| 46 |
image_path = ""
|
| 47 |
load_dotenv()
|
| 48 |
+
PANDAS_EXPORTS_PATH = os.environ["PANDAS_EXPORTS_PATH"]
|
| 49 |
|
| 50 |
# Ensure the exports directory exists
|
| 51 |
os.makedirs(PANDAS_EXPORTS_PATH, exist_ok=True)
|
langchain_mcp_client.py
CHANGED
|
@@ -39,16 +39,16 @@ async def lc_mcp_exec(request: str, history=None) -> Tuple[str, list]:
|
|
| 39 |
|
| 40 |
# Initialize the LLM for OpenAI
|
| 41 |
# llm = init_chat_model(
|
| 42 |
-
# model_provider=os.
|
| 43 |
-
# model=os.
|
| 44 |
-
# api_key=os.
|
| 45 |
# )
|
| 46 |
|
| 47 |
# Initialize the LLM for Gemini
|
| 48 |
llm = init_chat_model(
|
| 49 |
-
model_provider=os.
|
| 50 |
-
model=os.
|
| 51 |
-
api_key=os.
|
| 52 |
)
|
| 53 |
|
| 54 |
# Initialize the MCP client
|
|
|
|
| 39 |
|
| 40 |
# Initialize the LLM for OpenAI
|
| 41 |
# llm = init_chat_model(
|
| 42 |
+
# model_provider=os.environ["OPENAI_MODEL_PROVIDER"],
|
| 43 |
+
# model=os.environ["OPENAI_MODEL"],
|
| 44 |
+
# api_key=os.environ["OPENAI_API_KEY"]
|
| 45 |
# )
|
| 46 |
|
| 47 |
# Initialize the LLM for Gemini
|
| 48 |
llm = init_chat_model(
|
| 49 |
+
model_provider=os.environ["GEMINI_MODEL_PROVIDER"],
|
| 50 |
+
model=os.environ["GEMINI_MODEL"],
|
| 51 |
+
api_key=os.environ["GEMINI_API_KEY"]
|
| 52 |
)
|
| 53 |
|
| 54 |
# Initialize the MCP client
|
postgre_mcp_server.py
CHANGED
|
@@ -40,10 +40,10 @@ async def db_lifespan(server: FastMCP) -> AsyncIterator[DbContext]:
|
|
| 40 |
"""Manage database connection lifecycle"""
|
| 41 |
# Initialize DB connection from environment variables
|
| 42 |
load_dotenv()
|
| 43 |
-
dsn = os.
|
| 44 |
-
schema = os.
|
| 45 |
|
| 46 |
-
print("DEBUG: DB_URL =", os.
|
| 47 |
|
| 48 |
pool = await asyncpg.create_pool(
|
| 49 |
dsn,
|
|
@@ -327,7 +327,7 @@ async def list_tables() -> str:
|
|
| 327 |
async def get_table_schema(table_name: str) -> str:
|
| 328 |
"""Get schema information for a specific table"""
|
| 329 |
try:
|
| 330 |
-
schema = os.
|
| 331 |
|
| 332 |
async with db_lifespan(mcp) as db_ctx:
|
| 333 |
columns = await get_table_schema_info(db_ctx.pool, schema, table_name)
|
|
@@ -350,7 +350,7 @@ def get_foreign_keys(table_name: str) -> str:
|
|
| 350 |
table_name: The name of the table to get foreign keys from
|
| 351 |
schema: The schema name (defaults to 'public')
|
| 352 |
"""
|
| 353 |
-
schema = os.
|
| 354 |
|
| 355 |
sql = """
|
| 356 |
SELECT
|
|
@@ -380,7 +380,7 @@ def get_foreign_keys(table_name: str) -> str:
|
|
| 380 |
async def get_all_schemas() -> str:
|
| 381 |
"""Get schema information for all tables in the database"""
|
| 382 |
try:
|
| 383 |
-
schema = os.
|
| 384 |
|
| 385 |
async with db_lifespan(mcp) as db_ctx:
|
| 386 |
tables = await get_all_tables(db_ctx.pool, db_ctx.schema)
|
|
@@ -450,7 +450,7 @@ async def generate_analytical_query(table_name: str) -> list[PromptMessage]:
|
|
| 450 |
table_name: The name of the table to generate analytical queries for
|
| 451 |
"""
|
| 452 |
load_dotenv()
|
| 453 |
-
schema = os.
|
| 454 |
try:
|
| 455 |
async with db_lifespan(mcp) as db_ctx:
|
| 456 |
pool = db_ctx.pool
|
|
@@ -631,14 +631,14 @@ async def visualize_results(json_data: dict, vis_prompt: str) -> str:
|
|
| 631 |
|
| 632 |
# Load api key
|
| 633 |
load_dotenv()
|
| 634 |
-
api_key = os.environ
|
| 635 |
pai.api_key.set(api_key)
|
| 636 |
|
| 637 |
# Generate visualization
|
| 638 |
df_ai.chat(vis_prompt)
|
| 639 |
|
| 640 |
# Get the visualization path
|
| 641 |
-
PANDAS_EXPORTS_PATH = os.
|
| 642 |
generated_files = [f for f in os.listdir(PANDAS_EXPORTS_PATH) if f.startswith("temp_chart")]
|
| 643 |
if generated_files:
|
| 644 |
visualization_path = os.path.join(PANDAS_EXPORTS_PATH, generated_files[0])
|
|
|
|
| 40 |
"""Manage database connection lifecycle"""
|
| 41 |
# Initialize DB connection from environment variables
|
| 42 |
load_dotenv()
|
| 43 |
+
dsn = os.environ["DB_URL"]
|
| 44 |
+
schema = os.environ["DB_SCHEMA"]
|
| 45 |
|
| 46 |
+
print("DEBUG: DB_URL =", os.environ["DB_URL"])
|
| 47 |
|
| 48 |
pool = await asyncpg.create_pool(
|
| 49 |
dsn,
|
|
|
|
| 327 |
async def get_table_schema(table_name: str) -> str:
|
| 328 |
"""Get schema information for a specific table"""
|
| 329 |
try:
|
| 330 |
+
schema = os.environ["DB_SCHEMA"]
|
| 331 |
|
| 332 |
async with db_lifespan(mcp) as db_ctx:
|
| 333 |
columns = await get_table_schema_info(db_ctx.pool, schema, table_name)
|
|
|
|
| 350 |
table_name: The name of the table to get foreign keys from
|
| 351 |
schema: The schema name (defaults to 'public')
|
| 352 |
"""
|
| 353 |
+
schema = os.environ["DB_SCHEMA"]
|
| 354 |
|
| 355 |
sql = """
|
| 356 |
SELECT
|
|
|
|
| 380 |
async def get_all_schemas() -> str:
|
| 381 |
"""Get schema information for all tables in the database"""
|
| 382 |
try:
|
| 383 |
+
schema = os.environ["DB_SCHEMA"]
|
| 384 |
|
| 385 |
async with db_lifespan(mcp) as db_ctx:
|
| 386 |
tables = await get_all_tables(db_ctx.pool, db_ctx.schema)
|
|
|
|
| 450 |
table_name: The name of the table to generate analytical queries for
|
| 451 |
"""
|
| 452 |
load_dotenv()
|
| 453 |
+
schema = os.environ["DB_SCHEMA"]
|
| 454 |
try:
|
| 455 |
async with db_lifespan(mcp) as db_ctx:
|
| 456 |
pool = db_ctx.pool
|
|
|
|
| 631 |
|
| 632 |
# Load api key
|
| 633 |
load_dotenv()
|
| 634 |
+
api_key = os.environ["PANDAS_KEY"]
|
| 635 |
pai.api_key.set(api_key)
|
| 636 |
|
| 637 |
# Generate visualization
|
| 638 |
df_ai.chat(vis_prompt)
|
| 639 |
|
| 640 |
# Get the visualization path
|
| 641 |
+
PANDAS_EXPORTS_PATH = os.environ["PANDAS_EXPORTS_PATH"]
|
| 642 |
generated_files = [f for f in os.listdir(PANDAS_EXPORTS_PATH) if f.startswith("temp_chart")]
|
| 643 |
if generated_files:
|
| 644 |
visualization_path = os.path.join(PANDAS_EXPORTS_PATH, generated_files[0])
|