🌴

GoogleのPaLM APIを呼ぶ方法

2023/11/17に公開

あんまり情報なかったのでメモ。

MakerSuite ってのを使ったらいいだけっぽいけど、そこに辿り着くまでのメモ。
MakerSuite

まず、ここにアクセス。API のドキュメント。
Get an API key  |  PaLM API  |  Generative AI for Developers

Get an API keyをクリック

project 作るかとか聞かれるのでぽちぽちしていく。

Create API key in new projectをクリック

こんな感じで試してみる。

PALM_KEY="YOUR KEY HERE"
curl -H 'Content-Type: application/json' \
     -d '{"prompt": {text: "Give me five subcategories of jazz"} }' \
     "https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=${PALM_KEY}"

こんな感じで返ってきた。

{
  "candidates": [
    {
      "output": "* **Swing:** Jazz that originated in the 1930s and is characterized by a strong beat and a focus on improvisation. Some famous swing musicians include Louis Armstrong, Benny Goodman, and Ella Fitzgerald.\n* **Bebop:** Jazz that originated in the 1940s and is characterized by fast tempos, complex chord progressions, and virtuosic solos. Some famous bebop musicians include Charlie Parker, Dizzy Gillespie, and Thelonious Monk.\n* **Cool jazz:** Jazz that originated in the 1950s and is characterized by a relaxed, laid-back feel. Some famous cool jazz musicians include Miles Davis, Chet Baker, and Gerry Mulligan.\n* **Hard bop:** Jazz that originated in the 1950s and is characterized by a more aggressive and rhythmic style than cool jazz. Some famous hard bop musicians include Art Blakey, Horace Silver, and Freddie Hubbard.\n* **Free jazz:** Jazz that originated in the 1960s and is characterized by its lack of structure and its emphasis on improvisation. Some famous free jazz musicians include Ornette Coleman, John Coltrane, and Cecil Taylor.",
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_DEROGATORY",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_TOXICITY",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_VIOLENCE",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_SEXUAL",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_MEDICAL",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ]
}

OpenAI 以外の LLM の API ってどんなんかなと思って触ってみた。
やってみればシンプルだけど、たどりつくのに少し時間がかかった。
いまいち、GCP のアカウントの連携具合がよくわからない。気が向いた時にまた調べてみよう。

GitHubで編集を提案

Discussion