Spaces:
Runtime error
Runtime error
Aryan Jain commited on
Commit ·
d191819
1
Parent(s): 1b605f8
update apis to generate sow from knowledge base
Browse files
src/controllers/_sow_controller.py
CHANGED
|
@@ -112,13 +112,13 @@ class SOWController:
|
|
| 112 |
response_model=ResponseSOWSingle,
|
| 113 |
tags=["Upload Requirement File"],
|
| 114 |
)
|
| 115 |
-
self.router.add_api_route(
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
)
|
| 122 |
|
| 123 |
async def get_sows(self):
|
| 124 |
async with self.__sow_service() as service:
|
|
|
|
| 112 |
response_model=ResponseSOWSingle,
|
| 113 |
tags=["Upload Requirement File"],
|
| 114 |
)
|
| 115 |
+
# self.router.add_api_route(
|
| 116 |
+
# "/sows/{sow_id}/upload",
|
| 117 |
+
# self.upload_sow_by_id,
|
| 118 |
+
# methods=["POST"],
|
| 119 |
+
# response_model=ResponseSOWSingle,
|
| 120 |
+
# tags=["Upload Requirement File"],
|
| 121 |
+
# )
|
| 122 |
|
| 123 |
async def get_sows(self):
|
| 124 |
async with self.__sow_service() as service:
|
src/services/_sow_service.py
CHANGED
|
@@ -34,7 +34,8 @@ class SOWService:
|
|
| 34 |
async def create_sow(self, sow: dict) -> dict:
|
| 35 |
try:
|
| 36 |
async with self.__repository() as repository:
|
| 37 |
-
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
logger.exception(e)
|
| 40 |
raise HTTPException(
|
|
@@ -47,7 +48,7 @@ class SOWService:
|
|
| 47 |
result = await repository.update_sow(sow_id=sow_id, sow=sow)
|
| 48 |
if not result:
|
| 49 |
raise HTTPException(status_code=404, detail="SOW not found")
|
| 50 |
-
return
|
| 51 |
except HTTPException:
|
| 52 |
raise
|
| 53 |
except Exception as e:
|
|
@@ -107,7 +108,7 @@ class SOWService:
|
|
| 107 |
id=folder_id, files=files
|
| 108 |
)
|
| 109 |
|
| 110 |
-
return
|
| 111 |
except HTTPException:
|
| 112 |
raise
|
| 113 |
except Exception as e:
|
|
|
|
| 34 |
async def create_sow(self, sow: dict) -> dict:
|
| 35 |
try:
|
| 36 |
async with self.__repository() as repository:
|
| 37 |
+
sow = await repository.create_sow(sow)
|
| 38 |
+
return await self.generate_sow(sow_id=sow["id"])
|
| 39 |
except Exception as e:
|
| 40 |
logger.exception(e)
|
| 41 |
raise HTTPException(
|
|
|
|
| 48 |
result = await repository.update_sow(sow_id=sow_id, sow=sow)
|
| 49 |
if not result:
|
| 50 |
raise HTTPException(status_code=404, detail="SOW not found")
|
| 51 |
+
return await self.generate_sow(sow_id=sow_id)
|
| 52 |
except HTTPException:
|
| 53 |
raise
|
| 54 |
except Exception as e:
|
|
|
|
| 108 |
id=folder_id, files=files
|
| 109 |
)
|
| 110 |
|
| 111 |
+
return await self.generate_sow(sow_id=folder_id)
|
| 112 |
except HTTPException:
|
| 113 |
raise
|
| 114 |
except Exception as e:
|
src/utils/_sow_client.py
CHANGED
|
@@ -38,34 +38,47 @@ class SOWClient:
|
|
| 38 |
pass
|
| 39 |
|
| 40 |
async def generate_sow(self, sow_id: UUID) -> dict:
|
|
|
|
|
|
|
| 41 |
async with self._repository() as repository:
|
| 42 |
sows = await repository.get_sows(sow_id=sow_id)
|
| 43 |
folder_path = os.path.join(os.getcwd(), "temp", str(sow_id))
|
| 44 |
if os.path.exists(folder_path):
|
| 45 |
content = await self._read_uploaded_files(id=sow_id)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
else:
|
| 49 |
-
sow = sows[0]
|
| 50 |
-
sow["rfp_content"] = sow["requirement"]
|
| 51 |
del sow["id"]
|
| 52 |
del sow["created_at"]
|
| 53 |
del sow["updated_at"]
|
| 54 |
url = os.getenv(
|
| 55 |
-
"NN_SOW_URL", "https://n8n.srv763317.hstgr.cloud/webhook/
|
| 56 |
)
|
| 57 |
async with httpx.AsyncClient() as client:
|
| 58 |
response = await client.post(
|
| 59 |
url,
|
| 60 |
json=sow,
|
| 61 |
-
timeout=
|
| 62 |
)
|
| 63 |
response_json = response.json()
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
async with self._repository() as repository:
|
| 66 |
updated_sow = await repository.update_sow(
|
| 67 |
sow_id=sow_id,
|
| 68 |
-
sow={
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
)
|
| 70 |
await self._remove_uploaded_files(id=sow_id)
|
| 71 |
return updated_sow
|
|
|
|
| 38 |
pass
|
| 39 |
|
| 40 |
async def generate_sow(self, sow_id: UUID) -> dict:
|
| 41 |
+
content = None
|
| 42 |
+
question_json = None
|
| 43 |
async with self._repository() as repository:
|
| 44 |
sows = await repository.get_sows(sow_id=sow_id)
|
| 45 |
folder_path = os.path.join(os.getcwd(), "temp", str(sow_id))
|
| 46 |
if os.path.exists(folder_path):
|
| 47 |
content = await self._read_uploaded_files(id=sow_id)
|
| 48 |
+
sow = sows[0]
|
| 49 |
+
sow["requirement"] = content if content else sow["requirement"]
|
|
|
|
|
|
|
|
|
|
| 50 |
del sow["id"]
|
| 51 |
del sow["created_at"]
|
| 52 |
del sow["updated_at"]
|
| 53 |
url = os.getenv(
|
| 54 |
+
"NN_SOW_URL", "https://n8n.srv763317.hstgr.cloud/webhook/sow-generate"
|
| 55 |
)
|
| 56 |
async with httpx.AsyncClient() as client:
|
| 57 |
response = await client.post(
|
| 58 |
url,
|
| 59 |
json=sow,
|
| 60 |
+
timeout=3000,
|
| 61 |
)
|
| 62 |
response_json = response.json()
|
| 63 |
+
generated_sow_json = response_json["message"]["content"]
|
| 64 |
+
if generated_sow_json["is_required_questions"]:
|
| 65 |
+
question_json = {}
|
| 66 |
+
for question in generated_sow_json["questions"]:
|
| 67 |
+
question_json[question] = None
|
| 68 |
+
question_json = str(question_json)
|
| 69 |
+
generated_sow = (
|
| 70 |
+
generated_sow_json["generated_sow"]
|
| 71 |
+
if generated_sow_json["generated_sow"]
|
| 72 |
+
else None
|
| 73 |
+
)
|
| 74 |
async with self._repository() as repository:
|
| 75 |
updated_sow = await repository.update_sow(
|
| 76 |
sow_id=sow_id,
|
| 77 |
+
sow={
|
| 78 |
+
"sow_generated_text": generated_sow,
|
| 79 |
+
"additional_info": question_json,
|
| 80 |
+
"requirement": content if content else sow["requirement"],
|
| 81 |
+
},
|
| 82 |
)
|
| 83 |
await self._remove_uploaded_files(id=sow_id)
|
| 84 |
return updated_sow
|