AI-powered security analysis assistant.
| 32 | class SecurityCopilot: |
| 33 | """AI-powered security analysis assistant.""" |
| 34 | |
| 35 | def __init__( |
| 36 | self, |
| 37 | provider: str = "anthropic", |
| 38 | model: str | None = None, |
| 39 | api_key: str | None = None, |
| 40 | base_url: str | None = None, |
| 41 | ): |
| 42 | """Initialize Security Copilot. |
| 43 | |
| 44 | Args: |
| 45 | provider: LLM provider - "anthropic", "openai", "ollama", "ollama/<model>", |
| 46 | or model shortcuts like "qwen", "llama3", "mistral" |
| 47 | model: Model to use (defaults to provider's best) |
| 48 | api_key: API key (or use environment variable) |
| 49 | base_url: Base URL for API (for ollama or openai-compatible) |
| 50 | |
| 51 | Examples: |
| 52 | SecurityCopilot("anthropic") |
| 53 | SecurityCopilot("ollama", model="qwen2.5") |
| 54 | SecurityCopilot("ollama/llama3.2") |
| 55 | SecurityCopilot("qwen") # shortcut for ollama/qwen2.5 |
| 56 | SecurityCopilot("openai-compatible", base_url="http://localhost:8000/v1", model="my-model") |
| 57 | """ |
| 58 | self.logger = get_logger("ai.copilot") |
| 59 | self.provider = provider |
| 60 | self.correlator = FindingCorrelator() |
| 61 | |
| 62 | kwargs = {} |
| 63 | if api_key: |
| 64 | kwargs["api_key"] = api_key |
| 65 | if model: |
| 66 | kwargs["model"] = model |
| 67 | if base_url: |
| 68 | kwargs["base_url"] = base_url |
| 69 | |
| 70 | self._client: BaseLLMClient | None = None |
| 71 | self._client_kwargs = kwargs |
| 72 | |
| 73 | # Conversation history for context |
| 74 | self.conversation: list[Message] = [] |
| 75 | self.scan_context: list[ScanResult] = [] |
| 76 | self.correlation_report: CorrelationReport | None = None |
| 77 | |
| 78 | def _get_client(self) -> BaseLLMClient: |
| 79 | """Lazy load LLM client.""" |
| 80 | if self._client is None: |
| 81 | self._client = get_llm_client(self.provider, **self._client_kwargs) |
| 82 | return self._client |
| 83 | |
| 84 | def load_scan_results(self, results: list[ScanResult]) -> CorrelationReport: |
| 85 | """Load scan results into copilot context. |
| 86 | |
| 87 | Args: |
| 88 | results: List of scan results to analyze |
| 89 | |
| 90 | Returns: |
| 91 | Correlation report from initial analysis |
no outgoing calls
no test coverage detected