3
3
import json
4
4
from firebase_admin import initialize_app
5
5
from firebase_functions import https_fn , options
6
+ import os
6
7
7
8
initialize_app ()
8
9
app = Flask (__name__ )
@@ -12,8 +13,14 @@ def is_intersection(keys, required_keys):
12
13
return (keys & required_keys ) == required_keys
13
14
14
15
16
+ def set_openai_api_key ():
17
+ if os .environ .get ("OPENAI_DEV" ) != None :
18
+ os .environ ["OPENAI_API_KEY" ] = os .environ ["OPENAI_DEV" ]
19
+
20
+
15
21
@app .route ("/summary" , methods = ["POST" ])
16
22
def summary ():
23
+ set_openai_api_key ()
17
24
body = json .loads (request .data )
18
25
# We require bill_id, bill_title, bill_text to exist as keys in the POST
19
26
if not is_intersection (body .keys (), {"bill_id" , "bill_title" , "bill_text" }):
@@ -28,8 +35,10 @@ def summary():
28
35
29
36
return jsonify (summary ["summary" ])
30
37
38
+
31
39
@app .route ("/tags" , methods = ["POST" ])
32
40
def tags ():
41
+ set_openai_api_key ()
33
42
body = json .loads (request .data )
34
43
# We require bill_id, bill_title, bill_text to exist as keys in the POST
35
44
# Note: & is essentially set intersection
@@ -43,11 +52,15 @@ def tags():
43
52
44
53
return jsonify (tags ["tags" ])
45
54
55
+
46
56
@app .route ("/ready" , methods = ["GET" ])
47
57
def ready ():
48
58
return ""
49
59
50
- @https_fn .on_request (secrets = ["OPENAI_DEV" ], timeout_sec = 300 , memory = options .MemoryOption .GB_1 )
60
+
61
+ @https_fn .on_request (
62
+ secrets = ["OPENAI_DEV" ], timeout_sec = 300 , memory = options .MemoryOption .GB_1
63
+ )
51
64
def httpsflaskexample (req : https_fn .Request ) -> https_fn .Response :
52
65
with app .request_context (req .environ ):
53
66
return app .full_dispatch_request ()
0 commit comments