Spaces:
Sleeping
Sleeping
| 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) | |