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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
|
| 6 |
+
from application_layer_agent import ApplicationLayerAgent
|
| 7 |
|
| 8 |
+
from datetime import datetime, timedelta
|
| 9 |
+
from databaseengine import DatabaseEngine
|
| 10 |
+
import uuid
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
app = FastAPI()
|
| 18 |
+
|
| 19 |
+
dbe=DatabaseEngine()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# CORS configuration
|
| 24 |
+
origins = ["*"] # Allow all origins; specify domains in production
|
| 25 |
+
|
| 26 |
+
app.add_middleware(
|
| 27 |
+
CORSMiddleware,
|
| 28 |
+
allow_origins=origins, # Allows all origins
|
| 29 |
+
allow_credentials=True,
|
| 30 |
+
allow_methods=["*"], # Allows all HTTP methods
|
| 31 |
+
allow_headers=["*"], # Allows all headers
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class PlannerInstruction(BaseModel):
|
| 36 |
+
uid:str
|
| 37 |
+
pid:str
|
| 38 |
+
target:str
|
| 39 |
+
high_level_bio_query:str
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class Registration(BaseModel):
|
| 44 |
+
name:str
|
| 45 |
+
operation:str
|
| 46 |
+
username:str
|
| 47 |
+
password:str
|
| 48 |
+
|
| 49 |
+
|
| 50 |
|
| 51 |
|
| 52 |
@app.get("/")
|
| 53 |
+
def Home():
|
| 54 |
+
return """
|
| 55 |
+
newMATTER
|
| 56 |
+
Version 1.0
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
'''
|
| 61 |
+
@app.post("/registerorg")
|
| 62 |
+
def Register(request:Registration):
|
| 63 |
+
try:
|
| 64 |
+
data={
|
| 65 |
+
|
| 66 |
+
"name":request.name,
|
| 67 |
+
"operation":request.operation,
|
| 68 |
+
"username":request.username,
|
| 69 |
+
"password":request.password,
|
| 70 |
+
"projects":[]
|
| 71 |
+
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
dbe.RegisterUser(data)
|
| 75 |
+
return {"status":True}
|
| 76 |
+
except Exception as e:
|
| 77 |
+
return {"status":False}
|
| 78 |
+
|
| 79 |
+
'''
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
@app.post("/application_layer_agent")
|
| 83 |
+
|
| 84 |
+
def BCL_PLAN(request:PlannerInstruction):
|
| 85 |
+
|
| 86 |
+
try:
|
| 87 |
+
bio_query=request.high_level_bio_query
|
| 88 |
+
|
| 89 |
+
user_id=request.uid
|
| 90 |
+
project_id=request.pid
|
| 91 |
+
target=request.target
|
| 92 |
+
|
| 93 |
+
uid=f"origin_ai_bio_{user_id}_{project_id}"
|
| 94 |
+
|
| 95 |
+
response=ApplicationLayerAgent(bio_query,uid,user_id,project_id,target)
|
| 96 |
+
return { "message": response ,"status":"ok" }
|
| 97 |
+
|
| 98 |
+
except Exception as e:
|
| 99 |
+
|
| 100 |
+
return {"message":str(e),"status":str(e)}
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
@app.get("/user/operations/{user_id}")
|
| 108 |
+
def GetUserOps(user_id:str):
|
| 109 |
try:
|
| 110 |
+
userops=dbe.Find_User(uid=user_id)
|
| 111 |
+
return {"ops":userops}
|
| 112 |
except Exception as e:
|
| 113 |
+
return {"ops":str(e)}
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@app.get("{user_id}/{project_id}/operation/status")
|
| 123 |
+
|
| 124 |
+
def GetOperationStatus(user_id:str,project_id:str):
|
| 125 |
+
|
| 126 |
+
bcl_id=
|
| 127 |
+
uid=f"origin_ai_bio_{user_id}_{project_id}"
|
| 128 |
+
|
| 129 |
+
status=dbe.Fetch_Status(bcl_id)
|
| 130 |
+
return status
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
@app.get("/{user_id}/{project_id}/individual/experiment")
|
| 139 |
+
def GetIndividualExperiments(user_id:str,project_id:str):
|
| 140 |
+
try:
|
| 141 |
+
individual_experiments=dbe.Fetch_IE(f"origin_ai_bio_{user_id}_{project_id}")
|
| 142 |
+
return {"exp":str(individual_experiments)}
|
| 143 |
+
except Exception as e:
|
| 144 |
+
return {"exp":str(e)}
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
@app.get("/{user_id}/projects")
|
| 152 |
+
def FetchProject_based_on_Applayer(user_id):
|
| 153 |
+
try:
|
| 154 |
+
projects=dbe.Fetch_Projects(user_id)
|
| 155 |
+
if projects is None :
|
| 156 |
+
return {"projects":None}
|
| 157 |
+
|
| 158 |
+
else:
|
| 159 |
+
return {"projects":projects}
|
| 160 |
+
|
| 161 |
+
except Exception as e:
|
| 162 |
+
return { "projects":str(e) }
|
| 163 |
+
|
| 164 |
|
| 165 |
|
| 166 |
|