昨天修好了 SDK ,今天來把服務都部屬好再測試一次,並花點時間做一下權限控管。
把 Vertex AI Python SDK 修好後要調整一下 requirements.txt
,畢竟還沒 Merge 前官方的 Package 還是壞的,將 google-cloud-aiplatform
指向自己修改好的 GitHub repository :
google-cloud-aiplatform[adk,agent_engines] @ git+https://github.com/uncured7036/python-aiplatform.git@fix-async_stream_query
部屬好後就可以用之前寫的腳本測試一下:
回應比較久是 Auto-Scaling 的關係,如果再請求一次:
每個請求都在 20 秒左右,也差不多是 Agent 回應一次的時間。
多虧這兩天做的測試,花了 170 塊台幣 _(:ì」∠)_
。
接下來檢查一下各項設定有沒有問題,之前一直都有注意到部屬用的帳號沒有劃分權限,在 Cloud Run 頁面會看到 Security 標示:
點一下就可以為服務新增角色,但因為不知道要選什麼樣的權限測試了許久,一開始遇到錯誤:
ERROR: (gcloud.run.services.update) PERMISSION_DENIED: Permission 'run.services.get' denied on resource '...' (or resource may not exist). This command is authenticated as xxxx which is the active account specified by the [core/account] property.
花了很多時間問 Gemini 要怎麼設定,在不斷測試的過程中發現可以在 Cloud Build 頁面裡面直接 Rebuild ,不然一直都傻傻的亂 Commit 和 Push 。另外在 Cloud Run 頁面也可以按編輯可以重新部屬。
測試了非常久,後來先把權限調到跟原本設定的一樣大,然後問 Gemini 哪些可以減少,最後調整出來的角色要有:
要注意的是這個 Vertex AI User ,因為 API Server 初始化時使用到 Vertex AI SDK ,但只要沒有設定這個角色程式會噴這個錯誤:
}
metadata {
key: "permission"
value: "aiplatform.reasoningEngines.get"
}
導致服務起不來造成另一個錯誤:
Step #2 - "Deploy": ERROR: (gcloud.run.services.update) Revision 'xxxx' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.
到目前為止已經減少了幾個權限,但 Security 警示燈泡還是沒有熄滅,明天再繼續看看怎麼處理。