File size: 1,798 Bytes
cdf6424
7d876e9
6f5caa7
7d876e9
cdf6424
6f5caa7
 
5ae73e5
cdf6424
 
7d876e9
cdf6424
 
 
 
 
 
 
 
 
 
 
 
5ae73e5
cdf6424
 
 
d6e6a43
cdf6424
 
 
 
 
6f5caa7
cdf6424
 
 
 
 
 
 
6f5caa7
cdf6424
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f5caa7
cdf6424
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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": "<place>",
  "threats": [
    {
      "name": "<threat name>",
      "likelihood": <1-5>,
      "severity": <1-5>,
      "impact": "<impact statement>",
      "threat_rating": <likelihood * severity>
    }
  ]
}
"""
    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."
    }