准备工作
确保您已在“模型端点管理”中注册模型端点。如需了解详情,请参阅使用模型端点管理服务注册模型端点
调用通用模型的预测
使用 google_ml.predict_row()
SQL 函数调用已注册的通用模型端点以调用预测。
SELECT
google_ml.predict_row(
model_id => 'MODEL_ID',
request_body => 'REQUEST_BODY');
替换以下内容:
MODEL_ID
:您在注册模型端点时定义的模型 ID。REQUEST_BODY
:预测函数的参数,采用 JSON 格式。
示例
本部分包含一些使用已注册的模型端点调用预测的示例。
如需为已注册的 gemini-1.5-pro:streamGenerateContent
模型端点生成预测,请运行以下语句:
SELECT
json_array_elements( google_ml.predict_row( model_id => 'gemini-1.5-pro:streamGenerateContent',
request_body => '{ "contents": [ { "role": "user", "parts": [ { "text": "For TPCH database schema as mentioned here https://www.tpc.org/TPC_Documents_Current_Versions/pdf/TPC-H_v3.0.1.pdf , generate a SQL query to find all supplier names which are located in the India nation." } ] } ] }'))-> 'candidates' -> 0 -> 'content' -> 'parts' -> 0 -> 'text';
如需为 Hugging Face 上已注册的 facebook/bart-large-mnli
模型端点生成预测,请运行以下语句:
SELECT
google_ml.predict_row(
model_id => 'facebook/bart-large-mnli',
request_body =>
'{
"inputs": "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!",
"parameters": {"candidate_labels": ["refund", "legal", "faq"]}
}'
);
如需为已注册的 Anthropic claude-3-opus-20240229
模型端点生成预测,请运行以下语句:
SELECT
google_ml.predict_row('anthropic-opus', '{
"model": "claude-3-opus-20240229",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello, world"}
]
}');