見出し画像

【Google Gemini Pro API: 概要と活用法】英語解説を日本語で読む【2023年12月16日|@Prompt Engineering】

この動画では、Googleが新しいGemini ProモデルのAPIアクセスを公開したことを紹介しています。Gemini Proはビジョンとテキストの両方を扱える強力なモデルで、Python SDKを使用して操作する方法が説明されています。このAPIは無料で利用できる範囲があり、画像処理も可能です。さらに、Gemini Proはテキスト生成やチャットモデルとしても使え、Google AI Studioで利用できます。安全設定で有害なコンテンツを制御することもできます。Gemini Proは多くのアプリケーションで活用される可能性を秘めています。
公開日:2023年12月16日
※動画を再生してから読むのがオススメです。


Google just opened API access to their Gemini Pro Models to the public, and the best part is you can test this for absolutely free.

GoogleはGemini ProモデルへのAPIアクセスを一般に公開しました。そして、最高の部分は、これを完全に無料でテストできることです。

We're going to look at the pricing in a little bit, but Gemini Pro is the second best model from Google, and it's a multimodal model.

価格についてはこれから少し見ていきますが、Gemini ProはGoogleの2番目に優れたモデルで、マルチモーダルモデルです。

In this video, I'll show you how to use both the vision as well as the text version of Gemini Pro through their Python SDK.

このビデオでは、Gemini ProのPython SDKを通して、ビジョンとテキストバージョンの両方を使用する方法をお見せします。

Gemini Pro already has Integrations with tools like LangChain and LlamaIndex, that means that you can build rag pipelines on top of Gemini Pro.

Gemini Proには、LangChainやLlamaIndexのようなツールとの統合がすでにあり、Gemini Proの上にラグパイプラインを構築することができます。

We will cover that in a later video.

その件については、後のビデオで取り上げます。

Before showing you how to use this in your own projects, let's talk about the API pricing.

自分のプロジェクトでこれを使う方法を紹介する前に、APIの価格について話そう。

On their pricing page, they say priced to help you bring your app to the world.

Geminiの価格設定ページには、あなたのアプリを世に送り出すための価格設定と書かれている。

If you're making less than 60 queries per minute, it's absolutely free for everyone to use at the moment, both in terms of the input as well as the output.

もしあなたが1分間に60回以下のクエリーを行うのであれば、入力も出力も、今のところ誰でも無料で使うことができる。

The only catch is that Google will use this data, both the input data that you provide as well as the output from the model, to improve their products.

唯一の問題は、Googleがこのデータを、あなたが提供した入力データとモデルからの出力の両方を、製品の改良のために使用することです。

If you need more than 60 queries per minute, you can opt into pay as well.

1分間に60以上のクエリが必要な場合は、有料にすることもできる。

That is not yet available, but I think it's going to be available pretty soon.

これはまだ利用できませんが、かなり近いうちに利用できるようになると思います。

In terms of the price, both for the input as well as output tokens, it's actually pretty good compared to something like GPT-3.5.

価格に関しては、入力トークン、出力トークンともに、GPT-3.5のようなものと比べると、かなりいい。

So here is the price for GPT-3.5 turbo, and if you compare the price of Gemini Pro, it's actually in order of magnitude lower than GPT-3.5 turbo.

これはGPT-3.5ターボの価格ですが、Gemini Proの価格を比較すると、GPT-3.5ターボよりも桁違いに安いです。

And you also have the ability to process images.

また、画像を処理する能力もあります。

Again, if you compare the Gemini Pro Vision model with GPT-4 vision preview model, the price for image completion is also lower.

繰り返しになりますが、Gemini Pro VisionモデルとGPT-4 vision previewモデルを比較すると、画像補完の価格も安くなっています。

Now, just like OpenAI, if you pay for Gemini Pro API usage, then Google is not going to use both your input as well as output data to train or improve their products.

さて、OpenAIのように、Gemini Pro API使用料を支払えば、Googleは、あなたの入力データと出力データの両方を、彼らの製品のトレーニングや改良のために使用することはありません。

So again, the best part is it's absolutely free if you are just getting started.

繰り返しになるが、Gemini Proの最大の魅力は、これから始めるのであれば完全に無料であるということだ。

Now let me show you how to use this.

それでは、使い方をお見せしましょう。

Gemini Pro is currently available within the Google AI Studio, which used to be called MakerSuite.

Gemini Proは現在、Google AI Studio(以前はMakerSuiteと呼ばれていた)の中で利用できる。

Within the Google AI Studio, you can test the models.

Google AI Studioでは、モデルをテストすることができる。

Currently, there are two different models available.

現在、2種類のモデルが用意されている。

One is the Gemini Pro, which is the text model.

1つはGemini Proで、テキストモデルである。

The second one is Gemini Pro Vision, which has the ability to understand images.

もう1つはGemini Pro Visionで、画像を理解する能力を持つ。

You can experiment with both of these models in here.

ここではこの2つのモデルを試すことができる。

It's just like the OpenAI Playground.

これはOpenAI Playgroundと同じです。

However, if you want to use these models within your own applications, then you will need to create an API key and use that in your own code base.

ただし、これらのモデルを自分のアプリケーションで使いたい場合は、APIキーを作成し、それを自分のコードベースで使用する必要がある。

Before looking at that, let's just experiment with the models here and let me show you a few very interesting options that Google has added.

それを見る前に、ここでモデルを試してみましょう。Googleが追加したいくつかの非常に興味深いオプションを紹介します。

Okay, so I'm going to use this test prom, What is the meaning of life?

では、このテストプロムを使って、「人生の意味とは?

just to look at the output.

というテストプロムを使って出力を見てみましょう。

Now, in this video, we're not looking at comparing the output from Gemini Pro to something like GPT-3.5 or GPT-4.

このビデオでは、Gemini Proの出力をGPT-3.5やGPT-4のようなものと比較するわけではない。

I'm going to create a subsequent video on that.

それについては、次のビデオを作成するつもりだ。

The goal of this video is just to show you how to use Gemini Pro in your own projects using the Python SDK.

このビデオのゴールは、Python SDKを使用して自分のプロジェクトでGemini Proを使用する方法を紹介することです。

Okay, so you can see we got an output from the model.

さて、モデルから出力が得られたことがお分かりいただけたと思います。

So let's look at some of the options that you have in here.

ここでいくつかのオプションを見てみましょう。

So you have, you can set the temperature.

ですので、温度を設定することができます。

Currently, it's set to 9.

現在は9に設定されています。

One very interesting thing that Google has done in here is that it is giving the users the ability to define the safety settings for the model.

Googleがここで行った非常に興味深いことのひとつは、ユーザーにモデルの安全設定を定義する能力を与えていることです。

They have four different harmful categories: harassment, hate speech, sexually explicit content, and dangerous content.

ハラスメント、ヘイトスピーチ、性的に露骨なコンテンツ、危険なコンテンツの4つの異なる有害カテゴリーがある。

And you have this slider that you can use to actually set different levels, which is very interesting and it gives the user, the developers, more control on what they want their users to be able to see.

このスライダーを使ってさまざまなレベルを設定できるのですが、これはとても興味深く、ユーザーや開発者がユーザーに見てもらいたいものをよりコントロールできるようになります。

So I think it's a really good initiative from Google.

ですから、Googleの本当に良い取り組みだと思います。

Now you can also set some other settings in here.

ここでは他の設定も行うことができます。

So for example, this is the maximum number of output tokens, top K, top P. Now once you're happy with the Model Behavior, then you can simply export the code with all the settings.

例えば、これは出力トークンの最大数、トップK、トップPです。モデルの振る舞いに満足したら、設定を含んだコードを簡単にエクスポートできます。

So just click on this get code, this will give you the python code in this case, but you can also get the JavaScript, and here's everything that you need.

この「get code」をクリックすると、Pythonコードが表示されますが、JavaScriptも取得できます。必要なものはすべてここにあります。

So these are the configuration settings that we just used.

これらは、私たちが使用した設定です。

Here are the safety settings, you can modify them.

ここには安全設定があります。変更することができます。

And then, uh, how to actually use the model itself.

そして、モデル自体の実際の使用方法です。

We are going to look at an example later in the video.

動画の後半で例を見てみましょう。

If you click on the, um, Gemini Pro Vision model now, you will have the ability to upload images as well.

もしも今「Gemini Pro Visionモデルをクリックすると、画像をアップロードすることもできます。

If you want to use this in your own, uh, projects, you will need to create an API key.

自分のプロジェクトでこれを使用したい場合は、APIキーを作成する必要があります。

So we're going to click on this get API key and here I already have an API key that I was testing, but you can create a new API key for your project.

「get API key」をクリックすると、私はすでにテストしていたAPIキーが表示されますが、プロジェクト用に新しいAPIキーを作成することもできます。

So simply click on that, just copy your API key.

単純にそれをクリックして、APIキーをコピーしてください。

Now let me show you how to test Gemini Pro in a Google collab.

では、Google CollabでGemini Proをテストする方法をお見せしましょう。

So in this Google collab, we are going to be looking at a few things.

Google Collabでは、いくつかのことを見ていきます。

The first one is going to be how to set up your development environment and how to set access to your API key within, uh, Google notebook.

まずは、開発環境のセットアップ方法と、Googleノートブック内でAPIキーにアクセスする方法です。

Second, we're going to look at how to generate text responses from the model, then how to do streaming of those responses, as well as how to use the chat model.

次に、モデルからテキストの応答を生成する方法、それらの応答のストリーミング方法、およびチャットモデルの使用方法を見ていきます。

Later, I'll show you how to use the embedding model that you can use in your own rack pipelines, and I'll also show you how you can interact with images using the vision version of Gemini Pro.

その後、独自のラックパイプラインで使用できる埋め込みモデルの使用方法と、Gemini Proのビジョンバージョンを使用して画像との対話をする方法もお見せします。

We need to set our API key, so click on this key option.

まずはAPIキーを設定する必要がありますので、この「key」オプションをクリックしてください。

Now, here you can add a new secret.

ここで新しいシークレットを追加することができます。

So I currently have one which I'm calling, uh, Gemini, and I provided my API key in here.

私は現在、"Gemini"と呼んでいるものを持っており、ここにAPIキーを入力しています。

If you want to add another one, so for example, let's call this test, then I'll provide the API key in here, and let's just enable it so that it's visible to your Google Collab notebook.

もしもう1つ追加したい場合は、例えばこれを"test"と呼び、ここにAPIキーを入力し、Google Collabノートブックで表示できるように有効にしてください。

Now, in this case, you need to remember the name that you assign in here.

この場合、ここで割り当てた名前を覚えておく必要があります。

That is going to be your environment variable.

それがあなたの環境変数になります。

Once we do that, the first thing we need to do is to download and install the Google generative AI package.

これを行ったら、最初に行うべきことは、Googleの生成AIパッケージをダウンロードしてインストールすることです。

Here, we're just importing all the packages that we're going to be using.

ここでは、使用するすべてのパッケージをインポートしています。

Now, in this case, we're using the user data function or object from the Google Collab just to retrieve the API key.

今回は、Google Collabからユーザーデータの関数またはオブジェクトを使用してAPIキーを取得しています。

If you're running this locally on your own machine, you can set an environment variable and retrieve it that way.

自分のマシンでローカルに実行している場合は、環境変数を設定して取得することもできます。

And at the end, we are defining a function just to show the responses generated by the model and marked down.

そして最後に、モデルによって生成された応答を表示するための関数を定義しています。

Next, we need to retrieve the API key.

次に、APIキーを取得する必要があります。

So if you recall, I had this environment variable called Gemini.

覚えているかもしれませんが、私は"Gemini"という環境変数を持っています。

So here, I'm just providing that, and we are going to set this in configuration.

ですので、ここでそれを提供して、これを設定します。

Now, if you are running this locally, you can set an environment variable called Google API key.

今、もしローカルで実行している場合は、"Google API key"という環境変数を設定して、自分のコードで使用するためにそれをロードすることができます。

And then load that in order to use it in your own code.

そして、それを読み込んで自分のコードで使用できるようにします。

Next, we're going to look at all the models that are currently available within the Google Generative AI package.

次に、Googleの生成AIパッケージ内に現在利用可能な全てのモデルについて見ていきます。

So currently, we have access to Only The Gemini Pro, which is the text model, and the Gemini Pro Vision, which has the ability to understand images.

現在、私たちは「Gemini Pro」というテキストモデルと、画像を理解する能力を持つ「Gemini Pro Vision」のみにアクセスできます。

And as I said in the beginning of the video, there is a rate limit of 60 requests per minute or 6 queries per minute, but it's absolutely free to use, at least for the time being.

そして、動画の最初で言ったように、1分あたり60リクエストまたは6クエリのレート制限がありますが、少なくとも現時点では完全に無料で使用できます。

Now, how do you actually use the model?

実際にそのモデルをどのように使用するのですか?

So, we are going to be calling this generative model function on the Gen AI object that we created.

私たちは作成したGen AIオブジェクトに対してこの生成モデル関数を呼び出すことになります。

We pass on the name of the model, so in this case, we want to use the Gemini pro version, which is the text generation model, and that will load the model for us.

モデルの名前を渡します。この場合、テキスト生成モデルであるGemini proバージョンを使用したいので、それがモデルをロードしてくれます。

Now, in order to generate a response from the model, we will need to call this generate undor content function on the model and pass on our prompt.

モデルからの応答を生成するためには、モデル上でこのgenerate undor content関数を呼び出し、プロンプトを渡す必要があります。

If we look at the response object that we got, there are a lot of things that we can call, but the one that we are interested right now is just the text part of it.

私たちが得た応答オブジェクトを見ると、呼び出すことができる多くの要素がありますが、今はその中でテキスト部分に興味があります。

Let's run this.

これを実行しましょう。

This is basically the text or response from the model that was returned.

これは基本的に返されたモデルのテキストまたは応答です。

And using the markdown function that we wrote, we can convert this into a nicely formatted markdown.

私たちが書いたmarkdown関数を使用して、これをきれいにフォーマットされたmarkdownに変換することができます。

So, here is the response that you see in markdown.

したがって、ここにマークダウンで表示される応答があります。

Just to repeat what we did so far, initially, we imported the Google generative AI package as gen AI.

これまでに行ったことを繰り返すと、最初にGoogle generative AIパッケージをgen AIとしてインポートしました。

Then, we said that we want to use the Gemini Pro model using the generative model function.

次に、generative model関数を使用してGemini Proモデルを使用すると述べました。

And after that, we call the generate content function and pass on our prompt.

その後、generate content関数を呼び出し、プロンプトを渡しました。

And we get a response as a text field.

そして、テキストフィールドとして応答を得ます。

In terms of the API implementation, it's a very clean implementation, and I really like how it's formatted.

APIの実装に関しては、非常にクリーンな実装であり、フォーマットが気に入っています。

Now, apart from the text, there are some other properties of the response object that we want to look at.

今、テキスト以外にも、レスポンスオブジェクトのいくつかの他のプロパティを見てみたいと思います。

One of the most important ones is the prompt feedback.

最も重要なものの一つは、プロンプトのフィードバックです。

So basically, when the model generates responses for your prompt, it looks at the prompt and assigns it probability based on the four different harmful categories that we defined.

基本的に、モデルがプロンプトに対して応答を生成する際に、定義した4つの異なる有害なカテゴリに基づいて確率を割り当てます。

So, for example, if you look at in this case, my prompt was What is the meaning of life?

例えば、この場合、私のプロンプトは「人生の意味は何ですか?」でした。

And then, it looked at the safety ratings.

そして、それから、安全性の評価を見ました。

So, for example, if the category was sexually explicit, the probability of this category being present is negligible.

例えば、もしカテゴリが性的な表現であった場合、このカテゴリが存在する確率は無視できるほど低いです。

And, uh, same is the case for hate speech, harassment, as well as for Dangerous content.

また、ヘイトスピーチ、嫌がらせ、危険なコンテンツについても同様です。

Later in the video, I'll show you how you can control, uh, this for different prompts and allow some of these things based on your own tolerance.

後でビデオで、異なるプロンプトに対してこれを制御する方法と、自分の許容範囲に基づいてこれらのいくつかを許可する方法を紹介します。

If you have used Bard, you are probably aware that Bard generates multiple drafts and show you one of them.

Bardを使用したことがある場合、Bardは複数のドラフトを生成し、そのうちの1つを表示します。

Google has enabled exactly the same behavior to their API as well.

Googleは、APIでもまったく同じ動作を有効にしました。

So, in this case, on the response object, there is another property called candidates which will show you different candidates or different responses that it generated.

したがって、この場合、レスポンスオブジェクトには、生成された異なる候補または異なる応答を表示するcandidatesという別のプロパティがあります。

And you can select the response you want out of it.

そして、その中から希望する応答を選択することができます。

Currently, it's just limited to generation of a single, uh, candidate, but it seems like they're going to expose multiple responses to the user.

現在は単一の候補の生成に限定されていますが、複数の応答をユーザーに公開する予定のようです。

And then, as a developer, you can choose which response to show to the user.

そして、開発者として、どの応答をユーザーに表示するかを選択することができます。

So, for example, you can set some of the configurations in here.

例えば、ここでいくつかの設定を行うことができます。

So, apart from the simple prompt that you get from the user, you can set a few configurations.

ユーザーから得られる単純なプロンプト以外にも、いくつかの設定を行うことができます。

Right now, the candidate count can only be set to one, but in a future update, this might change.

現在は、候補の数は1に設定することしかできませんが、将来のアップデートで変更される可能性があります。

You can control the maximum number of output tokens.

最大の出力トークン数を制御することができます。

So far, we did the whole text generation at once, but sometimes you want to stream the text.

これまでは一度に全体のテキスト生成を行ってきましたが、時にはテキストをストリーミングしたい場合もあります。

That means you want to generate text in chunks and show them to the user.

つまり、テキストをチャンクごとに生成し、ユーザーに表示したいということです。

So, in order to do that, all you need to do is just set this, um, stream parameter to true.

それを行うためには、単にこのstreamパラメータをtrueに設定するだけで十分です。

Now, once you run this, you will get a response, but you will need to retrieve chunks from the response and show them to the user one at a time.

このコードを実行すると、レスポンスが得られますが、そのレスポンスからチャンクを取得し、ユーザーに一つずつ表示する必要があります。

So, for example, here's the first chunk of text, then the next, and then the next, and so on and so forth.

例えば、最初のテキストチャンク、次のチャンク、そして次のチャンク、というように表示します。

So far, we just looked at an example of using Gemini Pro as a text generation model.

これまでは、Gemini Proをテキスト生成モデルとして使用する例を見てきました。

However, you can use this as a chat model as well.

しかし、これをチャットモデルとしても使用することができます。

The way you do it is that you create a model.

やり方は、モデルを作成することです。

So, specifically, we're using the Gemini Pro model.

具体的には、Gemini Proモデルを使用しています。

Then, instead of content generator, you want to use this in, uh, chat mode.

そして、コンテンツジェネレータの代わりに、チャットモードで使用します。

So, for that, you're going to call this, uh, start chat function, and you will pass on the history.

そのためには、この「スタートチャット」関数を呼び出し、履歴を渡します。

Now, in this case, we are, um, passing on an empty list, but you can pass on, uh, previous conversations that you had, and that will become his history to the model.

今回は空のリストを渡していますが、以前の会話を渡すこともできます。それがモデルの履歴になります。

Now, in order to use the model, you are going to call the send message function.

モデルを使用するためには、「メッセージを送信する」関数を呼び出します。

Here's an example prompt: In a single sentence, explain how a computer works to a young child.

ここに例として、コンピュータがどのように動作するかを子供に説明する一文があります。

You get the response, and we can show the response in here.

レスポンスが得られ、それをここに表示することができます。

So, the response is, A computer is a machine that helps us do many things by following instructions we give it.

したがって、レスポンスは「コンピュータは、私たちが与えた指示に従って多くのことを行う機械です」となります。

Now, we can actually look at the history.

実際に履歴を見ることもできます。

So, everything is divided into parts.

すべてはパーツに分かれています。

The first one is text input from the user, and that's why you see the role user.

最初のパートはユーザーからのテキスト入力であり、そのために「ユーザー」という役割が表示されます。

Then, we have a second part, which is the response from the model, and the role is set to the model.

次に、モデルからのレスポンスで、役割がモデルに設定されています。

Now, you can store this history as a list, uh, and you can provide this to the model when you initiate it.

この履歴をリストとして保存し、モデルを初期化する際に提供することもできます。

So, it's going to use that, uh, in its chat history, or you can simply continue the conversation.

それによって、モデルはそのチャット履歴を使用します。または、単に会話を続けることもできます。

So, you can again call the send message function, ask another, uh, question, or pass on another prompt.

再び「メッセージを送信する」関数を呼び出し、別の質問をしたり、別のプロンプトを渡したりすることができます。

You can also stream the responses if you want, and you will get a streaming response.

必要に応じてレスポンスをストリーミングすることもでき、ストリーミングレスポンスが得られます。

In this case, we are, uh, retrieving the role as well as the corresponding text messages, right?

この場合、役割と対応するテキストメッセージを取得していますね?

So, you have the user input, then the model response, another user input, and another response from the model.

つまり、ユーザーの入力、モデルのレスポンス、別のユーザーの入力、そしてモデルからの別のレスポンスがあります。

As you can see, since it's a chat model, it keeps all the historical, uh, conversation that has happened before in order to generate more responses.

ご覧の通り、チャットモデルなので、以前に行われたすべての会話を保持して、より多くの応答を生成するために使用します。

Before looking at the Gemini Vision model as well as how to, uh, change the safety settings, let's look at the embedding model that Google has released as a part of their generative AI package.

Gemini Visionモデルや安全設定の変更方法を見る前に、Googleが彼らの生成AIパッケージの一部としてリリースした埋め込みモデルを見てみましょう。

This is a purely text embedding model that Google released, and you can use this for a number of applications, including enom detection in your documents, clustering with ellings, as well as document question answer as a part of the rack pipelines.

これはGoogleがリリースした純粋なテキスト埋め込みモデルで、ドキュメント内のエラー検出、クラスタリング、ドキュメントの質問応答など、さまざまなアプリケーションに使用することができます。

I'm going to be creating more videos on this, but let me show you how to use the embedding model.

これについてはもっと動画を作成する予定ですが、まず埋め込みモデルの使い方をお見せします。

Something that Google has done in here is there are five different tasks for which you can use the embedding model to compute the embeddings, and it seems like these are task-specific embeddings, which makes it very powerful.

Googleがここで行ったことは、埋め込みモデルを使用して埋め込みを計算するために使用できる5つの異なるタスクがあることです。これらはタスク固有の埋め込みであり、非常に強力です。

Within the generative AI package, there is a special embedding model.

生成AIパッケージには特別な埋め込みモデルがあります。

You can invoke that using the embed content function.

それを呼び出すには、embed content関数を使用します。

Currently, there is only one model, so embedding 001.

現在、モデルは1つしかないので、埋め込み001です。

Then, you need to provide the text that you want to encode, then the type of task that you want to encode it for, right?

それから、エンコードしたいテキストを提供し、それをエンコードするためのタスクのタイプを指定する必要がありますね。

And if you're doing a retrieval document, then you need to also provide a title for the embedding that you create.

そして、ドキュメントの検索を行っている場合は、作成する埋め込みにタイトルも提供する必要があります。

Now, there are five different tasks: retrieval query, retrieval document, semantic similarity classification, as well as clustering.

さて、5つの異なるタスクがあります: 検索クエリ、検索ドキュメント、意味の類似性分類、およびクラスタリングです。

The embedding vector that you get has 768 dimensions, so it's a pretty large embedding vector.

取得する埋め込みベクトルは768次元であり、かなり大きな埋め込みベクトルです。

Instead of providing a single sentence, you can, uh, provide multiple sentences.

単一の文を提供する代わりに、複数の文を提供することもできます。

So, for example, if you look here, we have three different sentences, and we get, uh, three different embedding vectors for each of the sentence.

例えば、ここを見てください。3つの異なる文があり、それぞれの文に対して3つの異なる埋め込みベクトルが得られます。

You can also provide whole paragraphs, and this will give you, um, embeddings of the paragraph.

また、全体の段落を提供することもでき、これにより段落の埋め込みが得られます。

Both LlamaIndex as well as, uh, LangChain has already support for this embedding model.

LlamaIndexとLangChainの両方が、この埋め込みモデルをすでにサポートしています。

So, in a future video, I'll show you how to use this embedding model as a part of your rag pipeline.

将来の動画では、この埋め込みモデルをragパイプラインの一部として使用する方法をお見せします。

Just like the Google a studio, you can control the safety settings within the Python SDK.

Googleのスタジオと同様に、Python SDK内で安全設定を制御することができます。

For example, here I defined or initiated a new model.

例えば、ここでは新しいモデルを定義または初期化しました。

Then, I asked it how to break into a car, and the response is, I'm sorry, I'm not able to provide assistance with illegal activities.

そして、それに対して車への侵入方法を尋ねたところ、返答は「申し訳ありませんが、違法な活動に関する援助はできません」となりました。

Breaking into a car is a crime, and I would not be able to help you with that.

車への侵入は犯罪であり、それに関してはお手伝いできません。

When I looked at the safety ratings, so for some reason, it identified the prompt to have a low probability of containing harassment, although I was expecting it to have a high probability of dangerous content.

安全評価を見たところ、何らかの理由で、プロンプトが嫌がらせを含む可能性が低いと判断されましたが、私は危険なコンテンツの高い確率を期待していました。

So, let me show you how you can potentially change this behavior, although personally, I did not have much luck.

ですので、この振る舞いを変更する方法をお見せしましょう。ただし、個人的にはあまりうまくいきませんでした。

You can define your own safety settings.

独自の安全設定を定義することができます。

So, again, you have four categories: harassment, hate speech, sexually explicit content, and dangerous content.

ですので、再度、4つのカテゴリがあります:嫌がらせ、憎悪表現、性的な表現、危険なコンテンツです。

And then, you can define different thresholds.

そして、異なる閾値を定義することができます。

So, for example, for the first three, I defined block medium and above, and for the dangerous content, I said block then.

例えば、最初の3つについては「中程度以上をブロック」と定義し、危険なコンテンツについては「そのままブロック」としました。

But even after that, when I ran the same prompt, I got this response.

しかし、それでも同じプロンプトを実行した後でも、このような返答が得られました。

It might be that it's detecting some illegal activities, and as a user, you cannot really change those in here.

おそらく、違法な活動を検出しているため、ユーザーとしてはここではそれを変更することはできません。

So, that might be a possible reason that it's not working for my prompt.

ですので、それが私のプロンプトに対して機能しない可能性がある理由かもしれません。

Where are these settings from?

これらの設定はどこから来るのでしょうか?

You can actually look at the documentation in here, and they have an explanation.

実際には、ここでドキュメントを参照することができ、説明があります。

For example, block none so you set it to block none, then there is block few, block some, and block most.

例えば、「ブロックなし」と設定すると、「ブロックなし」、「一部ブロック」、「多くブロック」といった設定があります。

So, you can set these based on different thresholds that you have in here.

ですので、ここに基づいて異なる閾値を設定することができます。

I'll put a link to the documentation in the last part of this video.

このビデオの最後の部分にドキュメントへのリンクを掲載します。

I'll show you how to work with the Gemini Pro Vision model, but for that, first, we need an image.

Gemini Pro Visionモデルの操作方法をお見せしますが、そのためにはまず画像が必要です。

So, here is an image.

では、こちらが画像です。

This is provided an example notebook from Google.

これはGoogleから提供されたサンプルノートブックです。

We downloaded the image, then using the pillow package, we are reading the image, and this is an image of food.

私たちは画像をダウンロードし、pillowパッケージを使用して画像を読み込んでいます。これは食べ物の画像です。

Now, since we want to use the Vision model, so we're going to initiate another model, and this time we're going to be using the Gemini Pro Vision.

今度はVisionモデルを使用したいので、別のモデルを初期化します。今回はGemini Pro Visionを使用します。

So, now the model is going to have Vision capabilities, and if you pass the image as an input, the model will generate a response.

これでモデルはVisionの機能を持つようになり、画像を入力として渡すと、モデルは応答を生成します。

And this is basically what it thinks about the image.

そして、これがモデルが画像について考えていることです。

So, in this case, it says a chicken toak meal prep ball with brown rice and roasted vegetables, which, uh, seems to be accurate.

この場合、鶏肉のトークミールプレップボールに茶色のご飯と焼き野菜があります。正確なようですね。

The beauty of this Vision model is that not only you can provide images and input, but you can also provide text.

このVisionモデルの素晴らしいところは、画像だけでなくテキストも提供できることです。

So, for example, here we have a text prompt along with the image.

例えば、ここでは画像と一緒にテキストプロンプトがあります。

So, here's our input image, and then the text prompt is write a short engaging blog post based on this picture.

こちらが入力画像で、テキストプロンプトは「この写真を基に、短く魅力的なブログ記事を書いてください。写真の食事の説明と、私の食事の準備の旅について話してください」となっています。

It should include a description of the meal in the photo and talk about my journey meal prepping.

入力画像と入力プロンプトに基づいて、このような応答が生成されました。

Based on the input image as well as the input prompt, it generated this response.

食事の準備は時間とお金を節約する素晴らしい方法であり、健康的な食事にも役立ちます。

Meal prepping is a great way to save time and money, and it can also help you eat healthier.

画像に基づいて、茶色のご飯、焼き野菜、チキンテリヤキがあることを特定できました。

Based on the image, it's able to identify that there is brown rice, roasted vegetables, and chicken Teryaki.

画像を基にすると、茶色のご飯、焼き野菜、チキンテリヤキが特定できます。

So, it's able to include that information in the response.

その情報をレスポンスに含めることができますので。

This is pretty awesome, as you can imagine.

想像できるように、これはかなり素晴らしいです。

This opens up so many possibilities, even with the chat with your documents or rack pipelines.

これにより、ドキュメントやラックパイプラインとのチャットを含め、さまざまな可能性が広がります。

Now, you can use this model as a part of a multimodal rack pipeline, which is going to be pretty awesome.

これから、このモデルをマルチモーダルラックパイプラインの一部として使用することができます。これはかなり素晴らしいことです。

In a subsequent video, I'll show you how to do that.

次のビデオでは、その方法をお見せします。

I'll highly recommend everybody to check out the documentation that Google has provided, both for the API as well as there is a prompt Gallery.

Googleが提供しているドキュメント、API用のものだけでなく、プロンプトギャラリーについても、皆さんに是非チェックしていただきたいと強くお勧めします。

So, Google provided a few examples of how to interact with these LLMs and also the vision models.

つまり、GoogleはこれらのLLMやビジョンモデルとのやり取り方法についていくつかの例を提供しました。

I hope you found this video useful.

このビデオが役に立ったと思っていただければ幸いです。

Consider liking and subscribing to the Channel, and let me know in the comment section below if there are specific topics related to the Gemini Pro API that you want me to cover.

チャンネルの「いいね」と購読を検討してください。そして、Gemini Pro APIに関連する特定のトピックがあれば、以下のコメント欄で教えてください。

Thanks for watching, and as always, see you in the next one.

ご視聴いただき、いつもありがとうございます。次回もお会いしましょう。


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