File size: 1,271 Bytes
19949cf
 
 
 
 
 
 
 
 
 
 
 
 
158b546
19949cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0afcef7
19949cf
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
import openai
import os

def summarize_cve(cve_data):
    """Generate CVE summary using OpenAI"""
    api_key = os.getenv('OPENAI_API_KEY')
    if not api_key:
        return "OPENAI_API_KEY environment variable required"
    
    # Extract basic information
    cve = cve_data['cve']
    description = cve['descriptions'][0]['value']
    
    
    cve_id = cve['id']
    prompt = f"Please provide a professional security analysis of this CVE vulnerability in English:\n\nCVE ID: {cve_id}\nDescription: {description}\n\nPlease provide:\n1. Vulnerability Summary\n2. Risk Assessment\n3. Recommended Mitigation Actions\n\nUse British English and security industry terminology."
    
    try:
        client = openai.OpenAI(api_key=api_key)
        response = client.chat.completions.create(
            model="gpt-4o-mini",
            messages=[{"role": "user", "content": prompt}],
            max_tokens=3000
        )
        return response.choices[0].message.content
    except Exception as e:
        return f"LLM error: {e}"

# Test
if __name__ == "__main__":
    from api_client import fetch_cve_simple
    cve_data = fetch_cve_simple("CVE-2021-44228")
    if cve_data:
        summary = summarize_cve(cve_data)
        print("AI Summary:")
        print(summary)