見出し画像

【ChatGPT】英語解説を日本語で読む【2023年4月25日|@Matthew Berman】

ChatGPTを使ってコードを書く方法を解説しています。
⏱️ タイムスタンプ
00:00 イントロ
01:25 概要
02:57 企画
04:30 スケルトンの作成
07:19 コードの記入
08:25 リファクタリング
11:05 テスト
13:18 デバッギング
15:32 機能を追加する
19:27 その他の注意点
20:14 アウトロ
公開日:2023年4月25日


ChatGPT has forever changed the way developers build code.

ChatGPTは、開発者のコード構築の方法を永遠に変えてしまいました。

There are gonna be two types of developers in the future.

今後、開発者は2種類に分かれるでしょう。

Those who learn to leverage AI will be hyperproductive, and those who don't will be out of jobs.

AIを活用することを学んだ人は超生産的になり、そうでない人は職を失うことになるでしょう。

It's going to happen sooner than you think.

それは、あなたが思っているよりも早く起こりそうです。

Here's the thing, the bar to become a 10X engineer has dropped tremendously.

ここで、10Xエンジニアになるためのハードルはものすごく下がっている。

Anyone can achieve it, but only if you know how to use AI to help.

誰でも達成できますが、AIの使い方を知っていればの話です。

I've done a ton of coding using Copilot, and now ChatGPT has brought my productivity to another level.

私はCopilotを使って大量のコーディングをしてきましたが、今はChatGPTが私の生産性をもう一段階上げてくれました。

You have to change your mindset from being a builder to being a conductor.

ビルダーであることから指揮者であることに意識を変える必要があるのです。

In this video, I'll show you how to leverage the power of ChatGPT to code in any language, regardless of your skill set.

このビデオでは、ChatGPTのパワーを活用して、スキルに関係なく、どんな言語でもコーディングする方法を紹介します。

Here's what you're gonna need.

必要なものは以下の通りです。

A basic understanding of how coding works.

コーディングの仕組みについて基本的に理解していること。

You don't really need to know that much.

それほど多くの知識は必要ありません。

Start with Python.

Pythonから始めましょう。

Its syntax is very much like reading English, where previously you had to understand a language at a very deep level to build something really meaningful.

その構文は、英語を読むのと非常によく似ており、以前は言語を非常に深いレベルで理解しなければ意味のあるものを構築できませんでした。

Now, we can learn as we go using ChatGPT.

今は、ChatGPTを使いながら学ぶことができます。

Next, you'll need an understanding of the file structure of each language that you wanna use.

次に、使用する各言語のファイル構造を理解する必要があります。

So we're gonna be using Python in this tutorial, and it's important to know where the things go.

このチュートリアルではPythonを使いますが、どこに何があるのかを知っておくことは重要です。

You can maybe skip this and learn while you go, but it'll be more difficult.

このチュートリアルはPythonを使います。

ChatGPT can even explain where things should go in certain languages, so let's get into it.

ChatGPTでは、特定の言語において、どこに何があるべきかを説明することも可能です。

Let's talk about a few things first.

まず、いくつかのことを説明しましょう。

This is ChatGPT.

これがChatGPTです。

I'm gonna be using GPT-4, and if you don't have access to GPT-4, definitely sign up, and GPT-3.5 will be fine for now.

GPT-4を使うつもりです。GPT-4にアクセスできない人は絶対に登録してください。今はGPT-3.5で大丈夫です。

I'll also get into the differences between GPT-3.5 and GPT-4.

GPT-3.5とGPT-4の違いについても触れておこう。

Four is definitely better for coding, but 3.5 can be sufficient.

コーディングには間違いなく4が良いですが、3.5でも十分です。

And even if you do have GPT-4, you're gonna be very limited in your messages.

それに、GPT-4を導入したとしても、メッセージがかなり制限されることになる。

Right now, it's 25 messages for every three hours, which is nothing.

今現在、3時間ごとに25通のメッセージが送られてきますが、これは何もないことです。

So I'm also gonna show you how to be very efficient with your prompts.

そこで、プロンプトを非常に効率的に使用する方法も紹介するつもりです。

The next thing to note before we dive into the code is the token limits, and tokens are essentially portions of words.

コードに入る前に注意すべきは、トークンの制限です。トークンとは、基本的に単語の一部です。

It's how many words you can use in your prompt.

プロンプトで使用できる単語の数です。

GPT-3.5 has about 4,000 tokens as the limit, and that's between the prompt and the response, whereas GPT-4 has up to 32,000, so it's much, much bigger, and that means you're able to provide it a lot more code for context as you're building.

GPT-3.5 は約4,000トークンが制限で、それはプロンプトとレスポンスの間になりますが、GPT-4は最大32,000トークンを持っているため、はるかに大きく、それはあなたが構築する際にコンテキストとしてより多くのコードを提供できることを意味します。

Now, as your code base grows, you're gonna find that providing all the context necessary becomes harder and harder.

しかし、コードベースが大きくなると、必要なコンテキストをすべて提供することが難しくなってきます。

So what you're gonna need to do is name your files really well, name your methods really well, and ChatGPT will actually be able to infer about what the functionality is of each of the files and each of the methods.

したがって、ファイル名を適切に付け、メソッド名も適切に付ける必要があり、ChatGPTは各ファイルと各メソッドの機能について推測できるようになります。

You can also describe it as a way to kind of compress the context.

また、コンテキストを圧縮する方法と表現することもできます。

So let's get into the code.

では、コードに入りましょう。

We're gonna be building a ChatGPT integration, and essentially what we're gonna do is recreate the ChatGPT interface, but make it command line and have it locally enabled.

私たちはChatGPTとの連携を構築し、基本的にはChatGPTインターフェースを再現するが、コマンドラインでローカルに有効にすることを目指します。

So the first thing I like to do is just discuss the high-level plan with ChatGPT.

まず最初に、ChatGPTの高レベルな計画について議論したいと思います。

So let's do that.

では、それをやってみましょう。

I want to build a ChatGP integration so I can ask questions from the command line.

コマンドラインから質問できるようにChatGPの統合を構築したい。

I want to use GPT 3.5 turbo, and that's because it's extremely cheap to use and it's very, very fast as well.

GPT 3.5ターボを使いたいのですが、これは非常に安く使えて、しかも非常に速いからです。

And I want to use Python.

そして、Pythonを使いたい。

What should the file structure be?

ファイル構成はどうすればいいのでしょうか?

And please provide me with the outline of the code.

そして、コードのアウトラインを提供してください。

Now, the more you ask it in each prompt, the better, because you wanna be really efficient with the 25 messages per three hours that you have.

3時間あたり25通のメッセージを効率的に使いたいので、各プロンプトで質問する量は多ければ多いほどよい。

After you reach that 25 message limit, it's gonna switch you over to GPT 3.5, which again, it's fine, but GPT-4 is much better right now.

25メッセージの制限に達すると、GPT3.5に切り替わりますが、これも問題ありませんが、今はGPT-4の方がはるかに優れています。

So let's go ahead and hit Enter, and we'll wait for the output.

では、Enterを押して、出力を待ってみましょう。

Now, while that's outputting, one other thing I'm gonna mention is I'm using Visual Studio Code.

さて、出力されている間に、もうひとつ言っておくと、私はVisual Studio Codeを使用しています。

So I have it loaded up with nothing in there, and we're gonna create everything from scratch.

何も入っていない状態でロードし、ゼロからすべてを作成することになります。

So to build a chat bot using GPT 3.5 turbo and Python, you can use the OpenAI API with the OpenAI package.

GPT 3.5ターボとPythonを使ってチャットボットを作るには、OpenAI APIとOpenAIパッケージを使います。

First, you need to install the package, if you haven't already.

まず、まだインストールしていない場合は、パッケージをインストールする必要があります。

So while it's outputting the rest of this, let's do that.

というわけで、この続きを出力している間に、それをやってしまいましょう。

So I'm gonna go copy it, and you can also click Copy Code right there.

コピーしてきますが、その場で「コードをコピー」をクリックすることもできます。

So I'm gonna copy it.

コピーしてみましょう。

I'm gonna switch over to Visual Studio Code.

Visual Studio Codeに切り替えて、コマンドラインを開きます。

I'm gonna open the command line, the terminal, that's that little button in the top right.

コマンドライン、ターミナル、右上の小さなボタンを開きます。

I'm waiting for it to load up, and there it is.

ロードされるのを待つと、そこにあります。

So right now, we're gonna type ls, which tells us all of the files and directories of where we are.

今いる場所のすべてのファイルとディレクトリを表示するlsを入力します。

So let's change directory cd into the desktop, and now we're going to create a directory called, and what do they want us to call it?

ディレクトリをcdしてデスクトップに移動し、ディレクトリを作成します。

ChatGPT CLI, underscore CLI.

ChatGPT CLI、アンダースコアCLIです。

There we go.

そうです。

Now we're gonna change directory into that folder, and we can hit Tab to complete.

そのフォルダにディレクトリを変更し、Tabキーを押して完了です。

So now we're in that folder.

これでフォルダに入りました。

And so the first thing we wanna do is install that module.

まず最初にやることは、このモジュールをインストールすることです。

So copy, paste.

コピーして、貼り付けます。

And I already have it installed, but if you don't, it'll install it.

私はすでにインストールしていますが、そうでない場合は、インストールされます。

So once we have that done, now it's saying we can create a new directory, which we've done.

インストールが完了したら、今度は新しいディレクトリを作ると表示されるので、それを作成します。

We need an env file.

envファイルが必要です。

We need a requirements.txt file, and we need the chatgpt.py file.

requirements.txtが必要で、chatgpt.pyが必要です。

So let's go ahead and create all three of those.

では、これら3つをすべて作成しましょう。

So now that we have that folder created, let's open it up.

では、フォルダを作成したら、それを開いてみましょう。

So I've already done that, but what you're gonna do is click this Explore button.

すでに作成済みですが、このExploreボタンをクリックします。

There's gonna be an open folder, and then you're gonna navigate to the folder.

開いたフォルダが表示されるので、そのフォルダに移動します。

Now we're in the chatgpt.cli folder.

今、私たちはchatgpt.cliフォルダにいます。

So right here, you're gonna click this button, which is New File, and we're gonna name it chatgpt.py.

ここで、新規ファイルというボタンをクリックし、chatgpt.pyという名前を付けます。

By calling it.py, it's automatically going to know that it's a Python file.

.pyとすることで、Pythonファイルであることを自動的に認識します。

So save.

保存してください。

And the next thing it says we're gonna need is a.env file.

次に必要なのは.envファイルだと言われました。

So I'm gonna go ahead and click that again.

もう一度クリックします。

I'm gonna type d.env, enter.

d.envと入力し、Enter。

Now we have that.

これで出来上がりです。

And we're not putting anything in there yet, but we're gonna ask chatgpt to do that.

まだ何も入れていませんが、chatgptにお願いすることにします。

And then we're gonna need a requirements.txt file.

それから、requirements.txt ファイルが必要です。

So again, hit New File, requirements.txt, enter.

もう一度、新規ファイル、requirements.txt、Enterを押してください。

Now we have all three files that it says we need there.

これで、必要な3つのファイルが揃いました。

Next, in the requirements.txt file, add the dependencies.

次に、requirements.txt ファイルに依存関係を追加します。

So we're gonna grab that.

これを取得します。

We're gonna copy it, requirements.txt, paste, hit Save.

requirements.txtをコピーして、ペーストし、Saveをクリックします。

Next, we're gonna need our OpenAI API key.

次に、OpenAIのAPIキーが必要です。

And so that is gonna go in the.env file, so I'll copy that.

これは.envファイルに書くので、それをコピーします。

Switch over to the.env file, paste.

.envファイルに切り替えて、貼り付けます。

Now we actually need to put a value in here, so we're gonna go grab that now.

ここで実際に値を入れる必要があるので、それを取得します。

So I'll create a new secret key.

新しい秘密鍵を作成します。

I'm not gonna name it.

名前は付けません。

There it is, I'm gonna copy.

これをコピーします。

Please know, I will rotate this key before publishing the video.

この鍵はビデオを公開する前に回転させます。

So you don't need to tell me in the comments.

だから、コメントで言う必要はない。

Thank you, though.

でも、ありがとうございます。

So I'll switch back.

では、スイッチバックします。

I'll paste the API key here.

APIキーをここに貼り付けます。

We're gonna click Save.

保存をクリックします。

We'll switch back to ChatGPT.

ChatGPTに戻ります。

We're gonna scroll down, and now it's gonna say, let's create an outline of the code for ChatGPT.py.

スクロールダウンすると、ChatGPT.pyのコードのアウトラインを作成しますと表示されます。

So it literally created the entire skeleton for what we're gonna need.

文字通り、必要なコードの骨格が出来上がりました。

So we're gonna copy.

コピーしましょう。

We're gonna switch back over to ChatGPT.py, and we're gonna paste it.

ChatGPT.pyに戻り、それを貼り付けます。

So the nice thing about ChatGPT is it also includes comments a lot of the time.

ChatGPTの良いところは、多くの場合、コメントも含まれていることです。

Now the reason that some of these are underlined in yellow is because it can't resolve the module.

黄色い下線が引かれているのは、モジュールを解決できないからです。

So that's usually a Python version issue.

これはPythonのバージョンの問題です。

So we're gonna come down here, and I'm gonna select 3.11.2, because that's the version that I have everything installed on.

そこで、3.11.2を選択することにします。

Okay, now we'll hit Save.

では、「保存」をクリックします。

Now there's still a problem, because we have nothing in this method, but that's okay for now.

このメソッドには何も入っていないので、まだ問題がありますが、とりあえずは大丈夫です。

And so next, we'll switch back to ChatGPT.

次に、ChatGPTに戻りましょう。

This script sets up a simple command line interface for interacting with GPT 3.5 Turbo.

このスクリプトは、GPT 3.5 Turboと対話するためのシンプルなコマンドラインインターフェイスをセットアップします。

To complete the ChatGPT function, you'll need to call the OpenAI API and handle the response as follows.

ChatGPTの機能を完成させるには、OpenAI APIを呼び出して、以下のようにレスポンスを処理する必要があります。

So the nice thing is it explains it all along the way.

いいことに、途中ですべて説明してくれています。

So we're gonna copy this function, switch back, and this function gets placed right here.

この関数をコピーして、スイッチバックすると、この関数がここに配置されます。

It's a replacement for this.

この関数はこの関数を置き換えるものです。

So now it's filling it out for us.

この関数はこの関数を置き換えるもので、今、私たちのために記入されています。

So we're gonna click Save.

保存」をクリックします。

Now let's take a look.

さて、見てみましょう。

The one thing that jumps out to me immediately is even though we're saying use ChatGPT 3.5 Turbo, it usually defaults to DaVinci 002, which is the older version.

一つすぐに目立つことは、ChatGPT 3.5 Turboを使用するように指示しているにもかかわらず、通常は古いバージョンであるDaVinci 002にデフォルト設定されていることです。

I don't know why it does that.

なぜそうなるのかは分かりませんが。

And it says right here in the comment, replace this with the 3.5 Turbo model when it's available.

コメントには、3.5Turboが利用可能になったら、これを3.5Turboモデルに置き換えてくださいと書かれています。

It is available.

利用可能です。

So let's tell it so.

だから、そう言ってあげましょう。

This is our first debugging with ChatGPT.

ChatGPTを使ったデバッグはこれが初めてです。

So we're gonna say, the ChatGPT 3.5 Turbo API endpoint is available.

ChatGPT 3.5 Turbo APIエンドポイントが利用可能です、と言うことにしましょう。

Please give me the ChatGPT method with 3.5 Turbo.

3.5TurboでChatGPTのメソッドを教えてください。

Great.

素晴らしい。

Now that the GPT 3.5 Turbo API endpoint is available, you can update the method as follows.

GPT 3.5 Turbo APIエンドポイントが利用できるようになったので、以下のようにメソッドを更新します。

So it switches over, Model Engine GPT 3.5 Turbo.

つまり、モデルエンジンGPT 3.5 Turboに切り替わるわけです。

So interestingly, this is still not correct.

興味深いことに、これはまだ正しいとは言えません。

This is still using kind of the old architecture.

これはまだ、古いアーキテクチャを使用していることになります。

So here's next what we're gonna do.

そこで、次にやることはこれです。

We're gonna open up the GPT 3.5 Turbo API docs, and we're literally gonna copy paste the format that it should be in.

GPT 3.5 TurboのAPIドキュメントを開き、本来あるべき形式をコピーペーストします。

So here it is, okay?

これがそうです、いいですか?

So we're gonna copy this, and we're gonna switch back, and we're gonna say, that's not correct.

これをコピーして、元に戻して、「これは正しくない」と言いましょう。

Here is the correct usage for GPT 3.5 Turbo.

GPT 3.5 Turboの正しい使い方はこちらです。

And we just paste it in, and now it knows.

そして、それを貼り付けると、今度はそれがわかるようになります。

Now it apologizes every time it gets something wrong, which I find quite annoying.

何か間違うたびに謝ってきますが、これはかなり迷惑な話です。

I could probably just tell it, hey, no need to apologize, but it's not worth it.

謝らなくてもいいんだよ、と言ってもいいんですが、その価値はないんです。

And so now it's rewriting the ChatGPT method with 3.5, and there it is.

それで、ChatGPTメソッドを3.5で書き換えているところです。

So we can see already, this is ChatCompletion, which is the new version.

これがChatCompletionで、これが新しいバージョンです。

So let's copy it.

これをコピーしてみましょう。

And it's already thinking about how to maintain the conversation history, which is nice.

会話の履歴を維持する方法についてすでに考えています。

So let's switch back, because we have this method ready.

では、このメソッドの準備ができたので、スイッチバックしましょう。

We're gonna highlight the whole thing, paste, and now that should work.

全体をハイライトして貼り付けると、これでうまくいくはずです。

So it has the role of system, you're a helpful assistant, and the message, which is the prompt.

これで、システムの役割、あなたは親切なアシスタント、そしてメッセージ、つまりプロンプトができました。

We'll save, we'll switch back, and here we can maintain the conversation history.

保存して、スイッチバックし、ここで会話の履歴を維持することができます。

So we're gonna copy this whole thing, and this replaces the main function right there, okay?

これを丸ごとコピーして、メイン機能を置き換えるんだ、いいね?

So we import the modules, we load the.m file, we load the API key, we get OpenAI ready, and then we have the two functions that make it work.

モジュールをインポートし、.mファイルを読み込み、APIキーを読み込み、OpenAIの準備をし、そして2つの関数で動作させるわけです。

Let's see what happens, let's run the Python file.

何が起こるか見てみましょう、Pythonファイルを実行してみましょう。

In the top right, the little play button, we're just gonna click play, and let's see.

右上の小さな再生ボタンをクリックし、再生してみましょう。

There it is, welcome to ChatGPT CLI, type exit to quit.

ChatGPT CLIへようこそ、終了するにはexitと入力してください。

So let's type an example prompt.

では、プロンプトの例を入力してみましょう。

Write me a 10 word poem about AI, and we hit enter.

AIについて10語の詩を書いてください。

Artificial intelligence, endless possibilities, limitless potential.

人工知能、無限の可能性、無限の可能性。

So less than 10 words, but still, that's fine.

というわけで、10語未満ですが、それでも大丈夫です。

Now we can say, write me code in Python to count to 100.

では、Pythonで100まで数えるコードを書いてくださいと言えばいい。

Count to 100, there it is, and even outputs it with the formatting if we did have something to actually format it.

100まで数える、これです。実際にフォーマットするものがあれば、フォーマットして出力することも可能です。

So for AI in range one to one to one, print AI, perfect.

AI in range one to one to one, print AI, perfect.

Now we're gonna extend this a little bit more, but I wanna actually walk through a couple nuances that you should know as you're using ChatGPT to code.

さて、これからもう少し拡張していきますが、ChatGPTを使ってコーディングする際に知っておくべきいくつかのニュアンスを説明したいと思います。

So first, it might get things wrong.

まず、間違ってしまうことがあります。

So you actually have to look through it, you have to test it and see what it gets wrong.

だから、実際に見て、テストして、何が間違っているのかを確認する必要があるんだ。

As you get better and better at coding, you're gonna notice little issues even before you test out the code.

コーディングの腕が上がれば、テストする前から小さな問題に気づくようになります。

But it might not know that it's wrong.

でも、それが間違っていることに気づかないかもしれません。

So what you have to do is give it guidance, and it weighs your guidance heavily.

ですから、あなたがしなければならないのは、ガイダンスを与えることです。そして、ガイダンスは重く評価されます。

So if you say, I want you to build something like this, even if the way you're telling it to do it is wrong, it's gonna follow that.

つまり、「こういうものを作ってほしい」と言えば、たとえその方法が間違っていたとしても、それに従おうとするのです。

So really be confident in your suggestions to ChatGPT before doing so.

ですから、ChatGPTへの提案に自信を持ってから実行するようにしてください。

Now you can prompt it and actually have a conversation with it about how to accomplish something.

これで、プロンプトを表示して、実際に何かを達成する方法について会話することができます。

You need to structure that prompt in a certain way so that you're telling it, hey, don't follow my instructions blindly, talk to me about this.

プロンプトは、「私の指示に盲目的に従わないで、私に相談してください」と伝えるために、ある方法で構成する必要があります。

And to do that, you literally just say that.

そのためには、文字通り、こう言うのです。

You say, don't just follow what I'm gonna tell you to do, tell me what you think is the best method, here's what I'm thinking.

私の指示に従うだけでなく、最適な方法を教えてください、私はこう考えています、と言うのです。

The next thing to note is ChatGPT will actually keep the context pretty well throughout the history of your conversation.

次に、ChatGPTは、会話の履歴の中で、文脈をうまく維持することができます。

3.5 does this a little bit worse, but 4.0 does it pretty well.

3.5では少し悪いですが、4.0ではかなり良くなっています。

So all of these messages that I've already typed out, it's gonna know.

つまり、私がすでに入力したメッセージは、すべて把握されているのです。

So in future prompts, I don't need to say, hey, remember, this is what I'm building, I can just continue.

だから、今後のプロンプトでは、「そういえば、こんなものを作っているんだった」と言う必要がなく、そのまま続けることができます。

Now let's talk a little bit about how to debug.

では、デバッグの方法について少しお話ししましょう。

I'm actually gonna walk through an example.

実際に例を挙げて説明していきます。

So I switched back to Visual Studio code and I'm gonna cause some bugs in this code.

Visual Studioのコードに戻り、このコードにいくつかのバグを発生させます。

So right here, let's change it to 3.0 turbo, which is not right.

ここで、3.0ターボに変更しましょう。これは正しくありませんね。

So I'm gonna control C to quit out of the command line, and then I'm gonna click play again.

だからCでコマンドラインを終了してもう一度再生をクリックします。

Welcome to ChatGPT CLI, type exit to quit.

ChatGPT CLIへようこそ、exitと入力して終了してください。

So let's say, tell me a poem, 10 words.

では、「詩を教えてください、10語」とします。

Now we have a bug.

これで、バグが発生しました。

Okay, and we actually have error output, which is great.

エラー出力があるのは素晴らしいことです。

Now what I do is I grab the entire error output.

そこで私は、エラー出力全体を取得することにしました。

I highlight it all the way up to where I'm running this file.

このファイルを実行しているところまでをハイライトします。

I'm gonna copy it.

それをコピーします。

I'm gonna switch back to ChatGPT and I'm gonna say, I have a bug in the code.

ChatGPTに切り替えて、「コードにバグがあります」と言う。

Here's the output, new lines, I'll paste it in.

これが出力です、新しい行を貼り付けます。

And so the last line of the error is gonna spell out exactly what's wrong.

エラーの最終行には 何が問題なのかが書かれています。

And hopefully ChatGPT sees that.

ChatGPTがそれを見てくれることを祈ります。

So hit enter, apologies for the confusion in the model name.

それでエンターキーを押して、モデル名を混乱させたことをお詫びします。

The correct model name should be GPT 3.5 turbo.

正しいモデル名はGPT 3.5ターボであるべきです。

Here it is corrected.

ここで修正しました。

So there it is, it found the bug immediately.

これで、すぐにバグを発見してくれました。

Really, really good.

本当に、本当に素晴らしい。

And that's the workflow you should take.

これが、あなたが取るべきワークフローです。

Create some code, test it out yourself.

コードを作成し、自分でテストする。

If you have any issues, bring that error output back into ChatGPT.

何か問題があれば、そのエラー出力をChatGPTに持ち帰る。

Again, you don't actually need to paste all the code every time because it has that context from the previous messages.

繰り返しになりますが、以前のメッセージの文脈があるので、毎回すべてのコードを貼り付ける必要はありません。

But at a certain point, ChatGPT will lose context.

しかし、ある時点でChatGPTはコンテキストを失うことになります。

Now GPT-4.0, it's a long time and you can continue asking questions without providing it additional context about that original code.

GPT-4.0では、長い時間、元のコードに関する追加のコンテキストを提供することなく、質問を続けることができます。

But with 3.5, you might have to do that more often.

しかし、3.5では、より頻繁にそれを行う必要があるかもしれません。

There's no hard and fast rule.

難しいルールはありません。

Just test it out and see what works.

ただ、試してみて、何がうまくいくかを見てください。

If you notice that you're getting the same suggestions that are incorrect over and over again, or suggestions with code that don't make sense, that's when you're gonna need to provide the code again.

何度も間違った提案や意味をなさないコードの提案を受け取っていることに気付いたら、コードを再度提供する必要があります。

So I'm gonna switch back, I'm gonna fix the code.

そこで、コードを修正し、もう一度テストしてみます。

Let's test it one more time.

もう1回テストしてみましょう。

Write me a poem, 10 words, hit enter.

詩を書いてください、10文字で、エンターキーを押してください。

And there it is, great.

そうです、素晴らしい。

So next, let's extend the code a little bit to make it a little bit more complex.

では次に、このコードを少し拡張して、もう少し複雑にしてみましょう。

I'm not even gonna decide how to extend the code.

どのようにコードを拡張するかは、私が決めることではありません。

Let's ask ChatGPT how to do that.

ChatGPTにどうすればいいのか聞いてみよう。

I want to extend this code more.

このコードをもっと拡張したい。

I don't know what cool features I should add.

どんなクールな機能を追加すればいいのかわからない。

What do you think?

どうでしょう?

Okay, there are many potential features you can add.

なるほど、追加できる機能はたくさんありそうですね。

Here are some suggestions.

いくつか提案します。

Conversational context management, save the conversation history in a file so that the chatbot can remember the past conversations.

会話コンテキストの管理、会話の履歴をファイルに保存して、チャットボットが過去の会話を記憶できるようにする。

Great, multi-user support, fine.

マルチユーザサポート、いいですね。

Rich media support, that's cool.

リッチメディアのサポート、クールですね。

Personalization, timed responses, so we can actually simulate typing the way that ChatGPT does, that's pretty cool.

パーソナライゼーション、時間指定応答、ChatGPTのように実際にタイピングをシミュレートできる、とてもクールです。

Sentiment analysis, language translation, a voice interface, integration with external APIs, so it gave me 10 suggestions, these are wonderful.

センチメント分析、言語翻訳、音声インターフェース、外部APIとの統合など、10個の候補が出ました。

So I really like number five, so let's ask ChatGPT to give us that one.

では、5番が気に入ったので、ChatGPTにお願いしてみましょう。

Tell me how to build number five.

5番の構築方法を教えてください。

To implement timed responses that simulate typing, you can use the time.sleep function to add a delay before displaying the chatbot's response.

タイピングをシミュレートする時間指定応答を実装するには、time.sleep関数を使って、チャットボットの応答を表示する前に遅延を加えることができます。

Okay, so it's giving us a method, it's giving us the modules we need.

よし、これでメソッドと必要なモジュールが揃ったぞ。

Let's give it a try when it finishes outputting this code.

このコードを出力し終えたら、試してみましょう。

Okay, so we're gonna grab a few pieces.

では、いくつかの部品を手に取ってみましょう。

Now, it gave us the methods we need, including main again, but what it didn't give us is the ChatGPT method.

mainを含む必要なメソッドは出力されましたが、ChatGPTメソッドは出力されませんでした。

So we're gonna need to keep this, but we're gonna need to add other things.

ですから、これはそのままにして、他のものを追加する必要があります。

So let's go to the top, let's add import and time, that goes at the top, save.

そこで、一番上に行って、importとtimeを追加し、一番上に行って、保存します。

We're gonna take this simulate typing method, let's put that at the top, and we're gonna need this main method, and we'll paste that and overwrite both of these at the bottom, there it is.

このsimulate typingメソッドを取り、上部に置き、このmainメソッドが必要になります。それらを下部に貼り付けて上書きします。そこにあります。

So I did that in a matter of seconds.

というわけで、数秒のうちにできました。

So we'll control C out of here, I'm gonna command K to clear the console, and I'm gonna push play again.

ここからCをコントロールし、Kコマンドでコンソールをクリアして、もう一度再生ボタンを押します。

And let's see if it works.

そして、うまくいくかどうか見てみましょう。

Write me a 50 word poem about AI.

AIについて50語の詩を書いてくれ

Hit enter, ChatGPT is typing, and there it is.

エンターキーを押すと チャットGPTが入力される

That's okay, I want something different.

いいんだ、違うのがいい。

I want it to type out like it does in ChatGPT, so I misunderstood that.

ChatGPTのように打ち出すのがいいんだ、だから誤解したんだ。

That's not quite what I want.

それは私の望むところとはちょっと違うんです。

I want to output the text the same way that ChatGPT does by simulating someone typing each word.

ChatGPTと同じように、誰かが単語を入力するのをシミュレートして、テキストを出力したいのです。

Here we go, got it.

そうだ、そうだ。

To simulate someone typing each character in the response, you can add a delay between printing each character.

誰かがレスポンスの各文字を入力するのをシミュレートするには、各文字を印刷する間に遅延を追加することができます。

And this is the iteration loop.

そして、これが反復ループです。

You ask ChatGPT for something, you try it out, you find what works, what doesn't work, and then you continue to iterate with ChatGPT.

ChatGPTに何かを要求し、それを試し、何がうまくいき、何がうまくいかないかを見つけ、ChatGPTと反復を続けていくのです。

It's really such a nice process.

本当に素敵なプロセスです。

Okay, so let's grab what we need.

さて、それでは必要なものを手に入れましょう。

We already have import time and import random.

import timeとimport randomはすでにあります。

We do not have simulate typing character, so let's put that at the top.

文字入力のシミュレートはないので、一番上に置いておきましょう。

We may not need simulate typing anymore, but we'll leave that for now.

シミュレートタイピングはもう必要ないかもしれませんが、今は残しておきましょう。

We're gonna need the display response, put that right there, and then it gives us the main function again.

ディスプレイ・レスポンスが必要なので、それをここに置くと、再びメイン関数が表示されます。

Let's copy that, and we'll go down to the bottom, and we'll paste that in.

それをコピーして、一番下まで行って、それを貼り付けます。

And we're going to exit out of here, clear the console, and let's try it again.

そして、ここを出て、コンソールをクリアして、もう一度やってみましょう。

Write me a poem, 50 words.

詩を書いてください、50語です。

There it is.

ほら、できました。

Now you can actually see it typing out each character, which is pretty cool.

実際に一文字一文字入力しているところを見ることができます。

Now, this isn't exactly like how ChatGPT outputs things because it does it by chunks, and we could ask it to do that, but feel free to do that yourself.

ChatGPTの出力方法とは異なりますが、ChatGPTはチャンク単位で出力するので、それをお願いすることもできます。

Now, one last thing I wanna reiterate is that as your code base becomes bigger and more complex, it's gonna be more and more difficult to provide all the context to ChatGPT, and that's okay.

最後に再度強調したいことは、コードベースが大きく複雑になるにつれて、ChatGPTにすべてのコンテキストを提供するのが難しくなることで、それは大丈夫です。

And what we'll do is, as we get better at coding, we'll take the parts of the code that we think are the context necessary to give us the response we want and paste that back into ChatGPT when necessary.

そして、私たちがコーディングが上手になるにつれて、私たちが求める回答を得るために必要なコンテキストと思われるコードの一部を取り、必要に応じてChatGPTに貼り戻すことにします。

And the more you use ChatGPT to partner with you on code, you're gonna figure out where its limits are, and you're gonna get better and better and quicker with it.

そして、コードでChatGPTと協力するほど、その限界を理解し、それを使用するのが上手になり、速くなります。

And of course, ChatGPT is going to get better over time.

もちろん、ChatGPTは時間が経てば経つほど良くなっていくでしょう。

The last thing to note is I'm really excited for GitHub Copilot X, which is essentially GitHub Copilot plus ChatGPT in one.

最後に、私はGitHub Copilot Xにとても期待しています。これはGitHub CopilotとChatGPTがひとつになったものです。

So I think it's gonna solve a lot of these context issues when it's launched, so I'm looking forward to that.

これはGitHub CopilotとChatGPTを1つにしたもので、発売されれば、このようなコンテキストの問題の多くを解決してくれると思います。

If you have any questions about how to use ChatGPT as a coding partner, drop it in a comment below.

ChatGPTをコーディングパートナーとして使う方法について何か質問があれば、下のコメント欄に書き込んでください。

I'm happy to answer all those questions.

私はそのような質問にすべて答えることができます。

Maybe I'll make a follow-up video answering them more in depth.

もしかしたら、もっと深く答えるフォローアップビデオを作るかもしれませんね。

If you liked this video, please consider giving a like and subscribe, and I'll see you in the next one.

このビデオが気に入ったら、「いいね!」と「購読」をお願いします!また次のビデオでお会いしましょう。

And I'll see you in the next one.

そして、次のビデオでお会いしましょう。


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