Ask the copilot a question about security findings. Args: question: Natural language question include_context: Whether to include scan context Returns: AI response
(
self,
question: str,
include_context: bool = True,
)
| 150 | async def ask( |
| 151 | self, |
| 152 | question: str, |
| 153 | include_context: bool = True, |
| 154 | ) -> str: |
| 155 | """Ask the copilot a question about security findings. |
| 156 | |
| 157 | Args: |
| 158 | question: Natural language question |
| 159 | include_context: Whether to include scan context |
| 160 | |
| 161 | Returns: |
| 162 | AI response |
| 163 | """ |
| 164 | messages = [Message(role="system", content=SYSTEM_PROMPT)] |
| 165 | |
| 166 | # Add scan context if available and requested |
| 167 | if include_context and self.scan_context: |
| 168 | context = self._build_context() |
| 169 | messages.append(Message( |
| 170 | role="user", |
| 171 | content=f"Here is the current scan data:\n\n```json\n{context}\n```\n\n" |
| 172 | "I'll now ask you questions about this data." |
| 173 | )) |
| 174 | messages.append(Message( |
| 175 | role="assistant", |
| 176 | content="I've analyzed the scan data. I can see the findings, risk levels, " |
| 177 | "and potential attack chains. What would you like to know?" |
| 178 | )) |
| 179 | |
| 180 | # Add conversation history |
| 181 | messages.extend(self.conversation) |
| 182 | |
| 183 | # Add current question |
| 184 | messages.append(Message(role="user", content=question)) |
| 185 | |
| 186 | # Get response |
| 187 | client = self._get_client() |
| 188 | response = await client.chat(messages, temperature=0.3) |
| 189 | |
| 190 | # Update conversation history |
| 191 | self.conversation.append(Message(role="user", content=question)) |
| 192 | self.conversation.append(Message(role="assistant", content=response.content)) |
| 193 | |
| 194 | # Trim conversation history if too long |
| 195 | if len(self.conversation) > 20: |
| 196 | self.conversation = self.conversation[-10:] |
| 197 | |
| 198 | return response.content |
| 199 | |
| 200 | async def stream_ask( |
| 201 | self, |
| 202 | question: str, |
| 203 | include_context: bool = True, |
no test coverage detected