zhiwen0905 commited on
Commit
191e0af
·
1 Parent(s): 353f8c4

feature(#74): implement api to delete data of autotask from firebase database

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,
@@ -35,6 +36,7 @@ from Brain.src.service.contact_service import ContactsService
35
  from Brain.src.service.feedback_service import FeedbackService
36
  from Brain.src.service.llm.chat_service import ChatService
37
  from Brain.src.service.twilio_service import TwilioService
 
38
 
39
  from fastapi import APIRouter, Depends
40
 
@@ -444,4 +446,42 @@ def construct_blueprint_api() -> APIRouter:
444
  200, "Deleted all contacts from pinecone successfully", ""
445
  )
446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
  return router
 
18
  BasicReq,
19
  ClientInfo,
20
  get_client_info,
21
+ AutoTaskDelete,
22
  )
23
  from Brain.src.rising_plugin.risingplugin import (
24
  getCompletion,
 
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
+ from Brain.src.service.auto_task_service import delete_db_data
40
 
41
  from fastapi import APIRouter, Depends
42
 
 
446
  200, "Deleted all contacts from pinecone successfully", ""
447
  )
448
 
449
+ """@generator.request_body(
450
+ {
451
+ "token": "String",
452
+ "uuid": "String",
453
+ "data": {
454
+ "reference_link": "test link",
455
+ },
456
+ }
457
+ )
458
+
459
+ @generator.response(
460
+ status_code=200, schema={"message": "message", "result": "test_result"}
461
+ )
462
+
463
+ """
464
+
465
+ @router.post("/auto_task/delete")
466
+ def delete_data(data: AutoTaskDelete):
467
+ # firebase admin init
468
+ try:
469
+ setting, firebase_app = firebase_admin_with_setting(data)
470
+ except BrainException as ex:
471
+ return assembler.to_response(ex.code, ex.message, "")
472
+ try:
473
+ token = setting.token
474
+ uuid = setting.uuid
475
+
476
+ # parsing contacts
477
+ # train contact
478
+ delete_db_data(data.data.reference_link, firebase_app)
479
+ except Exception as e:
480
+ if isinstance(e, BrainException):
481
+ return e.get_response_exp()
482
+ return assembler.to_response(400, "Failed to delete data", "")
483
+ return assembler.to_response(
484
+ 200, "Deleted data from real-time database of firebase", ""
485
+ )
486
+
487
  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