Merge pull request #123 from ttt246/feature/instant_answer_74
Browse files
Brain/src/model/requests/request_model.py
CHANGED
|
@@ -205,3 +205,13 @@ class Train(BasicReq):
|
|
| 205 |
id: str
|
| 206 |
data: TrainData
|
| 207 |
status: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
id: str
|
| 206 |
data: TrainData
|
| 207 |
status: str
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
"""endpoint /auto_task/delete"""
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
class AutoTaskDelete(BasicReq):
|
| 214 |
+
class Body(BaseModel):
|
| 215 |
+
reference_link: str
|
| 216 |
+
|
| 217 |
+
data: Body
|
Brain/src/router/api.py
CHANGED
|
@@ -18,6 +18,7 @@ from Brain.src.model.requests.request_model import (
|
|
| 18 |
BasicReq,
|
| 19 |
ClientInfo,
|
| 20 |
get_client_info,
|
|
|
|
| 21 |
)
|
| 22 |
from Brain.src.rising_plugin.risingplugin import (
|
| 23 |
getCompletion,
|
|
@@ -36,6 +37,7 @@ from Brain.src.service.contact_service import ContactsService
|
|
| 36 |
from Brain.src.service.feedback_service import FeedbackService
|
| 37 |
from Brain.src.service.llm.chat_service import ChatService
|
| 38 |
from Brain.src.service.twilio_service import TwilioService
|
|
|
|
| 39 |
|
| 40 |
from fastapi import APIRouter, Depends
|
| 41 |
|
|
@@ -452,4 +454,42 @@ def construct_blueprint_api() -> APIRouter:
|
|
| 452 |
200, "Deleted all contacts from pinecone successfully", ""
|
| 453 |
)
|
| 454 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
return router
|
|
|
|
| 18 |
BasicReq,
|
| 19 |
ClientInfo,
|
| 20 |
get_client_info,
|
| 21 |
+
AutoTaskDelete,
|
| 22 |
)
|
| 23 |
from Brain.src.rising_plugin.risingplugin import (
|
| 24 |
getCompletion,
|
|
|
|
| 37 |
from Brain.src.service.feedback_service import FeedbackService
|
| 38 |
from Brain.src.service.llm.chat_service import ChatService
|
| 39 |
from Brain.src.service.twilio_service import TwilioService
|
| 40 |
+
from Brain.src.service.auto_task_service import delete_db_data
|
| 41 |
|
| 42 |
from fastapi import APIRouter, Depends
|
| 43 |
|
|
|
|
| 454 |
200, "Deleted all contacts from pinecone successfully", ""
|
| 455 |
)
|
| 456 |
|
| 457 |
+
"""@generator.request_body(
|
| 458 |
+
{
|
| 459 |
+
"token": "String",
|
| 460 |
+
"uuid": "String",
|
| 461 |
+
"data": {
|
| 462 |
+
"reference_link": "test link",
|
| 463 |
+
},
|
| 464 |
+
}
|
| 465 |
+
)
|
| 466 |
+
|
| 467 |
+
@generator.response(
|
| 468 |
+
status_code=200, schema={"message": "message", "result": "test_result"}
|
| 469 |
+
)
|
| 470 |
+
|
| 471 |
+
"""
|
| 472 |
+
|
| 473 |
+
@router.post("/auto_task/delete")
|
| 474 |
+
def delete_data(data: AutoTaskDelete):
|
| 475 |
+
# firebase admin init
|
| 476 |
+
try:
|
| 477 |
+
setting, firebase_app = firebase_admin_with_setting(data)
|
| 478 |
+
except BrainException as ex:
|
| 479 |
+
return assembler.to_response(ex.code, ex.message, "")
|
| 480 |
+
try:
|
| 481 |
+
token = setting.token
|
| 482 |
+
uuid = setting.uuid
|
| 483 |
+
|
| 484 |
+
# parsing contacts
|
| 485 |
+
# train contact
|
| 486 |
+
delete_db_data(data.data.reference_link, firebase_app)
|
| 487 |
+
except Exception as e:
|
| 488 |
+
if isinstance(e, BrainException):
|
| 489 |
+
return e.get_response_exp()
|
| 490 |
+
return assembler.to_response(400, "Failed to delete data", "")
|
| 491 |
+
return assembler.to_response(
|
| 492 |
+
200, "Deleted data from real-time database of firebase", ""
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
return router
|
Brain/src/service/auto_task_service.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"""auto task management to get the expected output"""
|
| 2 |
import firebase_admin
|
|
|
|
| 3 |
|
| 4 |
from Brain.src.model.req_model import ReqModel
|
| 5 |
from Brain.src.rising_plugin.llm.autogpt_llm import AutoGPTLLM
|
|
@@ -7,6 +8,14 @@ import time
|
|
| 7 |
import asyncio
|
| 8 |
import threading
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
class AutoTaskService:
|
| 12 |
"""self task archivement with autogpt based on langchain
|
|
|
|
| 1 |
"""auto task management to get the expected output"""
|
| 2 |
import firebase_admin
|
| 3 |
+
from firebase_admin import db
|
| 4 |
|
| 5 |
from Brain.src.model.req_model import ReqModel
|
| 6 |
from Brain.src.rising_plugin.llm.autogpt_llm import AutoGPTLLM
|
|
|
|
| 8 |
import asyncio
|
| 9 |
import threading
|
| 10 |
|
| 11 |
+
"""delete data from real time database of firebase using reference link
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def delete_db_data(reference_link: str, firebase_app: firebase_admin.App):
|
| 16 |
+
ref = db.reference(reference_link, app=firebase_app)
|
| 17 |
+
ref.delete()
|
| 18 |
+
|
| 19 |
|
| 20 |
class AutoTaskService:
|
| 21 |
"""self task archivement with autogpt based on langchain
|
Brain/tests/functional/test_api.py
CHANGED
|
@@ -209,3 +209,29 @@ def test_chat_rising(body):
|
|
| 209 |
def test_train_contacts(body):
|
| 210 |
response = client.post("/train/contacts", json=body)
|
| 211 |
assert response.status_code == 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
def test_train_contacts(body):
|
| 210 |
response = client.post("/train/contacts", json=body)
|
| 211 |
assert response.status_code == 200
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
@pytest.mark.parametrize(
|
| 215 |
+
"body",
|
| 216 |
+
[
|
| 217 |
+
(
|
| 218 |
+
{
|
| 219 |
+
"data": {
|
| 220 |
+
"reference_link": "test link",
|
| 221 |
+
},
|
| 222 |
+
"confs": {
|
| 223 |
+
"token": "test_token",
|
| 224 |
+
"uuid": "test-uuid",
|
| 225 |
+
"openai_key": "",
|
| 226 |
+
"pinecone_key": "",
|
| 227 |
+
"pinecone_env": "",
|
| 228 |
+
"firebase_key": "",
|
| 229 |
+
"settings": {"temperature": 0.6},
|
| 230 |
+
},
|
| 231 |
+
}
|
| 232 |
+
)
|
| 233 |
+
],
|
| 234 |
+
)
|
| 235 |
+
def test_delete_data(body):
|
| 236 |
+
response = client.post("/auto_task/delete", json=body)
|
| 237 |
+
assert response.status_code == 200
|