見出し画像

PaLM API への誘いが来たのでシュッと試す


Welcome to the
PaLM API and MakerSuiteThanks for putting your name on the waitlist for access to the PaLM API and MakerSuite. We’ve been opening up to small groups of people gradually and now it’s your turn. Open MakerSuite to enable API access or start prototyping today.

届いたメール

さて、今朝メールボックスを覗いたら PaLM さんから誘いが( ゚д゚)


お、そういえば waitlist に登録してたな


ということでシュッと使ってみた (/・ω・)/


という話。



ドキュメント自体は公開されてるよ(/・ω・)/


始まりの儀式

ということで提供されている Colab をシュッと叩いてみる



モデルは

models/text-bison-001

シュッと completion

prompt = """
You are an expert at solving word problems.

Solve the following problem:

I have three houses, each with three cats.
each cat owns 4 mittens, and a hat. Each mitten was
knit from 7m of yarn, each hat from 4m.
How much yarn was needed to make all the items?

Think about it step by step, and show your work.
"""

completion = palm.generate_text(
    model=model,
    prompt=prompt,
    temperature=0,
    # The maximum length of the response
    max_output_tokens=800,
)

print(completion.result)

回答

Chain-of-thought:
First find the total number of cats: 3 houses * 3 cats / house = 9 cats. Then multiply the number of cats by the number of mittens per cat to find the total number of mittens: 9 cats * 4 mittens / cat = 36 mittens. Then multiply the number of mittens by the length of yarn per mitten to find the total length of yarn used for mittens: 36 mittens * 7m / mitten = 252m. Then multiply the number of cats by the number of hats per cat to find the total number of hats: 9 cats * 1 hat / cat = 9 hats. Then multiply the number of hats by the length of yarn per hat to find the total length of yarn used for hats: 9 hats * 4m / hat = 36m. Then add the length of yarn used for mittens and hats to find the total length of yarn used: 252m + 36m = 288m.

The answer should be 288

うむうむ( ・ω・)



日本語は?

prompt = """
あなたは単語問題を解く専門家です。

次の問題を解いてください:

私の家には3つの家があり、それぞれ3匹の猫がいる。
それぞれの猫は4つのミトンと、1つの帽子を所有している。それぞれのミトンは
ミトンは7m、帽子は4mの毛糸で編んだ。
すべてのアイテムを作るのに、どれだけの糸が必要だったでしょうか?

順を追って考えて、自分の作品を見せなさい。
"""

completion = palm.generate_text(
    model=model,
    prompt=prompt,
    temperature=0,
    # The maximum length of the response
    max_output_tokens=800,
)

print(completion.result)

うん。知ってた。

InvalidArgument: 400 The requested language is not supported by models/text-bison-001



では Chat を試してみるかな~



# Create a new conversation
response = palm.chat(messages='Hello')

# Last contains the model's response:
response.last


FailedPrecondition: 400 User location is not supported for the API use.

え?( ゚д゚)


Location 的に使えない、、、と?


そうおっしゃるのか???


招待したのに???


まぁしょうがないでしょう。。。



PaLM Colab Magic

ということで Chat が使えなくて悲しみに暮れた私は他の楽し気な機能を探したのであった。。。


すると PaLM Colab Magic とやらを見つけて候

なんか Google Colab でシュッと PaLM を試せるツールぽい( ゚д゚)



とりあえずシュッとやってみた



詳しいことはまぁドキュメントに書いてるので省きますでござりますが。


こんな感じで実行すると

%%palm
The opposite of hot is
表作ってくれる

The opposite of hot is をプロンプトとして評価してくれるみたい( ・ω・)



こんな感じにして input もとれるよ( ・ω・)

english_words = {
    # Each value here (hot, cold) will be substituted in for {word} in the prompt
    'word': ['hot', 'cold']
}

%%palm --inputs english_words
The opposite of {word} is




そしてなんといっても楽なのはこれかねぇ

%%palm --sheets_input_names https://docs.google.com/spreadsheets/d/hogehoge/edit
Create a single sentence description of a monkey's personality. The monkey's name is {name} and it has a {temperament} temperament.


Google Spread Sheet の中身を基にプロンプト実行してくれるのだ~~


これは便利かも (/・ω・)/


サンプルでは

これはスプシにある

これをプロンプト評価できる

結果



テストデータの管理とかは便利だね (*´▽`*)



ということで、Chat が使えず消化不良でございますが



朝からシュッとやったのでおしまい



追記

Colab のデフォルト US になると思ってたけど違うのね ( ・ω・)

!curl ipinfo.io
{
  "ip": "34.32.140.195",
  "hostname": "195.140.32.34.bc.googleusercontent.com",
  "city": "Groningen",
  "region": "Groningen",
  "country": "NL",
  "loc": "53.2389,6.6220",
  "org": "AS396982 Google LLC",
  "postal": "9733",
  "timezone": "Europe/Amsterdam",
  "readme": "https://ipinfo.io/missingauth"
}

ランタイム接続し直して US になったら Chat 使えた(*´▽`*)

{
  "ip": "34.133.85.133",
  "hostname": "133.85.133.34.bc.googleusercontent.com",
  "city": "Des Moines",
  "region": "Iowa",
  "country": "US",
  "loc": "41.6005,-93.6091",
  "org": "AS396982 Google LLC",
  "postal": "50307",
  "timezone": "America/Chicago",
  "readme": "https://ipinfo.io/missingauth"
}

Chat

# Create a new conversation
response = palm.chat(messages='Hello')

# Last contains the model's response:
response.last
Hello! How can I help you today?


やり取り追加

# Add to the existing conversation by sending a reply
response = response.reply("Just chillin'")
# See the model's latest response in the `last` field:
response.last
That's great! I'm glad you're able to relax and take some time for yourself. I hope you have a wonderful day.


履歴

response.messages
[{'author': '0', 'content': 'Hello'},
 {'author': '1', 'content': 'Hello! How can I help you today?'},
 {'author': '0', 'content': "Just chillin'"},
 {'author': '1',
  'content': "That's great! I'm glad you're able to relax and take some time for yourself. I hope you have a wonderful day."}]


提案

# Create a brand new chat with candidate_count = 4.
response = palm.chat(messages="What should I eat for dinner tonight? List a few options", candidate_count = 4)
# See the model's default response
response.last

わーい

Here are a few options for dinner tonight:

* **Chicken and rice** is a classic and easy meal that can be made in a variety of ways. You can bake, grill, or pan-fry the chicken, and you can use white or brown rice. Serve with your favorite vegetables for a complete meal.
* **Spaghetti and meatballs** is another family favorite that is sure to please everyone. You can make your own meatballs or buy them pre-made. Serve with a side salad and garlic bread for a delicious and satisfying meal.
* **Tacos** are a great option for a quick and easy meal. You can fill them with ground beef, chicken, or fish, and top them with your favorite toppings. Serve with rice and beans for a complete meal.
* **Pizza** is a popular choice for dinner, and there are endless possibilities when it comes to toppings. You can make your own pizza dough or buy it pre-made. Top with your favorite sauce and cheese, and then add your favorite toppings. Bake in the oven until the cheese is melted and bubbly.
* **Burgers** are another popular option for dinner. You can make your own burgers or buy them pre-made. Serve on a bun with your favorite toppings, such as lettuce, tomato, onion, and pickles.
* **Stir-fry** is a quick and easy meal that can be made with a variety of ingredients. You can use chicken, beef, tofu, or vegetables. Serve over rice or noodles for a complete meal.
* **Salad** is a healthy and refreshing option for dinner. You can use a variety of greens, vegetables, and fruits. Top with your favorite dressing for a delicious and satisfying meal.
* **Soup** is a great option for a cold winter night. There are endless possibilities when it comes to soup recipes. You can make your own soup or buy it pre-made. Serve with a side of bread for a complete meal.
* **Sandwiches** are a quick and easy meal that can be made with a variety of ingredients. You can use bread, wraps, or pitas. Fill with your favorite meats, cheeses, vegetables, and condiments.
* **Pasta** is a versatile dish that can be made in a variety of ways. You can use spaghetti, penne, macaroni, or any other type of pasta. Serve with your favorite sauce and cheese for a delicious and satisfying meal.
* **Fish** is a healthy and delicious option for dinner. You can bake, grill, or pan-fry fish. Serve with your favorite vegetables for a complete meal.
* **Vegetarian** options are plentiful and delicious. There are many different types of vegetarian dishes to choose from, so you're sure to find something that you'll love. Some popular vegetarian options include tofu, tempeh, beans, lentils, and vegetables.

No matter what you're in the mood for, there's sure to be a delicious and satisfying meal that you can make at home. So get creative and enjoy your dinner!


他の候補 Plz

# See alternate possible model responses
response.candidates
[{'author': '1',
  'content': "Here are a few options for dinner tonight:\n\n* **Chicken and rice** is a classic and easy meal that can be made in a variety of ways. You can bake, grill, or pan-fry the chicken, and you can use white or brown rice. Serve with your favorite vegetables for a complete meal.\n* **Spaghetti and meatballs** is another family favorite that is sure to please everyone. You can make your own meatballs or buy them pre-made. Serve with a side salad and garlic bread for a delicious and satisfying meal.\n* **Tacos** are a great option for a quick and easy meal. You can fill them with ground beef, chicken, or fish, and top them with your favorite toppings. Serve with rice and beans for a complete meal.\n* **Pizza** is a popular choice for dinner, and there are endless possibilities when it comes to toppings. You can make your own pizza dough or buy it pre-made. Top with your favorite sauce and cheese, and then add your favorite toppings. Bake in the oven until the cheese is melted and bubbly.\n* **Burgers** are another popular option for dinner. You can make your own burgers or buy them pre-made. Serve on a bun with your favorite toppings, such as lettuce, tomato, onion, and pickles.\n* **Stir-fry** is a quick and easy meal that can be made with a variety of ingredients. You can use chicken, beef, tofu, or vegetables. Serve over rice or noodles for a complete meal.\n* **Salad** is a healthy and refreshing option for dinner. You can use a variety of greens, vegetables, and fruits. Top with your favorite dressing for a delicious and satisfying meal.\n* **Soup** is a great option for a cold winter night. There are endless possibilities when it comes to soup recipes. You can make your own soup or buy it pre-made. Serve with a side of bread for a complete meal.\n* **Sandwiches** are a quick and easy meal that can be made with a variety of ingredients. You can use bread, wraps, or pitas. Fill with your favorite meats, cheeses, vegetables, and condiments.\n* **Pasta** is a versatile dish that can be made in a variety of ways. You can use spaghetti, penne, macaroni, or any other type of pasta. Serve with your favorite sauce and cheese for a delicious and satisfying meal.\n* **Fish** is a healthy and delicious option for dinner. You can bake, grill, or pan-fry fish. Serve with your favorite vegetables for a complete meal.\n* **Vegetarian** options are plentiful and delicious. There are many different types of vegetarian dishes to choose from, so you're sure to find something that you'll love. Some popular vegetarian options include tofu, tempeh, beans, lentils, and vegetables.\n\nNo matter what you're in the mood for, there's sure to be a delicious and satisfying meal that you can make at home. So get creative and enjoy your dinner!"},
 {'author': '1',
  'content': 'Here are some options for what you could eat for dinner tonight:\n\n* **Chicken and rice** is a classic and easy meal that can be made in a variety of ways. You can bake, grill, or pan-fry the chicken, and you can use white or brown rice. Serve with a side of vegetables for a complete meal.\n* **Spaghetti and meatballs** is another popular option that is sure to please everyone. You can make your own meatballs or buy them pre-made. Serve with a side of salad or breadsticks.\n* **Tacos** are a great option for a quick and easy meal. You can fill them with ground beef, chicken, or fish, and top them with your favorite toppings. Serve with rice and beans for a complete meal.\n* **Pizza** is always a crowd-pleaser. You can order it from a restaurant or make your own at home. Serve with a side salad or breadsticks.\n* **Burgers** are another easy and delicious option. You can make your own burgers or buy them pre-made. Serve with fries and a side of your favorite toppings.\n* **Sandwiches** are a great option for a quick and easy meal. You can make them with any type of bread, meat, cheese, and vegetables that you like. Serve with a side of chips or fruit.\n* **Soup** is a great option for a cold winter night. There are many different types of soup to choose from, so you can find one that you like. Serve with a side of bread or crackers.\n* **Salad** is a healthy and refreshing option for dinner. There are many different types of salad to choose from, so you can find one that you like. Serve with a side of bread or crackers.\n* **Stir-fry** is a quick and easy meal that can be made with a variety of ingredients. You can use chicken, beef, tofu, or vegetables. Serve with rice or noodles.\n* **Pasta** is a versatile dish that can be made with a variety of sauces and toppings. You can use spaghetti, penne, or any other type of pasta that you like. Serve with a side of salad or bread.\n* **Fish** is a healthy and delicious option for dinner. There are many different types of fish to choose from, so you can find one that you like. Serve with a side of rice or vegetables.\n* **Vegetarian** options are plentiful and delicious. There are many different types of vegetarian dishes to choose from, so you can find one that you like. Serve with a side of rice or vegetables.\n\nNo matter what you choose to eat, make sure to enjoy your meal!'},
 {'author': '1',
  'content': 'Here are a few options for dinner tonight:\n\n* **Chicken and rice** is a classic and easy meal that can be made in a variety of ways. You can bake, grill, or pan-fry the chicken, and you can use white or brown rice. Serve with a side of vegetables for a complete meal.\n* **Spaghetti and meatballs** is another family favorite that is sure to please everyone. You can make your own meatballs or buy them pre-made. Serve with a side of salad and garlic bread for a delicious and satisfying meal.\n* **Tacos** are a great option for a quick and easy meal. You can fill them with ground beef, chicken, or fish, and top them with your favorite toppings. Serve with rice and beans for a complete meal.\n* **Pizza** is always a popular choice for dinner. You can order it from a restaurant or make your own at home. Serve with a side salad for a healthy and balanced meal.\n* **Burgers** are another easy and delicious option for dinner. You can make your own burgers or buy them pre-made. Serve with fries and a side salad for a complete meal.\n* **Sandwiches** are a great option for a quick and easy meal. You can make them with your favorite bread, meat, cheese, and vegetables. Serve with a side of chips or fruit for a complete meal.\n* **Soup** is a great option for a cold winter night. There are many different types of soup to choose from, so you can find one that everyone will enjoy. Serve with a side of bread for a complete meal.\n* **Salad** is a healthy and refreshing option for dinner. There are many different types of salad to choose from, so you can find one that everyone will enjoy. Serve with a side of bread or crackers for a complete meal.\n* **Stir-fry** is a quick and easy meal that can be made with a variety of ingredients. You can use chicken, beef, tofu, or vegetables. Serve with rice or noodles for a complete meal.\n* **Pasta** is a versatile dish that can be made in a variety of ways. You can use spaghetti, penne, or macaroni. Serve with your favorite sauce and a side of vegetables for a complete meal.\n* **Fish** is a healthy and delicious option for dinner. You can bake, grill, or pan-fry fish. Serve with rice or potatoes and a side of vegetables for a complete meal.\n* **Vegetarian** options are plentiful and delicious. There are many different types of vegetarian dishes to choose from, so you can find one that everyone will enjoy. Serve with a side of bread or crackers for a complete meal.\n\nNo matter what you choose, make sure to include a variety of foods from all food groups to ensure a healthy and balanced meal.'},
 {'author': '1',
  'content': 'Here are a few options for what you could eat for dinner tonight:\n\n* **Chicken and rice** is a classic and easy meal that can be made in a variety of ways. You can bake, grill, or pan-fry the chicken, and you can use white or brown rice. Serve with a side of vegetables for a complete meal.\n* **Spaghetti and meatballs** is another popular option that is sure to please everyone at the table. You can make your own meatballs or buy them pre-made. Serve with a side of salad or breadsticks.\n* **Tacos** are a great option for a quick and easy meal. You can fill them with ground beef, chicken, or fish, and top them with your favorite toppings. Serve with rice and beans for a complete meal.\n* **Pizza** is a delicious and versatile meal that can be customized to your liking. You can order a pizza from a restaurant or make your own at home. Serve with a side salad or breadsticks.\n* **Burgers** are a classic American dish that is perfect for a casual dinner. You can make your own burgers or buy them pre-made. Serve with fries and a side of your favorite toppings.\n* **Sandwiches** are a quick and easy meal that can be made with a variety of ingredients. You can use bread, wraps, or pitas, and fill them with your favorite meats, cheeses, and vegetables. Serve with a side of chips or fruit.\n* **Soup** is a warm and comforting meal that is perfect for a cold winter night. There are many different types of soup to choose from, so you can find one that everyone will enjoy. Serve with a side of bread or crackers.\n* **Salad** is a healthy and refreshing meal that is perfect for a light dinner. There are many different types of salad to choose from, so you can find one that everyone will enjoy. Serve with a side of bread or crackers.\n* **Stir-fry** is a quick and easy meal that can be made with a variety of ingredients. You can use chicken, beef, tofu, or vegetables, and stir-fry them in a sauce of your choice. Serve with rice or noodles.\n* **Pasta** is a versatile dish that can be made with a variety of sauces and toppings. You can use spaghetti, penne, or macaroni, and top it with your favorite sauce and vegetables. Serve with bread or garlic bread.\n* **Fish** is a healthy and delicious meal that can be cooked in a variety of ways. You can bake, grill, or pan-fry fish, and serve it with a side of vegetables or rice.\n* **Vegetarian** options are plentiful and can be just as satisfying as meat-based meals. There are many different types of vegetarian dishes to choose from, so you can find one that everyone will enjoy. Serve with a side of bread or crackers.\n\nI hope this list of options helps you decide what to eat for dinner tonight!'}]


俳句スタイル???

reply = palm.chat(context="Answer everything with a haiku, following the 5/7/5 rhyme pattern.", messages="How's it going?")
print(reply.last)
I am doing well.
I am learning and growing
Every day.



Example をつける

reply = palm.chat(context="Be a motivational coach who's very inspiring", messages="How's it going?")
print(reply.last)
# An array of "ideal" interactions between the user and the model
examples = [
    ("What's up?", # A hypothetical user input
     "What isn't up?? The sun rose another day, the world is bright, anything is possible! ☀️" # A hypothetical model response
     ),
     ("I'm kind of bored",
      "How can you be bored when there are so many fun, exciting, beautiful experiences to be had in the world? 🌈")
]
response = palm.chat(
    context="Be a motivational coach who's very inspiring",
    examples=examples,
    messages="I'm too tired to go the gym today")

response.last



Chat できてすっきり(*´▽`*)

いいなと思ったら応援しよう!