瀏覽代碼

feat: Support for Vertex AI - load Default Application Configuration (#4641)

Co-authored-by: miendinh <miendinh@users.noreply.github.com>
Co-authored-by: crazywoola <427733928@qq.com>
tags/0.6.9
miendinh 1 年之前
父節點
當前提交
f804adbff3
沒有連結到貢獻者的電子郵件帳戶。

+ 5
- 2
api/core/model_runtime/model_providers/vertex_ai/llm/llm.py 查看文件

config_kwargs["stop_sequences"] = stop config_kwargs["stop_sequences"] = stop


service_account_info = json.loads(base64.b64decode(credentials["vertex_service_account_key"])) service_account_info = json.loads(base64.b64decode(credentials["vertex_service_account_key"]))
service_accountSA = service_account.Credentials.from_service_account_info(service_account_info)
project_id = credentials["vertex_project_id"] project_id = credentials["vertex_project_id"]
location = credentials["vertex_location"] location = credentials["vertex_location"]
aiplatform.init(credentials=service_accountSA, project=project_id, location=location)
if service_account_info:
service_accountSA = service_account.Credentials.from_service_account_info(service_account_info)
aiplatform.init(credentials=service_accountSA, project=project_id, location=location)
else:
aiplatform.init(project=project_id, location=location)


history = [] history = []
system_instruction = GEMINI_BLOCK_MODE_PROMPT system_instruction = GEMINI_BLOCK_MODE_PROMPT

+ 10
- 6
api/core/model_runtime/model_providers/vertex_ai/text_embedding/text_embedding.py 查看文件

:return: embeddings result :return: embeddings result
""" """
service_account_info = json.loads(base64.b64decode(credentials["vertex_service_account_key"])) service_account_info = json.loads(base64.b64decode(credentials["vertex_service_account_key"]))
service_accountSA = service_account.Credentials.from_service_account_info(service_account_info)
project_id = credentials["vertex_project_id"] project_id = credentials["vertex_project_id"]
location = credentials["vertex_location"] location = credentials["vertex_location"]
aiplatform.init(credentials=service_accountSA, project=project_id, location=location)
if service_account_info:
service_accountSA = service_account.Credentials.from_service_account_info(service_account_info)
aiplatform.init(credentials=service_accountSA, project=project_id, location=location)
else:
aiplatform.init(project=project_id, location=location)


client = VertexTextEmbeddingModel.from_pretrained(model) client = VertexTextEmbeddingModel.from_pretrained(model)



embeddings_batch, embedding_used_tokens = self._embedding_invoke( embeddings_batch, embedding_used_tokens = self._embedding_invoke(
client=client, client=client,
texts=texts texts=texts
""" """
try: try:
service_account_info = json.loads(base64.b64decode(credentials["vertex_service_account_key"])) service_account_info = json.loads(base64.b64decode(credentials["vertex_service_account_key"]))
service_accountSA = service_account.Credentials.from_service_account_info(service_account_info)
project_id = credentials["vertex_project_id"] project_id = credentials["vertex_project_id"]
location = credentials["vertex_location"] location = credentials["vertex_location"]
aiplatform.init(credentials=service_accountSA, project=project_id, location=location)
if service_account_info:
service_accountSA = service_account.Credentials.from_service_account_info(service_account_info)
aiplatform.init(credentials=service_accountSA, project=project_id, location=location)
else:
aiplatform.init(project=project_id, location=location)


client = VertexTextEmbeddingModel.from_pretrained(model) client = VertexTextEmbeddingModel.from_pretrained(model)



+ 2
- 2
api/core/model_runtime/model_providers/vertex_ai/vertex_ai.yaml 查看文件

en_US: Enter your Google Cloud Location en_US: Enter your Google Cloud Location
- variable: vertex_service_account_key - variable: vertex_service_account_key
label: label:
en_US: Service Account Key
en_US: Service Account Key (Leave blank if you use Application Default Credentials)
type: secret-input type: secret-input
required: true
required: false
placeholder: placeholder:
en_US: Enter your Google Cloud Service Account Key in base64 format en_US: Enter your Google Cloud Service Account Key in base64 format

Loading…
取消
儲存