Spaces:
Sleeping
Sleeping
Upload requirements_pipe.py
Browse files- pipelines/requirements_pipe.py +38 -11
pipelines/requirements_pipe.py
CHANGED
|
@@ -64,10 +64,21 @@ class RAGModel:
|
|
| 64 |
class Router:
|
| 65 |
"""Chooses a target pipeline for the extracted requirements."""
|
| 66 |
|
| 67 |
-
def route(self, *, compliant: bool, requirements: str) -> str:
|
| 68 |
"""
|
| 69 |
-
Route
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
return "matrix" if compliant else "jira"
|
| 72 |
|
| 73 |
|
|
@@ -93,10 +104,20 @@ class JiraAgent:
|
|
| 93 |
|
| 94 |
def stream(self, requirements: str) -> Iterable[str]:
|
| 95 |
system_prompt = (
|
| 96 |
-
"You are a Jira assistant. Respond ONLY with
|
| 97 |
-
'{
|
| 98 |
-
'"
|
| 99 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
user_prompt = (
|
| 101 |
"Create a Jira ticket for these requirements:\n"
|
| 102 |
f"{requirements}")
|
|
@@ -144,10 +165,12 @@ class ComplianceMatrixAgent:
|
|
| 144 |
|
| 145 |
def stream(self, requirements: str) -> Iterable[str]:
|
| 146 |
system_prompt = (
|
| 147 |
-
"You are a compliance analyst. Produce ONLY a markdown table
|
| 148 |
-
"
|
| 149 |
-
"
|
| 150 |
-
"
|
|
|
|
|
|
|
| 151 |
user_prompt = (
|
| 152 |
"Create a compliance matrix CSV for these requirements:\n"
|
| 153 |
f"{requirements}")
|
|
@@ -203,7 +226,11 @@ class RequirementsPipeline:
|
|
| 203 |
requirements = extraction["requirements"]
|
| 204 |
compliant = extraction["compliant"]
|
| 205 |
|
| 206 |
-
target = self.router.route(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
agent = self.agents.get(target)
|
| 209 |
if not agent:
|
|
|
|
| 64 |
class Router:
|
| 65 |
"""Chooses a target pipeline for the extracted requirements."""
|
| 66 |
|
| 67 |
+
def route(self, *, compliant: bool, requirements: str, user_query: str = "") -> str:
|
| 68 |
"""
|
| 69 |
+
Route based on explicit intent first, otherwise by compliance status.
|
| 70 |
+
|
| 71 |
+
- If the user asks for a Jira ticket (keywords like "jira", "ticket",
|
| 72 |
+
"issue", "bug", "story", "epic"), route to Jira.
|
| 73 |
+
- Else: non-compliant -> Jira; compliant -> matrix.
|
| 74 |
"""
|
| 75 |
+
intent = user_query.lower()
|
| 76 |
+
wants_jira = any(
|
| 77 |
+
keyword in intent
|
| 78 |
+
for keyword in ("jira", "ticket", "issue", "bug", "story", "epic")
|
| 79 |
+
)
|
| 80 |
+
if wants_jira:
|
| 81 |
+
return "jira"
|
| 82 |
return "matrix" if compliant else "jira"
|
| 83 |
|
| 84 |
|
|
|
|
| 104 |
|
| 105 |
def stream(self, requirements: str) -> Iterable[str]:
|
| 106 |
system_prompt = (
|
| 107 |
+
"You are a Jira assistant. Respond ONLY with valid JSON (no markdown) in this exact shape:\n"
|
| 108 |
+
'{\n'
|
| 109 |
+
' "fields": {\n'
|
| 110 |
+
' "project": { "key": "SERVICEDESK" },\n'
|
| 111 |
+
' "summary": "User-submitted issue summary",\n'
|
| 112 |
+
' "description": "Detailed problem description",\n'
|
| 113 |
+
' "issuetype": { "name": "Incident" },\n'
|
| 114 |
+
' "reporter": { "name": "username@email.com" },\n'
|
| 115 |
+
' "priority": { "name": "High" },\n'
|
| 116 |
+
' "labels": ["mobile-app", "user-submitted"],\n'
|
| 117 |
+
' "customfield_10002": { "value": "Customer" }\n'
|
| 118 |
+
' }\n'
|
| 119 |
+
'}\n'
|
| 120 |
+
"Do not add, remove, or rename keys. Fill the values using the user's request. Keep it to valid JSON only.")
|
| 121 |
user_prompt = (
|
| 122 |
"Create a Jira ticket for these requirements:\n"
|
| 123 |
f"{requirements}")
|
|
|
|
| 165 |
|
| 166 |
def stream(self, requirements: str) -> Iterable[str]:
|
| 167 |
system_prompt = (
|
| 168 |
+
"You are a compliance analyst. Produce ONLY a markdown table (no code fences, no prose) "
|
| 169 |
+
"with these exact headers:\n"
|
| 170 |
+
"| Requirement ID | Requirement Text | Source (Spec/Std) | Verification Method | Evidence / Link | Status | Notes |\n"
|
| 171 |
+
"Use realistic IDs (e.g., SYS-REQ-001…), short requirement text, cite a plausible source, "
|
| 172 |
+
"choose a verification method (Test, Inspection, Analysis, or combo), provide a concise evidence/link label, "
|
| 173 |
+
"set Status to one of: Compliant, Partially compliant, Non-compliant, or Pending, and keep Notes brief.")
|
| 174 |
user_prompt = (
|
| 175 |
"Create a compliance matrix CSV for these requirements:\n"
|
| 176 |
f"{requirements}")
|
|
|
|
| 226 |
requirements = extraction["requirements"]
|
| 227 |
compliant = extraction["compliant"]
|
| 228 |
|
| 229 |
+
target = self.router.route(
|
| 230 |
+
compliant=compliant,
|
| 231 |
+
requirements=requirements,
|
| 232 |
+
user_query=query,
|
| 233 |
+
)
|
| 234 |
|
| 235 |
agent = self.agents.get(target)
|
| 236 |
if not agent:
|