Update databaseengine.py
Browse files- databaseengine.py +34 -4
databaseengine.py
CHANGED
@@ -1,22 +1,52 @@
|
|
1 |
from astrapy import DataAPIClient
|
2 |
|
3 |
# Initialize the client
|
4 |
-
|
5 |
-
|
6 |
"https://ab618096-30bc-47c4-85ac-1a97c75e746c-us-east-2.apps.astra.datastax.com"
|
7 |
)
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
class DatabaseEngine():
|
12 |
def __init__(self):
|
13 |
pass
|
14 |
|
|
|
15 |
def Update(self,data):
|
16 |
|
17 |
-
collection=
|
18 |
collection.update_one(
|
19 |
{"_id": data["prompt"]},
|
20 |
{"$set": {"biological_context_alignment":data["biological_context_alignment"]}},
|
21 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
1 |
from astrapy import DataAPIClient
|
2 |
|
3 |
# Initialize the client
|
4 |
+
client1 = DataAPIClient("AstraCS:vUPtWJNjuqSJzFwpjwGaIMCG:a763d288a24184d3d8f87e78d8f3a9bdb4e687002ea80fb3e21949b969715b7f")
|
5 |
+
db1 = client.get_database_by_api_endpoint(
|
6 |
"https://ab618096-30bc-47c4-85ac-1a97c75e746c-us-east-2.apps.astra.datastax.com"
|
7 |
)
|
8 |
+
coll1="p1"
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
client2= DataAPIClient("AstraCS:ZZUTCqocrzQiBhtvlEPfKqRq:b556beac8fc27ab35a3075db0d1fb34fde88872313673836f14ab3f5a1fb8438")
|
13 |
+
db2= client.get_database_by_api_endpoint(
|
14 |
+
"https://b4031b92-c3c2-46af-a2ff-bf39cd832d0a-us-east-2.apps.astra.datastax.com"
|
15 |
+
)
|
16 |
+
coll2="uq"
|
17 |
|
18 |
|
19 |
class DatabaseEngine():
|
20 |
def __init__(self):
|
21 |
pass
|
22 |
|
23 |
+
|
24 |
def Update(self,data):
|
25 |
|
26 |
+
collection=db1.get_collection(coll1)
|
27 |
collection.update_one(
|
28 |
{"_id": data["prompt"]},
|
29 |
{"$set": {"biological_context_alignment":data["biological_context_alignment"]}},
|
30 |
)
|
31 |
+
|
32 |
+
|
33 |
+
def GetData(self,promptversion):
|
34 |
+
|
35 |
+
collection1=db1.get_collection(coll1)
|
36 |
+
collection2=db2.get_collection(coll2)
|
37 |
+
|
38 |
+
promptdocument = collection1.find_one({"_id":promptversion})
|
39 |
+
|
40 |
+
|
41 |
+
contextdocument=collection2.find_one({"_id":promptversion})
|
42 |
+
responsedocument=collection2.find_one({"_id":promptversion})
|
43 |
+
|
44 |
+
|
45 |
+
return {
|
46 |
+
"prompt":promptdocument,
|
47 |
+
"context":contextdocument,
|
48 |
+
"response":responsedocument
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
|