Lucas ARRIESSE
commited on
Commit
·
f3bf993
1
Parent(s):
2c86f91
Random fixes + doc bits
Browse files- api/docs.py +17 -15
- doc/doc.md +6 -0
- schemas.py +17 -14
- static/index.html +5 -6
- static/js/app.js +3 -3
api/docs.py
CHANGED
@@ -22,7 +22,7 @@ from fastapi.responses import StreamingResponse
|
|
22 |
from litellm.router import Router
|
23 |
from kreuzberg import ExtractionConfig, extract_bytes
|
24 |
|
25 |
-
from schemas import
|
26 |
|
27 |
# API router for requirement extraction from docs / doc list retrieval / download
|
28 |
router = APIRouter(tags=["document extraction"])
|
@@ -108,6 +108,7 @@ async def convert_file(contents: io.BytesIO, filename: str, input_ext: str, outp
|
|
108 |
# Rate limit of FTP downloads per minute
|
109 |
FTP_DOWNLOAD_RATE_LIMITER = AsyncLimiter(max_rate=120, time_period=60)
|
110 |
|
|
|
111 |
async def get_doc_archive(url: str, client: AsyncClient) -> tuple[str, str, io.BytesIO]:
|
112 |
"""Récupère le docx depuis l'URL et le retourne un tuple (nom, extension, contenu)"""
|
113 |
|
@@ -241,8 +242,11 @@ async def doc_to_txt(doc_id: str, url: str, client: AsyncClient) -> str:
|
|
241 |
|
242 |
# ============================================= Doc routes =========================================================
|
243 |
|
244 |
-
@router.post("/get_meetings", response_model=
|
245 |
-
async def get_meetings(req:
|
|
|
|
|
|
|
246 |
# Extracting WG
|
247 |
working_group = req.working_group
|
248 |
tsg = re.sub(r"\d+", "", working_group)
|
@@ -278,13 +282,13 @@ async def get_meetings(req: MeetingsRequest, http_client: AsyncClient = Depends(
|
|
278 |
all_meetings = [working_group + "#" + meeting.split("_", 1)[1].replace("_", " ").replace(
|
279 |
"-", " ") if meeting.startswith('TSG') else meeting.replace("-", "#") for meeting in meeting_folders]
|
280 |
|
281 |
-
return
|
282 |
|
283 |
# ============================================================================================================================================
|
284 |
|
285 |
|
286 |
-
@router.post("/
|
287 |
-
async def
|
288 |
"""
|
289 |
Downloads the document list dataframe for a given meeting
|
290 |
"""
|
@@ -314,22 +318,20 @@ async def get_docs_df(req: DataRequest, http_client: AsyncClient = Depends(get_h
|
|
314 |
if files == []:
|
315 |
raise HTTPException(status_code=404, detail="No XLSX has been found")
|
316 |
|
317 |
-
def gen_url(tdoc: str):
|
318 |
-
return f"{url}/{tdoc}.zip"
|
319 |
-
|
320 |
df = pd.read_excel(str(url + "/" + files[0]).replace("#", "%23"))
|
321 |
filtered_df = df[~(
|
322 |
df["Uploaded"].isna())][["TDoc", "Title", "CR category", "Source", "Type", "Agenda item", "Agenda item description", "TDoc Status"]]
|
323 |
-
filtered_df["URL"] = filtered_df["TDoc"].apply(
|
|
|
324 |
|
325 |
df = filtered_df.fillna("")
|
326 |
-
return
|
327 |
|
328 |
# ==================================================================================================================================
|
329 |
|
330 |
|
331 |
-
@router.post("/
|
332 |
-
async def
|
333 |
"""Download the specified TDocs and zips them in a single archive"""
|
334 |
|
335 |
# Document IDs to download
|
@@ -379,8 +381,8 @@ class ProgressUpdate(BaseModel):
|
|
379 |
processed_docs: int
|
380 |
|
381 |
|
382 |
-
@router.post("/
|
383 |
-
async def
|
384 |
"""Extract requirements from the specified xxxxCR docs using a LLM and returns SSE events about the progress of ongoing operations"""
|
385 |
|
386 |
documents = req.documents
|
|
|
22 |
from litellm.router import Router
|
23 |
from kreuzberg import ExtractionConfig, extract_bytes
|
24 |
|
25 |
+
from schemas import GetMeetingDocsRequest, GetMeetingDocsResponse, DocRequirements, DownloadDocsRequest, GetMeetingsRequest, GetMeetingsResponse, ExtractRequirementsRequest, ExtractRequirementsResponse
|
26 |
|
27 |
# API router for requirement extraction from docs / doc list retrieval / download
|
28 |
router = APIRouter(tags=["document extraction"])
|
|
|
108 |
# Rate limit of FTP downloads per minute
|
109 |
FTP_DOWNLOAD_RATE_LIMITER = AsyncLimiter(max_rate=120, time_period=60)
|
110 |
|
111 |
+
|
112 |
async def get_doc_archive(url: str, client: AsyncClient) -> tuple[str, str, io.BytesIO]:
|
113 |
"""Récupère le docx depuis l'URL et le retourne un tuple (nom, extension, contenu)"""
|
114 |
|
|
|
242 |
|
243 |
# ============================================= Doc routes =========================================================
|
244 |
|
245 |
+
@router.post("/get_meetings", response_model=GetMeetingsResponse)
|
246 |
+
async def get_meetings(req: GetMeetingsRequest, http_client: AsyncClient = Depends(get_http_client)):
|
247 |
+
"""
|
248 |
+
Retrieves the list of meetings for the given working group.
|
249 |
+
"""
|
250 |
# Extracting WG
|
251 |
working_group = req.working_group
|
252 |
tsg = re.sub(r"\d+", "", working_group)
|
|
|
282 |
all_meetings = [working_group + "#" + meeting.split("_", 1)[1].replace("_", " ").replace(
|
283 |
"-", " ") if meeting.startswith('TSG') else meeting.replace("-", "#") for meeting in meeting_folders]
|
284 |
|
285 |
+
return GetMeetingsResponse(meetings=dict(zip(all_meetings, meeting_folders)))
|
286 |
|
287 |
# ============================================================================================================================================
|
288 |
|
289 |
|
290 |
+
@router.post("/get_meeting_docs", response_model=GetMeetingDocsResponse)
|
291 |
+
async def get_meeting_docs(req: GetMeetingDocsRequest, http_client: AsyncClient = Depends(get_http_client)) -> GetMeetingDocsResponse:
|
292 |
"""
|
293 |
Downloads the document list dataframe for a given meeting
|
294 |
"""
|
|
|
318 |
if files == []:
|
319 |
raise HTTPException(status_code=404, detail="No XLSX has been found")
|
320 |
|
|
|
|
|
|
|
321 |
df = pd.read_excel(str(url + "/" + files[0]).replace("#", "%23"))
|
322 |
filtered_df = df[~(
|
323 |
df["Uploaded"].isna())][["TDoc", "Title", "CR category", "Source", "Type", "Agenda item", "Agenda item description", "TDoc Status"]]
|
324 |
+
filtered_df["URL"] = filtered_df["TDoc"].apply(
|
325 |
+
lambda tdoc: f"{url}/{tdoc}.zip")
|
326 |
|
327 |
df = filtered_df.fillna("")
|
328 |
+
return GetMeetingDocsResponse(data=df[["TDoc", "Title", "Type", "TDoc Status", "Agenda item description", "URL"]].to_dict(orient="records"))
|
329 |
|
330 |
# ==================================================================================================================================
|
331 |
|
332 |
|
333 |
+
@router.post("/download_docs")
|
334 |
+
async def download_docs(req: DownloadDocsRequest, http_client: AsyncClient = Depends(get_http_client)) -> StreamingResponse:
|
335 |
"""Download the specified TDocs and zips them in a single archive"""
|
336 |
|
337 |
# Document IDs to download
|
|
|
381 |
processed_docs: int
|
382 |
|
383 |
|
384 |
+
@router.post("/extract_requirements/sse")
|
385 |
+
async def extract_requirements_from_docs(req: ExtractRequirementsRequest, llm_router: Router = Depends(get_llm_router), http_client: AsyncClient = Depends(get_http_client)):
|
386 |
"""Extract requirements from the specified xxxxCR docs using a LLM and returns SSE events about the progress of ongoing operations"""
|
387 |
|
388 |
documents = req.documents
|
doc/doc.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
|
2 |
## Reqxtract
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
### General flow
|
6 |
The general use flow for the project is as follows
|
|
|
1 |
|
2 |
## Reqxtract
|
3 |
|
4 |
+
### API router list
|
5 |
+
|
6 |
+
- `api/docs.py` : Handles documents processing and extraction of requirements
|
7 |
+
- `api/requirements.py` : Handles requirements processing and operations.
|
8 |
+
- `api/solutions.py` : Handles solution generation and critique.
|
9 |
+
|
10 |
|
11 |
### General flow
|
12 |
The general use flow for the project is as follows
|
schemas.py
CHANGED
@@ -2,25 +2,26 @@ from pydantic import BaseModel, Field
|
|
2 |
from typing import Any, List, Dict, Literal, Optional
|
3 |
|
4 |
|
5 |
-
|
6 |
-
working_group: str
|
7 |
|
|
|
|
|
|
|
8 |
|
9 |
-
class MeetingsResponse(BaseModel):
|
10 |
-
meetings: Dict[str, str]
|
11 |
-
# --------------------------------------
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
-
|
|
|
15 |
working_group: str
|
16 |
meeting: str
|
17 |
|
18 |
|
19 |
-
class
|
20 |
data: List[Dict[Any, Any]]
|
21 |
|
22 |
-
# --------------------------------------
|
23 |
-
|
24 |
|
25 |
class DocInfo(BaseModel):
|
26 |
"""
|
@@ -34,6 +35,13 @@ class DocInfo(BaseModel):
|
|
34 |
type: str
|
35 |
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
class ExtractRequirementsRequest(BaseModel):
|
38 |
documents: List[DocInfo]
|
39 |
|
@@ -73,11 +81,6 @@ class ReqSearchResponse(BaseModel):
|
|
73 |
# --------------------------------------
|
74 |
|
75 |
|
76 |
-
class DocDownloadRequest(BaseModel):
|
77 |
-
documents: List[DocInfo] = Field(
|
78 |
-
description="List of documents to download")
|
79 |
-
|
80 |
-
|
81 |
class ReqGroupingCategory(BaseModel):
|
82 |
"""Represents the category of requirements grouped together"""
|
83 |
id: int = Field(..., description="ID of the grouping category")
|
|
|
2 |
from typing import Any, List, Dict, Literal, Optional
|
3 |
|
4 |
|
5 |
+
# --------------------------------------- Document related endpoints ---------------------------------------
|
|
|
6 |
|
7 |
+
class GetMeetingsRequest(BaseModel):
|
8 |
+
working_group: Literal["SA1", "SA2", "SA3", "SA4", "SA5", "SA6",
|
9 |
+
"CT1", "CT2", "CT3", "CT4", "CT5", "CT6", "RAN1", "RAN2"]
|
10 |
|
|
|
|
|
|
|
11 |
|
12 |
+
class GetMeetingsResponse(BaseModel):
|
13 |
+
meetings: Dict[str, str] = Field(
|
14 |
+
..., description="Mapping of meetings with as key their display name and value the FTP meeting name.")
|
15 |
|
16 |
+
|
17 |
+
class GetMeetingDocsRequest(BaseModel):
|
18 |
working_group: str
|
19 |
meeting: str
|
20 |
|
21 |
|
22 |
+
class GetMeetingDocsResponse(BaseModel):
|
23 |
data: List[Dict[Any, Any]]
|
24 |
|
|
|
|
|
25 |
|
26 |
class DocInfo(BaseModel):
|
27 |
"""
|
|
|
35 |
type: str
|
36 |
|
37 |
|
38 |
+
class DownloadDocsRequest(BaseModel):
|
39 |
+
documents: List[DocInfo] = Field(
|
40 |
+
description="List of documents to download")
|
41 |
+
|
42 |
+
# --------------------------------------
|
43 |
+
|
44 |
+
|
45 |
class ExtractRequirementsRequest(BaseModel):
|
46 |
documents: List[DocInfo]
|
47 |
|
|
|
81 |
# --------------------------------------
|
82 |
|
83 |
|
|
|
|
|
|
|
|
|
|
|
84 |
class ReqGroupingCategory(BaseModel):
|
85 |
"""Represents the category of requirements grouped together"""
|
86 |
id: int = Field(..., description="ID of the grouping category")
|
static/index.html
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
<head>
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
-
<title>
|
8 |
<!--See JS imports for ESM modules-->
|
9 |
<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css" />
|
10 |
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
|
@@ -22,7 +22,7 @@
|
|
22 |
|
23 |
<div class="container mx-auto p-6">
|
24 |
<div class="relative flex justify-center items-center p-4">
|
25 |
-
<h1 class="text-3xl font-bold">
|
26 |
<button class="absolute right-4 btn btn-sm btn-circle btn-outline" id="settings-btn"
|
27 |
onclick="settings_modal.showModal()" title="Settings">🔧</button>
|
28 |
</div>
|
@@ -159,12 +159,12 @@
|
|
159 |
<div class="tooltip" data-tip="Extract requirements from selected pCR / CR documents">
|
160 |
<button id="extract-requirements-btn"
|
161 |
class="bg-orange-300 text-white text-sm rounded px-3 py-1 shadow hover:bg-orange-600">💉
|
162 |
-
Extract Requirements
|
163 |
</button>
|
164 |
</div>
|
165 |
-
<div class="tooltip" data-tip="Download all selected
|
166 |
<button id="download-tdocs-btn" class="text-sm rounded px-3 py-1 shadow cursor-pointer">
|
167 |
-
📦 Download Selected
|
168 |
</button>
|
169 |
</div>
|
170 |
</div>
|
@@ -498,7 +498,6 @@
|
|
498 |
</div>
|
499 |
</div>
|
500 |
</dialog>
|
501 |
-
|
502 |
<script type="module" src="js/app.js"></script>
|
503 |
</body>
|
504 |
|
|
|
4 |
<head>
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>Docxtract</title>
|
8 |
<!--See JS imports for ESM modules-->
|
9 |
<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css" />
|
10 |
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
|
|
|
22 |
|
23 |
<div class="container mx-auto p-6">
|
24 |
<div class="relative flex justify-center items-center p-4">
|
25 |
+
<h1 class="text-3xl font-bold">Docxtract</h1>
|
26 |
<button class="absolute right-4 btn btn-sm btn-circle btn-outline" id="settings-btn"
|
27 |
onclick="settings_modal.showModal()" title="Settings">🔧</button>
|
28 |
</div>
|
|
|
159 |
<div class="tooltip" data-tip="Extract requirements from selected pCR / CR documents">
|
160 |
<button id="extract-requirements-btn"
|
161 |
class="bg-orange-300 text-white text-sm rounded px-3 py-1 shadow hover:bg-orange-600">💉
|
162 |
+
Extract Requirements from CRs
|
163 |
</button>
|
164 |
</div>
|
165 |
+
<div class="tooltip" data-tip="Download all selected docs as text files">
|
166 |
<button id="download-tdocs-btn" class="text-sm rounded px-3 py-1 shadow cursor-pointer">
|
167 |
+
📦 Download Selected Docs
|
168 |
</button>
|
169 |
</div>
|
170 |
</div>
|
|
|
498 |
</div>
|
499 |
</div>
|
500 |
</dialog>
|
|
|
501 |
<script type="module" src="js/app.js"></script>
|
502 |
</body>
|
503 |
|
static/js/app.js
CHANGED
@@ -74,7 +74,7 @@ async function getTDocs() {
|
|
74 |
toggleElementsEnabled(['get-tdocs-btn'], false);
|
75 |
|
76 |
try {
|
77 |
-
const response = await fetch('/docs/
|
78 |
method: 'POST',
|
79 |
headers: { 'Content-Type': 'application/json' },
|
80 |
body: JSON.stringify({ working_group: workingGroup, meeting: meeting })
|
@@ -245,7 +245,7 @@ async function downloadTDocs() {
|
|
245 |
// on prend tout
|
246 |
const documents = selectedData;
|
247 |
|
248 |
-
const response = await fetch('/docs/
|
249 |
method: 'POST',
|
250 |
headers: { 'Content-Type': 'application/json' },
|
251 |
body: JSON.stringify({ documents: documents })
|
@@ -336,7 +336,7 @@ async function extractRequirements() {
|
|
336 |
toggleElementsEnabled(['extract-requirements-btn'], false);
|
337 |
|
338 |
try {
|
339 |
-
const response = await postWithSSE('/docs/
|
340 |
onMessage: (msg) => {
|
341 |
console.log("SSE message:");
|
342 |
console.log(msg);
|
|
|
74 |
toggleElementsEnabled(['get-tdocs-btn'], false);
|
75 |
|
76 |
try {
|
77 |
+
const response = await fetch('/docs/get_meeting_docs', {
|
78 |
method: 'POST',
|
79 |
headers: { 'Content-Type': 'application/json' },
|
80 |
body: JSON.stringify({ working_group: workingGroup, meeting: meeting })
|
|
|
245 |
// on prend tout
|
246 |
const documents = selectedData;
|
247 |
|
248 |
+
const response = await fetch('/docs/download_docs', {
|
249 |
method: 'POST',
|
250 |
headers: { 'Content-Type': 'application/json' },
|
251 |
body: JSON.stringify({ documents: documents })
|
|
|
336 |
toggleElementsEnabled(['extract-requirements-btn'], false);
|
337 |
|
338 |
try {
|
339 |
+
const response = await postWithSSE('/docs/extract_requirements/sse', { documents: documents }, {
|
340 |
onMessage: (msg) => {
|
341 |
console.log("SSE message:");
|
342 |
console.log(msg);
|