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