2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RuruCun個人開発Advent Calendar 2023

Day 14

Gemini ProのAPIが提供されたので試してみる

Posted at

背景

Google AI Studioで、APIKeyを手に入れる

Google AI Studioヘアクセスする

サイトへアクセスし、「Get API key in Google AI Studio」でGoggleAIStudioへアクセス。

image.png

利用規約へ同意する

image.png

API Keyを手に入れる

サイドバーの「Get API Key」へアクセス。

image.png

「Create API key in new project」をクリック

image.png

しばらく待つと、下記のモーダルにAPI keyが表示されるので、Copyを押して保存しておきます。

image.png

簡単にAPIKeyを試す。

APIKey生成後に、下記の簡単にテストできるcurlが表示されるので、こちらでAPIKeyが正常に動くか試します。

image.png

ターミナルで下記を叩いてみます。

curl \
-H 'Content-Type: application/json' \
-d '{ "prompt": { "text": "Write a story about a magic backpack"} }' \
"https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=コピーしたKey"

APIKeyが正しければ、下記のようにAIが考えた物語が帰ってきます。

{
  "candidates": [
    {
      "output": "Once upon a time, there was a young boy named Billy who loved to go on adventures. He would often explore the woods near his house, looking for new and exciting things to see. One day, Billy was exploring the woods when he came across a strange backpack. It was sitting on a rock, and it looked like it had been abandoned. Billy picked up the backpack and examined it. It was made of a strange material that he didn't recognize, and it had a few straps and a zipper. Billy opened the zipper and peered inside. The backpack was filled with all sorts of strange and wonderful things. There were maps, compasses, telescopes, binoculars, and even a few magic items. Billy was amazed. He had never seen anything like it before.\n\nBilly decided to take the backpack home with him. He couldn't wait to show his friends all the amazing things he had found. When he got home, he showed his friends the backpack. They were all amazed by it, too. They started to play with all the different items, and they had a lot of fun.\n\nOne of the items in the backpack was a magic map. The map showed all the different places in the world that Billy could visit. Billy decided that he wanted to use the map to go on an adventure. He packed his things and set off on his journey.\n\nBilly traveled all over the world. He visited different countries, met new people, and had many exciting experiences. He used the magic items in the backpack to help him on his adventures. He used the maps to find his way, the compasses to stay on course, and the telescopes and binoculars to see faraway places.\n\nBilly had the time of his life on his adventures. He learned a lot about the world, and he made many new friends. He also learned a lot about himself. He learned that he was braver and more resourceful than he thought he was.\n\nWhen Billy finally returned home, he was a different person. He was more confident and more adventurous. He was also more grateful for the things he had. He knew that he had been lucky to have the opportunity to go on such an amazing journey.\n\nBilly continued to use the magic backpack on his future adventures. He went to all sorts of amazing places and had many more exciting experiences. He learned a lot about the world, and he made many more friends. He also learned a lot about himself. He learned that he was capable of anything he set his mind to.\n\nThe magic backpack was a gift that Billy would never forget. It gave him the opportunity to have the adventure of a lifetime. It also taught him a lot about himself and the world around him.",
      "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"
        }
      ]
    }
  ]
}

これで無事、APIKeyを手に入れて、curlからGeminiProのAPIを叩くことができました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?