fix: Resolve environment variable initialization order and load-time API key requirement
Browse files
agents.py
CHANGED
|
@@ -4,10 +4,15 @@ from langchain_google_genai import ChatGoogleGenerativeAI
|
|
| 4 |
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
from langchain_core.output_parsers import StrOutputParser
|
| 6 |
from tools import web_search, scrape_url
|
|
|
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
load_dotenv() # Load environment variables from .env file
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
#Model Setup
|
| 12 |
llm= ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0)
|
| 13 |
|
|
|
|
| 4 |
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
from langchain_core.output_parsers import StrOutputParser
|
| 6 |
from tools import web_search, scrape_url
|
| 7 |
+
import os
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
|
| 10 |
load_dotenv() # Load environment variables from .env file
|
| 11 |
|
| 12 |
+
# Map Gemini_API_KEY to GOOGLE_API_KEY for LangChain if necessary
|
| 13 |
+
if "Gemini_API_KEY" in os.environ and "GOOGLE_API_KEY" not in os.environ:
|
| 14 |
+
os.environ["GOOGLE_API_KEY"] = os.environ["Gemini_API_KEY"]
|
| 15 |
+
|
| 16 |
#Model Setup
|
| 17 |
llm= ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0)
|
| 18 |
|
main.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from pydantic import BaseModel
|
| 5 |
-
from pipeline import run_research_pipeline
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
|
| 8 |
load_dotenv()
|
|
@@ -11,6 +10,8 @@ load_dotenv()
|
|
| 11 |
if "Gemini_API_KEY" in os.environ and "GOOGLE_API_KEY" not in os.environ:
|
| 12 |
os.environ["GOOGLE_API_KEY"] = os.environ["Gemini_API_KEY"]
|
| 13 |
|
|
|
|
|
|
|
| 14 |
app = FastAPI(
|
| 15 |
title="Multi-Agent RAG System API",
|
| 16 |
description="REST API for the multi-agent research pipeline.",
|
|
|
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from pydantic import BaseModel
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
|
| 7 |
load_dotenv()
|
|
|
|
| 10 |
if "Gemini_API_KEY" in os.environ and "GOOGLE_API_KEY" not in os.environ:
|
| 11 |
os.environ["GOOGLE_API_KEY"] = os.environ["Gemini_API_KEY"]
|
| 12 |
|
| 13 |
+
from pipeline import run_research_pipeline
|
| 14 |
+
|
| 15 |
app = FastAPI(
|
| 16 |
title="Multi-Agent RAG System API",
|
| 17 |
description="REST API for the multi-agent research pipeline.",
|