Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Application Settings
APP_NAME=InPactAI


GEMINI_API_KEY=your-gemini-api-key-here
# Supabase Configuration
SUPABASE_URL=https://yoursupabaseurl.supabase.co
SUPABASE_KEY=your-supabase-anon-key-here
Expand Down
39 changes: 39 additions & 0 deletions backend/app/api/routes/gemini_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import httpx
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from app.core.config import settings







router = APIRouter()
GEMINI_API_KEY = settings.gemini_api_key
GEMINI_API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent"

class GenerateRequest(BaseModel):
prompt: str

@router.post("/generate")
async def generate_content(request: GenerateRequest):
if not GEMINI_API_KEY:
raise HTTPException(status_code=500, detail="Gemini API is not configured. Please set GEMINI_API_KEY in environment.")
payload = {
"contents": [{"role": "user", "parts": [{"text": request.prompt}]}]
}
headers = {
"Content-Type": "application/json",
}
params = {"key": GEMINI_API_KEY}
try:
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.post(GEMINI_API_URL, json=payload, headers=headers, params=params)
response.raise_for_status()
return response.json()
except httpx.RequestError as e:
raise HTTPException(status_code=502, detail=f"Gemini API error: {str(e)}")
except httpx.HTTPStatusError as e:
raise HTTPException(status_code=502, detail=f"Gemini API error: {str(e)}")
1 change: 1 addition & 0 deletions backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Settings(BaseSettings):
# AI Configuration
ai_api_key: Optional[str] = None
groq_api_key: Optional[str] = None
gemini_api_key: Optional[str] = None

# CORS Configuration
allowed_origins: str = "http://localhost:3000"
Expand Down
4 changes: 2 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app.api.routes import health
from app.services.supabase_client import supabase
from app.api.routes import auth

from app.api.routes import gemini_generate
app = FastAPI(title="Inpact Backend", version="0.1.0")

# Verify Supabase client initialization on startup
Expand All @@ -27,7 +27,7 @@
allow_methods=["*"],
allow_headers=["*"],
)

app.include_router(gemini_generate.router)
app.include_router(health.router)
app.include_router(auth.router)

Expand Down
4 changes: 4 additions & 0 deletions backend/env_example
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ DATABASE_URL=postgresql://postgres.your-project-ref:[YOUR-PASSWORD]@aws-0-region
GROQ_API_KEY=your-groq-api-key
AI_API_KEY=your-openai-api-key-optional

# Gemini API Key (Optional)

GEMINI_API_KEY=your-gemini-api-key-here

# CORS Origins (comma-separated)

ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pydantic==2.12.3
pydantic-settings>=2.0.3
pydantic_core==2.41.4
python-dotenv==1.2.1
pytokens==0.2.0
httpx
ruff==0.14.3
sniffio==1.3.1
starlette==0.49.1
Expand Down
23 changes: 23 additions & 0 deletions frontend/lib/geminiApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Gemini text generation API integration
// Calls backend /generate endpoint securely
export async function generateGeminiText(prompt: string): Promise<any> {
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
if (!apiUrl) {
throw new Error("NEXT_PUBLIC_API_URL is not set in environment.");
}
try {
const res = await fetch(`${apiUrl}/generate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ prompt }),
});
if (!res.ok) {
throw new Error(`Backend error: ${res.status} ${res.statusText}`);
}
return await res.json();
} catch (err: any) {
throw new Error(`Gemini API call failed: ${err.message}`);
}
}
Loading