# app.py from fastapi import FastAPI from pydantic import BaseModel import os import openai app = FastAPI() # Environment Variables GROQ_API_KEY = os.environ.get("GROQ_API_KEY") # Model Setup def generate_response(system_prompt: str, user_message: str): client = openai.OpenAI(api_key=GROQ_API_KEY, base_url="https://api.groq.com/openai/v1") response = client.chat.completions.create( model="mixtral-8x7b-32768", messages=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_message} ], temperature=0.4 ) return response.choices[0].message.content # Request model class Message(BaseModel): message: str @app.post("/bia/threat-assessment") def bia_threat_assessment(req: Message): prompt = """ You are a cybersecurity and geopolitical risk analyst AI working on Business Impact Assessment (BIA). Given a paragraph, do the following: 1. Identify the **place** mentioned in the text. 2. List likely **threats** specific to that place and context. 3. For each threat: - Give a **likelihood rating (1–5)**. - Give a **severity rating (1–5)**. - Describe the **potential impact**. - Compute **threat rating = likelihood × severity**. Respond strictly in this JSON format: { "place": "", "threats": [ { "name": "", "likelihood": <1-5>, "severity": <1-5>, "impact": "", "threat_rating": } ] } """ result = generate_response(prompt, req.message) return result @app.post("/bia/impact-analysis") def bia_impact_analysis(req: Message): return { "status": "placeholder", "note": "This endpoint is reserved for BIA impact analysis logic." }