見出し画像

Vertex AI API をシュッと

今朝メールをチェックしたら Google さんからお便り来てました

Trusted Tester Program News and Resources

お? Trusted Tester Program 開始したんか?

と思ったらただのニュースレターでした (´・ω・`)
> Trusted Tester Program News and Resources

ただまぁ Google/generative-ai の GitHub Repository が案内されていたので取りえず。覗いてみる。

Welcome to the Google Cloud Generative AI repository.

This repository contains notebooks and content that demonstrate how to use, develop and manage generative AI workflows using Generative AI, powered by Vertex AI on Google Cloud.

https://github.com/GoogleCloudPlatform/generative-ai/

ふーん。

というわけでせっかくなので使ったことない Vertex AI をシュッと試してみた。

基本 README 記載の手順でサクサク進めます

まずは Setup

ざっくり言うと自分の GCP にログインして必要な API を有効化するだけ

したら後は Colab とかでコードぺちぺちするだけ。

from google.colab import auth
auth.authenticate_user()
!git clone https://github.com/GoogleCloudPlatform/generative-ai.git
!pip install google-cloud-aiplatform --upgrade
PROJECT_ID = "YOUR_GCP_PROJECT_ID"
LOCATION = "us-central1" #e.g. 日本リージョンは未対応だった!

import vertexai
vertexai.init(project=PROJECT_ID, location=LOCATION)
import pandas as pd
from vertexai.preview.language_models import TextGenerationModel
generation_model = TextGenerationModel.from_pretrained("text-bison@001")

Examples があったのでまんま実行

prompt = """Q: Who was President of the United States in 1955? Which party did he belong to?\n
            A:
         """
print(
    generation_model.predict(
        prompt,
        max_output_tokens=256,
        temperature=0.1,
    ).text
)
Dwight D. Eisenhower, Republican

prompt = """
Context:
The term "artificial intelligence" was first coined by John McCarthy in 1956. Since then, AI has developed into a vast
field with numerous applications, ranging from self-driving cars to virtual assistants like Siri and Alexa.

Question:
What is artificial intelligence?

Answer:
Artificial intelligence refers to the simulation of human intelligence in machines that are programmed to think and learn like humans.

---

Context:
The Wright brothers, Orville and Wilbur, were two American aviation pioneers who are credited with inventing and
building the world's first successful airplane and making the first controlled, powered and sustained heavier-than-air human flight,
 on December 17, 1903.

Question:
Who were the Wright brothers?

Answer:
The Wright brothers were American aviation pioneers who invented and built the world's first successful airplane
and made the first controlled, powered and sustained heavier-than-air human flight, on December 17, 1903.

---

Context:
The Mona Lisa is a 16th-century portrait painted by Leonardo da Vinci during the Italian Renaissance. It is one of
the most famous paintings in the world, known for the enigmatic smile of the woman depicted in the painting.

Question:
Who painted the Mona Lisa?

Answer:

"""
print(
    generation_model.predict(
        prompt,
    ).text
)
Leonardo da Vinci painted the Mona Lisa during the Italian Renaissance.

うん。いいね。

prompt = "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"

print(
    generation_model.predict(
        prompt, temperature=0.2, max_output_tokens=256, top_k=1, top_p=0.8
    ).text
)
* **Dried & Lovely**
* **Dried Blooms**
* **Dried Florals**
* **Dried Arrangements**
* **Dried Bouquets**
* **Dried Flowers**
* **Preserved Flowers**
* **Forever Flowers**
* **Immortal Flowers**
* **Timeless Flowers**
* **Seasonal Flowers**
* **Annual Flowers**
* **Perennial Flowers**
* **Herbal Flowers**
* **Aromatic Flowers**
* **Fragrant Flowers**
* **Scented Flowers**
* **Sweet Flowers**
* **Beautiful Flowers**
* **Lovely Flowers**
* **Gorgeous Flowers**
* **Magnificent Flowers**
* **Exquisite Flowers**
* **Dainty Flowers**
* **Delicate Flowers**
* **Graceful Flowers**
* **Subtle Flowers**
* **Elegant Flowers**
* **Sophisticated Flowers**
* **Romantic Flowers**
* **Chic Flowers**
* **Vintage Flowers**
* **Rustic Flowers**
* **Modern Flowers**
* **Contemporary Flowers**
* **Ec

うんうん。

prompt = """
Answer the question using the text below. Respond with only the text provided.
Question: What should I do to fix my disconnected WiFi? The light on my Google WiFi router is yellow and blinking slowly.

Text:
Color: No light
What it means: Router has no power or the light was dimmed in the app.
What to do:
Check that the power cable is properly connected to your router and to a working wall outlet.
If your device is already set up and the light appears off, check your light brightness settings in the app.
If there's still no light, contact WiFi customer support.

Color: Solid white, no light, solid white
What it means: Device is booting up.
What to do:
Wait for the device to boot up. This takes about a minute. When it's done, it will slowly pulse white, letting you know it's ready for setup.

Color: Slow-pulsing white
What it means: Device is ready for set up.
What to do:
Use the Google Home app to set up your router.

Color: Solid white
What it means: Router is online and all is well.
What to do:
You're online. Enjoy!

Color: Slowly pulsing yellow
What it means: There is a network error.
What to do:
Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.

Color: Fast blinking yellow
What it means: You are holding down the reset button and are factory resetting this device.
What to do:
If you keep holding down the reset button, after about 12 seconds, the light will turn solid yellow. Once it is solid yellow, let go of the factory reset button.

Color: Solid yellow
What it means: Router is factory resetting.
What to do:
This can take up to 10 minutes. When it's done, the device will reset itself and start pulsing white, letting you know it's ready for setup.
Image Solid red light Solid red Something is wrong. Critical failure. Factory reset the router. If the light stays red, contact WiFi customer support.
"""

print(
    generation_model.predict(
        prompt, temperature=0.2, max_output_tokens=256, top_k=1, top_p=0.8
    ).text
)
There is a network error.
Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.

いいですねぇ。

QA/成分抽出/アイディア出し等いろいろ賢そうだ

よっしゃ次は日本語で!!

prompt = """Q: 日本の首都は?\n
            A:
         """
print(
    generation_model.predict(
        prompt,
        max_output_tokens=256,
        temperature=0.1,
    ).text
)
  

ん?

prompt = """Q: アメリカの大統領は?\n
            A:
         """
print(
    generation_model.predict(
        prompt,
        max_output_tokens=256,
        temperature=0.1,
    ).text
)
 

( ゚Д゚)

日本語は非対応なのね、、、

prompt = """Q: Who is The Priminister of Japan?\n
            A:
         """
print(
    generation_model.predict(
        prompt,
        max_output_tokens=256,
        temperature=0.1,
    ).text
)
Shinzō Abe

うん。

prompt = """Q: Who is The Priminister of Japan? Translate it in Japanese\n
            A:
         """
print(
    generation_model.predict(
        prompt,
        max_output_tokens=256,
        temperature=0.1,
    ).text
)
 

翻訳もだめか、、、

まぁ、そんなもんだよね(*´▽`*)

ということでおしまい。

この記事が気に入ったらサポートをしてみませんか?