前几天的 Google I/O 大会上,Google 宣布,其 Model Garden 和 Generative AI Studio 已可在 GCP Vertex AI 上公开预览,包括访问 PaLM for Text and Chat 和 Embeddings API for Text。
这一 Generative AI 新闻令人振奋。那么如何体验呢?快跟随马可君,使用您的 Google Cloud 账号登陆试用(如需账号,可点击阅读原文联系我们,快速获取 ),快速尝鲜吧!
打开 Google Cloud Console:
https://console.cloud.google.com/
前往 Vertext AI:
https://console.cloud.google.com/vertex-ai
在左侧菜单栏中,我们已经可以看到 Model Garden 和 Generative AI Studio 的相关选项。
在 Model Garden 中, Google 预置了众多模型,方便用户快速使用。
在 Generative AI Studio 中,用户目前可以使用 Language 和 Speech 的功能,但图片生成功能还需要再耐心等等。
那么如何通过编程的方式进行调用呢?
Python
安装 Vertex AI SDK for Python
在您的应用程序中使用以下代码请求模型响应
import vertexai
from vertexai.preview.language_models import TextGenerationModel
def predict_large_language_model_sample(
project_id: str,
model_name: str,
temperature: float,
max_decode_steps: int,
top_p: float,
top_k: int,
content: str,
location: str = "us-central1",
tuned_model_name: str = "",
) :
"""Predict using a Large Language Model."""
vertexai.init(project=project_id, location=location)
model = TextGenerationModel.from_pretrained(model_name)
if tuned_model_name:
model = model.get_tuned_model(tuned_model_name)
response = model.predict(
content,
temperature=temperature,
max_output_tokens=max_decode_steps,
top_k=top_k,
top_p=top_p,)
print(f"Response from Model: {response.text}")
predict_large_language_model_sample("project-id", "text-bison@001", 0.2, 768, 0.8, 40, '''Provide a brief summary for the following article:
LONDON, England (Reuters) -- Harry Potter star Daniel Radcliffe gains access to a reported £20 million ($41.1 million) fortune as he turns 18 on Monday, but he insists the money won\'t cast a spell on him. Daniel Radcliffe as Harry Potter in "Harry Potter and the Order of the Phoenix" To the disappointment of gossip columnists around the world, the young actor says he has no plans to fritter his cash away on fast cars, drink and celebrity parties. "I don\'t plan to be one of those people who, as soon as they turn 18, suddenly buy themselves a massive sports car collection or something similar," he told an Australian interviewer earlier this month. "I don\'t think I\'ll be particularly extravagant. "The things I like buying are things that cost about 10 pounds -- books and CDs and DVDs." At 18, Radcliffe will be able to gamble in a casino, buy a drink in a pub or see the horror film "Hostel: Part II," currently six places below his number one movie on the UK box office chart. Details of how he\'ll mark his landmark birthday are under wraps. His agent and publicist had no comment on his plans. "I\'ll definitely have some sort of party," he said in an interview. "Hopefully none of you will be reading about it." Radcliffe\'s earnings from the first five Potter films have been held in a trust fund which he has not been able to touch. Despite his growing fame and riches, the actor says he is keeping his feet firmly on the ground. "People are always looking to say \'kid star goes off the rails,\'" he told reporters last month. "But I try very hard not to go that way because it would be too easy for them." His latest outing as the boy wizard in "Harry Potter and the Order of the Phoenix" is breaking records on both sides of the Atlantic and he will reprise the role in the last two films. Watch I-Reporter give her review of Potter\'s latest » . There is life beyond Potter, however. The Londoner has filmed a TV movie called "My Boy Jack," about author Rudyard Kipling and his son, due for release later this year. He will also appear in "December Boys," an Australian film about four boys who escape an orphanage. Earlier this year, he made his stage debut playing a tortured teenager in Peter Shaffer\'s "Equus." Meanwhile, he is braced for even closer media scrutiny now that he\'s legally an adult: "I just think I\'m going to be more sort of fair game," he told Reuters. E-mail to a friend . Copyright 2007 Reuters. All rights reserved.This material may not be published, broadcast, rewritten, or redistributed.''', "us-central1")
Restful API方式
安装Google Cloud SDK Google Cloud SDK
进行身份认证
gcloud auth application-default login
输入以下内容以请求模型响应
API_ENDPOINT="us-central1-aiplatform.googleapis.com"
PROJECT_ID="project-id"
MODEL_ID="text-bison@001"
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://${API_ENDPOINT}/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/${MODEL_ID}:predict" -d \
$'{
"instances": [
{
"content": "Provide a brief summary for the following article:
LONDON, England (Reuters) -- Harry Potter star Daniel Radcliffe gains access to a reported £20 million ($41.1 million) fortune as he turns 18 on Monday, but he insists the money won\'t cast a spell on him. Daniel Radcliffe as Harry Potter in \\"Harry Potter and the Order of the Phoenix\\" To the disappointment of gossip columnists around the world, the young actor says he has no plans to fritter his cash away on fast cars, drink and celebrity parties. \\"I don\'t plan to be one of those people who, as soon as they turn 18, suddenly buy themselves a massive sports car collection or something similar,\\" he told an Australian interviewer earlier this month. \\"I don\'t think I\'ll be particularly extravagant. \\"The things I like buying are things that cost about 10 pounds -- books and CDs and DVDs.\\" At 18, Radcliffe will be able to gamble in a casino, buy a drink in a pub or see the horror film \\"Hostel: Part II,\\" currently six places below his number one movie on the UK box office chart. Details of how he\'ll mark his landmark birthday are under wraps. His agent and publicist had no comment on his plans. \\"I\'ll definitely have some sort of party,\\" he said in an interview. \\"Hopefully none of you will be reading about it.\\" Radcliffe\'s earnings from the first five Potter films have been held in a trust fund which he has not been able to touch. Despite his growing fame and riches, the actor says he is keeping his feet firmly on the ground. \\"People are always looking to say \'kid star goes off the rails,\'\\" he told reporters last month. \\"But I try very hard not to go that way because it would be too easy for them.\\" His latest outing as the boy wizard in \\"Harry Potter and the Order of the Phoenix\\" is breaking records on both sides of the Atlantic and he will reprise the role in the last two films. Watch I-Reporter give her review of Potter\'s latest » . There is life beyond Potter, however. The Londoner has filmed a TV movie called \\"My Boy Jack,\\" about author Rudyard Kipling and his son, due for release later this year. He will also appear in \\"December Boys,\\" an Australian film about four boys who escape an orphanage. Earlier this year, he made his stage debut playing a tortured teenager in Peter Shaffer\'s \\"Equus.\\" Meanwhile, he is braced for even closer media scrutiny now that he\'s legally an adult: \\"I just think I\'m going to be more sort of fair game,\\" he told Reuters. E-mail to a friend . Copyright 2007 Reuters. All rights reserved.This material may not be published, broadcast, rewritten, or redistributed."
}
],
"parameters": {
"temperature": 0.2,
"maxOutputTokens": 768,
"topP": 0.8,
"topK": 40
}
}'
本站资源部分来自网友投稿,如有侵犯你的权益请联系管理员或给邮箱发送邮件PubwinSoft@foxmail.com 我们会第一时间进行审核删除。
站内资源为网友个人学习或测试研究使用,未经原版权作者许可,禁止用于任何商业途径!请在下载24小时内删除!
如果遇到评论可下载的文章,评论后刷新页面点击“对应的蓝字按钮”即可跳转到下载页面!
本站资源少部分采用7z压缩,为防止有人压缩软件不支持7z格式,7z解压,建议下载7-zip,zip、rar解压,建议下载WinRAR。
温馨提示:本站部分付费下载资源收取的费用为资源收集整理费用,并非资源费用,不对下载的资源提供任何技术支持及售后服务。