Skip to content

Commit

Permalink
Refactor main.py to update Firebase Admin SDK initialization and impr…
Browse files Browse the repository at this point in the history
…ove error handling
  • Loading branch information
kkdai committed Jul 12, 2024
1 parent c02f7ab commit beeeef8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@
這是所有的名片資料,請根據輸入文字來查詢相關的名片資料 {all_cards},例如: 名字, 職稱, 公司名稱。 查詢問句為: {msg}, 只要回覆我找到的 JSON Data 就好。
'''

# 使用默認應用憑證初始化 Firebase Admin SDK
cred = credentials.ApplicationDefault()
# firebase URL
firebase_url = os.environ['FIREBASE_URL']
# 从环境变量中读取服务账户密钥 JSON 内容
service_account_info = json.loads(os.environ['GOOGLE_CREDENTIALS'])
# 使用服务账户密钥 JSON 内容初始化 Firebase Admin SDK
cred = credentials.Certificate(service_account_info)
firebase_admin.initialize_app(
cred, {'databaseURL': 'https://line-vertex-default-rtdb.firebaseio.com/'})
cred, {'databaseURL': firebase_url})

# 初始化 Firestore 客戶端
db = firestore.client()
Expand Down Expand Up @@ -70,7 +74,7 @@
genai.configure(api_key=gemini_key)


@app.post("/")
@ app.post("/")
async def handle_callback(request: Request):
signature = request.headers['X-Line-Signature']

Expand Down

0 comments on commit beeeef8

Please sign in to comment.