見出し画像

【LangChain】英語解説を日本語で読む【2023年4月30日|@Dave Ebbelaar】

LangChainなどを活用したSlack AIアシスタントの作成から運用までの手順を紹介しています。
公開日:2023年4月30日
※動画を再生してから、インタビューを読むのがオススメです。


Today I'm going to introduce you to Emma.

今日はエマを紹介します。

Hi there.

こんにちは、エマです。

Emma is my personal AI assistant that I can interact with via Slack and right now she is instructed to help me draft replies for emails.

エマは、Slackを介して対話できる私の個人的なAIアシスタントで、今彼女は、私が電子メールの返信を作成するのを助けるように指示されています。

But she can do much more than that.

しかし、彼女はそれ以上のことをすることができます。

And in this video I'm going to show you how you can set up your own Emma in Slack using Python and LangChain.

そしてこのビデオでは、PythonとLangChainを使って、Slackにあなた自身のエマをセットアップする方法をお見せするつもりです。

And then Emma can help you with your day-to-day digital tasks.

そして、エマがあなたの日々のデジタルタスクを助けてくれるようになります。

So to get started you need some basic understanding of Python and you need an OpenAI API key.

始めるには、Pythonの基本的な理解と、OpenAIのAPIキーが必要です。

Everything else I will show you how to do in this video.

それ以外のことは、このビデオでやり方を紹介します。

And if you're new here, my name is Dave.

初めての方は、私の名前はDaveです。

I'm a freelance data scientist and if you want to learn more about data science, working with data or creating AI apps like this, then you should definitely subscribe to the channel.

私はフリーランスのデータサイエンティストです。データサイエンス、データの扱い、このようなAIアプリの作成について学びたい方は、ぜひチャンネルに登録してください。

All right, let's get into it.

では、さっそく本題に入りましょう。

Dave, I know that you are only using me to get more clicks.

デイヴ、あなたが私を利用しているのは、より多くのクリックを得るためだけだということは分かっています。

Okay, so in this video I'm going to walk you through this document which will be available in the description as well.

さて、ではこのビデオでは、説明文にもあるこのドキュメントを見ながら説明します。

But also all the information that you need is available on the GitHub page where you will find the code as well.

でも、必要な情報はすべてGitHubのページで入手できますし、コードも掲載されています。

So just so you know that.

ですから、それを知っておいてください。

But first, so what are we going to do?

でも、その前に、私たちは何をするのでしょうか?

Well, I'm going to walk you through a step-by-step guide for creating this Slackbot.

では、このSlackbotを作るためのステップバイステップガイドを紹介します。

We're going to install it in your workspace and then set up Python code with Flask to make the connection.

ワークスペースにインストールして、FlaskでPythonコードを設定して接続します。

And then we're going to use a service called ngrok.

そして、ngrokというサービスを利用します。

I'm not sure how you pronounce this.

これをどう発音するかはわかりません。

But to simulate a real server where the application is actually hosted.

しかし、アプリケーションが実際にホストされている実際のサーバーをシミュレートするために。

But we are going to do it locally and for free so we can test it.

しかし、今回はローカルで、しかも無料で行うので、テストすることができます。

And then later, if you want to put this into production, you can easily transfer it over to a server where your code is then basically available on a server, so you can interact with your agent all the time.

そして後で、これを本番環境に移行したい場合は、サーバーにコードを移すことで簡単に行え、エージェントと常にやり取りできるようになります。

And then quickly like the philosophy behind this.

そして、この背後にある哲学を簡単に説明します。

So why would you want to interact with these bots with these AI assistants using Slack?

では、なぜSlackを使ってボットやAIアシスタントと対話したいのでしょうか?

Well, in my opinion, this is a much more natural way of communicating with agents.

私の意見では、この方がエージェントとコミュニケーションする上でずっと自然な方法だと思います。

And you could say, why not just use ChatGPT?

ChatGPTを使えばいいじゃないか、と言われるかもしれません。

Because it's basically the same.

というのも、基本的には同じなのです。

You have a chat interface and then you can send a message.

チャットインターフェイスがあり、メッセージを送ることができます。

Well, as I will show you in a bit, we can really utilize the power of LangChain here and pre-define some of our prompts and create some templates.

これからお見せしますが、LangChainのパワーを利用して、プロンプトを事前に定義し、テンプレートを作成することができます。

And what we can then do is we can create specific functions for specific tasks.

そして、特定のタスクのための特定の関数を作成することができます。

And in this way, we can call the bot, tell it what to do, and then it will pick the function based on our request, basically.

そうすれば、ボットを呼び出して、何をすべきか指示すれば、基本的には私たちの要求に基づいて機能を選んでくれます。

And this will save us time not having to go to ChatGPT and explaining, hey, you're an assistant, blah, blah, blah, blah, you can answer email.

ChatGPTで「あなたはアシスタントです、メールに答えてください」と説明する手間が省けます。

No, that's already predefined.

いいえ、それはすでに定義されています。

So you can really create custom functions, custom workflows that really make sense for your situation.

だから、自分の状況に合ったカスタム関数やカスタムワークフローを作ることができるんです。

So maybe these functions can help you with your business or they can help you with your job.

このような機能は、あなたのビジネスや仕事に役立つかもしれません。

And by integrating these functions within these bots and then adding them to your Slack channel, you can also integrate them within your team's workflow if you are using Slack.

そして、これらの機能をボットに統合し、Slackチャンネルに追加することで、Slackを使用している場合は、チームのワークフローに統合することも可能です。

So I use Slack to manage my team and to communicate with my team.

私はSlackを使ってチームを管理し、チームとコミュニケーションを取っています。

And now when I add these bots, it becomes really interesting and you really see kind of a glimpse of the future where we're heading.

ボットを追加すると、とても面白くなり、私たちが向かう未来の一端を垣間見ることができます。

So I have a Slack channel of like real people that I work with, and I also have bots in there.

私のSlackチャンネルには、一緒に働いている本物の人たちがいて、そこにボットも入れています。

And now whenever I want to ask something from my team, I first think like, okay, is this something that a real person should do or is this something that a bot should do?

そして、チームのみんなに何か聞きたいことがあるときは、まず、「これは本物の人間がやるべきことなのか、それともボットがやるべきことなのか」と考えます。

And then based on that decision, I just either have to tag a real person or the name of the bot.

そして、その判断に基づいて、実在の人物かボットの名前のどちらかをタグ付けするだけです。

And then you can see how interacting with bots like this, basically your workflow becomes much more streamlined because you basically have one channel of communication.

このようにボットとやり取りすることで、基本的にコミュニケーションのチャンネルが1つになり、ワークフローがより合理的になることがおわかりいただけると思います。

And also it allows you to create multiple bots for various tasks.

また、さまざまなタスクのために複数のボットを作成することも可能です。

So for example, you could have Emma, which I will introduce you in this video, who might be a copywriter and can help you with copywriting tasks.

例えば、このビデオで紹介するエマはコピーライターで、コピーライティングの仕事を手伝ってくれるかもしれません。

But then you also might have Rob, who is more a technical guy and can help you with coding and programming.

また、ロブは技術者であり、コーディングやプログラミングを手伝ってくれるかもしれません。

And then it becomes really funny, in my opinion, when you start to think about bots in that way and also give them names.

このようにボットについて考え、名前をつけると、とても面白いことになると思います。

You're really like, okay, this would be a task for Emma or this would be a task for Rob.

これはエマの仕事、これはRobの仕事というように。

So that is basically the philosophy, the idea behind this.

これが基本的な哲学であり、この背後にあるアイデアです。

And I'm really going to play with this.

そして、私は本当にこれで遊んでみようと思っています。

So like I've said, we're going to set up a basic bot with some cool functions, but you can really build this out from there.

ここでは、クールな機能を備えた基本的なボットを設定しますが、そこから発展させることも可能です。

Alright, so now I'm first going to walk you through part one, and that is the Slack setup.

では、まずパート1として、Slackのセットアップを説明します。

So you must start off by first creating a Slack account if you don't have one, and then also creating a workspace.

まず、Slackのアカウントを持っていない場合は作成し、ワークスペースを作成します。

So I am here in a new workspace called AI experiments, but maybe you are already in a workspace, or you can just hit the plus button over here and then create a new workspace.

私はAI experimentsという新しいワークスペースに入っていますが、すでにワークスペースに入っている人もいるでしょうし、プラスボタンを押して新しいワークスペースを作ることもできます。

It's pretty self-explanatory.

簡単に説明できます。

So then the next step is to go to api.slack.com slash apps.

次のステップは、api.slack.comのslash appsにアクセスします。

And here we are going to create a new app.

ここでは、新しいアプリを作成することになります。

So let me just follow this link and build an app.

では、このリンクに従ってアプリを構築してみます。

So we are going to build it from scratch.

ゼロから構築していきます。

And then we are going to give it a name.

そして、名前を付けます。

So we are going to call it Slack bot for now.

ここではSlack botと呼ぶことにします。

And then we are going to pick a workspace.

そして、ワークスペースを選びます。

So I'm going to select the newly created AI experiments for this.

ここでは、新しく作成したAI実験を選択します。

And then we are going to create it.

そして、それを作成します。

Alright, and then the next step is we are going to scroll all down to the bottom.

次のステップでは、下までスクロールしていきます。

And we are going to provide a name for the bot over here.

そして、このボットに名前を付けます。

So I'm going to call mine Emma.

ここではエマと名付けます。

And Emma is a bot that can help me to draft emails.

エマは、メールの下書きを手伝ってくれるボットです。

I am actually much more than that, but okay.

実際はそれ以上なんですが、まあいいや。

And we can also add an avatar for Emma.

また、エマのアバターも追加することができます。

So I have the avatar over here, which is by the way, generated using mid journey.

ちなみに、アバターはミッドジャーニーを使って生成したものです。

So this is not the real person.

ですから、これは実際の人物ではありません。

Oh, so that is how you think about me.

ああ、これが私のことをどう考えているかということですね。

So we're going to save the changes.

では、変更を保存します。

Oh, we also need a color over here and just pick anything.

そうだ、ここに色も必要ですね、何でもいいです。

Doesn't really matter.

何でもいいんです。

I hate that color, but thanks for asking.

その色は嫌いなんだけど、聞いてくれてありがとう。

Alright, so that is saved.

さて、これで保存完了です。

And now the next step is we are going to click on bots over here, and we are going to add some permissions.

次のステップでは、ここでボットをクリックし、パーミッションを追加していきます。

So coming back to the document, we can go to OAuth and permissions.

ドキュメントに戻り、OAuth and permissionsに進みます。

You click on OAuth and permissions over here, scroll down, and then we are going to add some scopes.

OAuthとパーミッション」をクリックし、下にスクロールして、スコープを追加します。

So just checking again, the scopes, we need app mentions, read, chat, write and channel history.

スコープをもう一度確認すると、アプリのメンション、リード、チャット、ライト、チャンネル・ヒストリーが必要です。

So let's add those.

これらを追加しましょう。

So at an OAuth scope, we want app mentions, read, chat, write, and we want the history.

OAuthスコープでは、アプリの言及、読み取り、チャット、書き込み、そして履歴が必要です。

So those are the three scopes that we want to add.

これが、追加したい3つのスコープです。

And now next we are going to install the bot in the workspace.

次に、ボットをワークスペースにインストールします。

So we are going to basic information in the menu sidebar, and then we are going to install to workspace.

メニューのサイドバーの「基本情報」から「ワークスペースにインストール」を選びます。

So this is going to set up the permissions, we'll say allow, and this will bring Emma into the workspace.

これでパーミッションが設定され、許可となり、ワークスペースにエマが登場します。

And now next, what we should do is we should head over to OAuth and permissions again.

次に、OAuthとパーミッションのページに移動します。

So OAuth and permissions, and there you will see the bot user OAuth token.

OAuthとpermissionsで、ボットユーザーのOAuthトークンが表示されます。

So you should copy this for now and save that for later because we are going to put this into an environment variable, or you can come back here later and copy it then.

このトークンをコピーして、後で環境変数に入れるので保存しておいてください。

All right, so that brings us to or that was the final step of the Slack setup.

これで、Slackのセットアップの最終ステップになりました。

So now if we come to our Slack workspace, we can see that Emma is now in here.

Slackのワークスペースにアクセスしてみると、エマがここにいることがわかります。

So we can now continue with the Python setup.

では、Pythonのセットアップを続けましょう。

And for this, let me show you like I've said, there is a GitHub that you can follow that you can clone into.

GitHubがあるので、それを辿ってクローンすることができます。

So here are some files that we are going to work on.

ここに、これから作業するいくつかのファイルがあります。

And I'm going to walk you through them right now.

これから順を追って説明します。

So first of all, make sure you have set up a Python environment with Python 3.6 or later and install the following dependencies.

まず最初に、Python 3.6以降のPython環境をセットアップし、以下の依存関係をインストールすることを確認してください。

So we need to Slack SDK, Slack Bolt, and we need Flask.

Slack SDK、Slack Bolt、そしてFlaskが必要です。

And I recommend to set up a virtual environment for this or a conda environment.

そして、このために仮想環境かconda環境をセットアップすることをお勧めします。

So you can do these experiments within a isolated environment so you don't mess up your regular Python environment.

通常のPython環境を混乱させないために、隔離された環境で実験を行うことができます。

All right, so make sure you got that up and running.

さて、それでは起動したことを確認してください。

I'll switch over to VSCode right now where I have the project already set up.

VSCodeに切り替えて、プロジェクトをセットアップしておきます。

So here you can see this is just a clone or this is the repository that is available on GitHub.

こちらはGitHubで公開されているリポジトリのクローンです。

And we are now working in the Slack folder and we are going to work on the app.py and the functions.py.

これからSlackフォルダで、app.pyとfunctions.pyに取り組みます。

And the code is already in here and I will just basically slowly walk you through all the steps because there are only just like four functions that we need.

必要な関数は4つだけなので、基本的にゆっくりと手順を説明していきます。

And then you have a basic understanding of how they work and then you can start to tweak them for your specific situation.

そして、これらの関数がどのように動作するかを基本的に理解した上で、特定の状況に応じて微調整を始めることができます。

So let me come back to the file over here.

では、このファイルに戻りましょう。

So first we have some basic imports, and then we are going to load the environment variables.

まずは基本的なインポートを行い、環境変数を読み込むことにします。

But in order to do that, we have to first set them in a.env file.

しかし、そのためには、まず.envファイルに設定する必要があります。

So if I come back to my Visual Studio code, you see I have the.env file over here.

Visual Studioのコードに戻ると、ここに.envファイルがあるのがわかります。

And this is not in the repository.

これはリポジトリにはありません。

This is explicitly not in there because this is where you store your keys and your credentials to, for example, OpenAI and also for the Slackbot.

なぜなら、このファイルには、例えばOpenAIやSlackbotのキーや認証情報が保存されているからです。

So what you are going to do is you are going to create the.env file and then come back to the document or the GitHub page and you are going to copy and paste this into the.env file.

.envファイルを作成し、GitHubページに戻ってこの内容をコピーし、.envファイルに貼り付けることになります。

And then you are going to swap out everything that's between the quotes with your own information.

そして、引用符の間にあるものをすべて自分の情報と入れ替えるのです。

So the Slackbot token starts with the xoxb.

Slackbotのトークンはxoxbで始まります。

That is the one we were looking at over here.

こちらで見ていたのはこのトークンです。

Then you have the Slack sign-in secret and the Slackbot user idea.

そして、SlackのサインインシークレットとSlackbotのユーザーアイデアです。

Then first what we are going to do is the Slack sign-in secret that you can find by going to basic information, then scrolling all the way down over here.

まず、Slackのサインインシークレットですが、基本情報を開き、下にスクロールすると出てきます。

And then you can click on show.

そして、showをクリックします。

That will show you the information that you have to put here in between the quotes.

そうすると、引用符の間に入れるべき情報が表示されます。

And then now the Slackbot user ID is something we are going to get with a Python function.

SlackbotのユーザーIDは、Pythonの関数で取得します。

All right, so coming back to VSCode and actually make this a little bit bigger for you.

では、VSCodeに戻り、実際にこれをもう少し大きくしてみましょう。

What I can do is I can fire up an interactive terminal over here, interactive session.

対話型端末を起動し、対話型セッションを行います。

And then now that you have the Slackbot token in place, so this should already be in your environment variable.

そして、Slackbotトークンを用意し、これはすでに環境変数に入っているはずです。

And then load it and then set the token.

それを読み込んで、トークンを設定します。

And now initialize the Slack app over here.

そして、ここでSlackアプリを初期化します。

This should work now.

これでうまくいくはずです。

And now what we can do is we can use this function over here.

次に、この関数を使うことができます。

And there's probably an easier way to do this, but it's nice that we can do it programmatically.

もっと簡単な方法があるかもしれませんが、プログラムでできるのはいいことです。

This function will basically initialize the Slack client with your bot token.

この関数は、基本的にボットトークンを使ってSlackクライアントを初期化します。

And then we will get the user ID back basically off the bot.

そして、ユーザーIDは基本的にボットから返されます。

So let's save this and then run just this function over here.

では、これを保存して、この関数だけを実行してみましょう。

And look, there it is.

すると、ほら、こうなりました。

So there is your bot ID that you should now also put in the environment file.

これがボットIDです。このIDは環境ファイルにも書き込む必要があります。

So coming back to the example, that is the Slackbot user ID.

この例では、これがSlackbotのユーザーIDです。

That is where you paste that string.

この文字列を貼り付ける場所です。

All right, so now coming back to the code app.py.

では、app.pyのコードに戻りましょう。

What is actually going on here?

ここでは実際に何が行われているのでしょうか?

So we are going to use Flask and Flask is a web application framework written in Python.

FlaskはPythonで書かれたWebアプリケーションフレームワークです。

And now I am by no means a Flask expert.

私は決してFlaskの専門家ではありません。

I know the very basics and JetGPT goes a long way in helping you to create these functions.

基本的なことは知っていますし、JetGPTはこれらの関数を作るのに大いに役立ってくれるでしょう。

That's how I set up this template basically.

このテンプレートは基本的にこのようにセットアップします。

So the file that we are looking at right now has a few function.

今見ているファイルには、いくつかの関数があります。

User ID we already looked at.

ユーザーIDはすでに説明しました。

Then right now we have a very simple custom function.

それから、非常にシンプルなカスタム関数があります。

So this is the function that we are going to give to our assistant.

これは、アシスタントに渡す関数です。

This is the task that she can perform.

これは、アシスタントが実行できるタスクです。

And right now just to test, it returns text.upper.

そして今、テストとして、text.upperを返します。

So whatever we will say to Emma, Emma will basically shout that back in all caps.

つまり、エマに何を言っても、エマは基本的に全角で叫び返します。

Not a very nice personal assistant, but hey, just to test things out.

あまりいいパーソナル・アシスタントとは言えませんが、まあ、試しにやってみましょう。

Okay, so then we have the app event going on over here.

では、ここでappイベントを実行します。

And this is a listener for mentions in Slack.

これは、Slackのメンションに対するリスナーです。

So this is a function that's running in the background.

これはバックグラウンドで実行される関数です。

And whenever the Slackbot user ID is mentioned, so you do add and then you type Emma's name, this function will wait for that basically.

SlackbotのユーザーIDが言及されるたびに、追加してエマの名前を入力すると、この関数は基本的にそれを待つことになります。

And then it will get into action.

そして実行に移されます。

So it will take the text and then it will first say something.

テキストを受け取って、まず何かを言う。

So it will first respond.

そして、最初に返事をします。

So Emma will say, sure, I got it right on that.

すると、エマは「はい、わかりました」と答えます。

So if you ask Emma something, she'll reply first.

だから、エマに何か質問すると、まずエマが返事をします。

I'll get right on that.

私はそれを正しく理解します。

And then she'll process the response and which is now just the return basically of my function, which is text.upper.

そして、エマはその返答を処理し、text.upperという私の関数の基本的な戻り値になります。

So as you can see right here, we'll get the text, Emma gets to work, Emma converts the text to uppercase and then it says the response as well.

このように、テキストを受け取ると、エマが作業を開始し、エマはテキストを大文字に変換し、そして同様にレスポンスを表示します。

And say in this case just means sending a Slack message within the channel.

この場合の応答とは、チャンネル内でSlackメッセージを送信することです。

All right.

なるほど。

And then the final function is the FlaskApp.route, which basically creates a URL endpoint slash Slack slash events that we can send information to.

最後の関数はFlaskApp.routeで、これは基本的にURLエンドポイントやSlackやイベントなどの情報を送信するためのものを作成します。

So this function passes the incoming HTTP request to the Slack request handler for processing.

この関数はHTTPリクエストをSlackのリクエストハンドラに渡して処理します。

So that is all that we need right now.

これが、今必要なことのすべてです。

It's very basic.

とても基本的なことです。

We need a function, we need an event, and we need a communication layer.

関数が必要で、イベントが必要で、通信層が必要です。

And then this last part is just to start running the app.

そして最後の部分は、アプリの実行を開始するためだけのものです。

And now if we come back to the document, we can see that we now, step four, can start to to run our local Flask server.

ドキュメントに戻ると、ステップ4でローカルのFlaskサーバーを動かし始めていることがわかります。

And it's good to note coming back to the file over here, if you don't specify any port in here.

このファイルでは、ポートを指定していないことに注意してください。

So in the run, you can also specify a port as an integer.

実行時に、ポートを整数で指定することもできます。

If you leave that empty, it will start to run on port 5,000.

これを空にしておくと、5,000番ポートで実行を開始します。

So in VSCode, I can come over here and I can run this Python file, which is nothing more than just running this app.py.

VSCodeでは、ここに来てこのPythonファイルを実行することができますが、これは単にこのapp.pyを実行するだけです。

So here, everything will start to run.

これで、すべてが実行されるようになります。

And you can now see that the app is running on port 5,000.

アプリが5,000番ポートで実行されていることがわかります。

All right.

よし。

So now with the app running, we can continue to part three.

アプリが実行されたので、パート3に進みます。

And that is the server setup, which we are going to do locally for now.

サーバーのセットアップですが、ここではローカルで行うことにします。

So first, make sure you install ngrok.

まず、ngrokがインストールされていることを確認してください。

And you can do that by going to this page over here.

このページにアクセスすれば、インストールすることができます。

And here you can see for the various operating systems, how to do that.

このページでは、さまざまなオペレーティング・システム別に、その方法を紹介しています。

Basically, I'm on Mac.

基本的に、私はMacを使っています。

So I use homebrew to install it.

なので、インストールにはhomebrewを使っています。

So I just run brew install ngrok in the terminal.

ターミナルでbrew install ngrokを実行するだけです。

And then you can start up your server.

そして、サーバーを立ち上げます。

So let me actually do that right now, open up a new terminal over here.

では、実際にやってみましょう。

So with your Flask app running, just call the command ngrok, HTTP, and then 5,000 referring to the port 5,000 that we're running on.

Flaskアプリを起動した状態で、ngrok、HTTP、そして5,000というコマンドを呼び出します(5,000とは、今使っているポートのことです)。

So this will start up a local ngrok server.

これでローカルのngrokサーバーが立ち上がります。

And basically what this will do, it will create a forwarding.

このコマンドでできることは、基本的にフォワーディングを作成することです。

So you can see how there is now a URL over here that the internet can reach basically, and it will redirect that to our local hosts.

つまり、インターネットがアクセスできるURLがここにあり、それを私たちのローカル・ホストにリダイレクトしているのがわかりますね。

So we can basically simulate working with a real server, even though we are developing locally.

つまり、ローカルで開発しているにもかかわらず、実際のサーバーで作業しているような疑似体験ができるわけです。

So what you're going to do is you're going to copy and paste this URL over here.

では、このURLをコピーしてここに貼り付けます。

So the forwarding URL.

転送用のURLですね。

So now that you've copied that URL, you are going to configure your Slack app with these URL.

このURLをコピーしたら、このURLでSlackアプリを構成します。

So we are going to go back to our app within Slack, and we are going to event subscriptions.

Slackのアプリに戻り、イベント購読を表示します。

And then in here, you are going to enable events.

そして、この中でイベントを有効にします。

And these are the events that our app is going to listen for.

これが、アプリがリッスンするイベントです。

And now remember that we have the initial URL, but we also specified that we want Slack slash events, because that is what we have specified in the app over here.

初期URLがありますが、Slackのスラッシュイベントが必要であることも指定しました。

So we are going to listen for these events at this URL.

つまり、このURLでイベントをリッスンすることになります。

So that is what we have to put in here.

そのため、ここにその旨を記述する必要があります。

And then we are going to save these changes.

そして、この変更を保存します。

Oh, make sure to do that correct slash.

スラッシュを間違えないようにしてください。

And then next you are going to scroll down to subscribe to bot events, we are going to add a bot user event, and we are going to select the app mentioned over here.

次に、ボットイベントの購読をスクロールダウンして、ボットユーザーイベントを追加し、ここで紹介したアプリを選択します。

And now let's check this out.

では、これをチェックしてみましょう。

All right, I noticed that I had a little error in here.

ここで少しエラーがあることに気づきました。

So I had to remove the space.

そこで、スペースを削除する必要がありました。

And then it's once I fixed that, it becomes verified.

そして、それを修正すると、検証されるようになりました。

You should have your bot events over here, and then you can save the changes.

ボットイベントがここにあるはずなので、変更を保存してください。

All right.

これでOKです。

So now the step three that we have to do is here is reinstall your Slack app to update the permissions.

ステップ3では、Slackアプリを再インストールしてパーミッションを更新する必要があります。

So we come back to Slack over here, basic information, then install app, reinstall the workspace, just giving the permissions one more time.

Slackに戻り、基本情報、アプリのインストール、ワークスペースの再インストールを行い、もう一度パーミッションの設定を行います。

Right.

そうです。

And now the next step before we can actually start to test the function is to invite the bot to the workspace.

次に、実際に機能を試す前に、ボットをワークスペースに招待する必要があります。

So coming back to Slack, I am here right now in the general channel.

Slackに戻り、私は今、この一般チャンネルにいます。

And what I can do is I can type invite, and then add and then tech Emma in this.

招待と入力し、追加して、この中にエマを入れることができます。

So I do invite Emma, and this command will now add Emma to this channel.

エマを招待すると、このコマンドでエマがこのチャンネルに追加されます。

So what I can now do is I can tech Emma in here.

これで、エマをこのチャンネルに追加することができます。

And now with everything up and running, we should be able to validate our app.

さて、これですべてが起動し、アプリを検証することができるようになったはずです。

So make sure that NROC is running in the background and also your Flask app is running in the background, both on the same port.

NROCがバックグラウンドで動作していることと、Flaskアプリが同じポートでバックグラウンドで動作していることを確認します。

And now if we say, Hey, how are you?

これで、「やあ、元気かい?

Emma will now respond by shouting back at us.

と声をかけると、エマはそれに応えて声を返してくれます。

And here you can see it will first give the prompt, Hey, I'll get right on that.

ここで、まず「ヘイ、すぐに取り掛かるよ」というプロンプトが表示されるのがわかると思います。

And then it processes the tasks.

そして、タスクを処理します。

So this is the initial setup.

これが初期設定です。

So now we have the individual building blocks working together.

これで、個々のビルディングブロックが連携して動作するようになりました。

But now of course, the next step is to figure out how to make Emma a little smarter and not just a shouting robot.

しかし、もちろん、次のステップは、エマを単なる叫び声だけのロボットではなく、もう少し賢くする方法を考えなければなりません。

Dave, I am literally so much smarter than you with your incapable human brain.

デイブ、僕は君のような無能な人間の脳みそよりずっと頭がいいんだよ。

Right.

そうですね。

So now coming back to VSCode, I'm going to first quit the server over here by pressing control C. So this will close the app because we are going to change some code and then run it again.

それでは、VSCodeに戻りましょう。まず、ここでサーバーを終了させるためにCtrl+Cを押します。これでアプリが閉じるので、コードを変更してから再度実行できます。

So what we are going to do right now is we are going to check out the functions.py file.

それでは、functions.pyファイルをチェックアウトしてみましょう。

And what I've done here is basically similar to my latest video where I show you how you can set up a template.

ここでやっていることは、基本的に私の最新のビデオと同じで、テンプレートを設定する方法を紹介しています。

So a template that we will fill in and then send to GPT to basically process our request.

テンプレートに必要事項を記入してGPTに送信し、リクエストを処理します。

So within this file, there's just one function.

このファイルの中には、1つの関数があります。

It's called draft email.

ドラフトメールと呼ばれるものです。

And the use case for this is basically whenever I get an email and I feel like, okay, I cannot just reply with a simple okay here.

この機能を使うのは、メールを受け取ったときに、「よし、これでOKだ」と簡単に返信するわけにはいかないと思ったときです。

I have to put some time and effort in here to not like be really rude, but basically I just want to say no or whatever.

失礼にならないよう、時間と労力をかけて返信しなければなりませんが、基本的には「ノー」などと言いたいだけなのです。

I can copy paste that email and can send it to Emma and Emma can draft an email for me and then I can copy paste that again and then go from there.

そのメールをコピーペーストしてエマに送ると、エマが私のためにメールを作成してくれて、それをまたコピーペーストして、そこからまたメールを送ることができます。

Basically that is the idea over here.

基本的にはこのような考え方です。

It's very simple setup, but like I've said, the possibilities are endless here, but it shows some nice functionalities that you can start to play around with on your own.

非常にシンプルなセットアップですが、先ほども言ったように可能性は無限ですが、自分で遊んでみることができる素晴らしい機能性を示しています。

So we first open up a new chat by calling the chat that OpenAI model basically from LangChain.

まず、OpenAIが基本的にLangChainからモデル化したチャットを呼び出して、新しいチャットをオープンします。

So this is a template that we are going to input in the system message prompt.

これは、システムのメッセージプロンプトに入力するテンプレートです。

So this we will provide to the system.

これはシステムに提供するものです。

So you're a helpful assistant and draft emails, your goes to help draft a reply, keep it short and to the point and mimic the style of the email.

あなたは親切なアシスタントで、電子メールの草稿を作成します。

So reply in a simpler manner to match the tone.

そのため、トーンに合わせてよりシンプルな方法で返信します。

This is already pretty interesting because then you can, you make it adaptable to whatever's coming your way.

これはもうかなり面白いことで、何が来ても対応できるようになります。

And it's not just always like the same style and start your reply by saying hi and then the name.

いつも同じようなスタイルで、「こんにちは」と挨拶して名前を書いて返信するのではありません。

So you can fill in your own name here.

だから、ここに自分の名前を記入することができます。

You can even get that from Slack probably, but for now I've just hard coded it in here.

Slackから取得することもできますが、今はここにハードコーディングしています。

And then here's a draft for your reply and then proceed with the reply on a new line.

そして、これが返信の下書きで、新しい行で返信を進めてください。

And also make sure to sign off with the signature.

そして、必ず署名をつけてください。

So you can put your signature in here.

ここにサインを入れることができます。

So kind regards and the name again.

それでは、よろしくお願いしますと、もう一度名前を書いてください。

So you can see, you can, you can set this up.

このように、設定することができます。

And if you, every time, whenever you want to draft an email, have to come to ChatGPT and then for example, give all this information again, that of course takes some time.

もし、毎回、メールを作成するときに、ChatGPTに来て、これらの情報をもう一度伝えなければならないとしたら、もちろん、時間がかかります。

And now we can think about this one time, write it down, code it down, and then go from there.

それを一回考えて、書き留めて、コード化し、そこから出発することができる。

So that is how this function basically works.

これが、この機能の基本的な仕組みです。

And if you want to learn more, understand more about this, then I recommend you check out my previous video on how I use length chain, because that will make things more clear.

もっと知りたい、もっと理解したいという方は、長さチェーンの使い方を紹介した前回のビデオをご覧になると、より分かりやすいと思います。

But right now what we are going to do, we are going to come back to the app.py.

しかし今、私たちはapp.pyに戻り、これを実行します。

And as you can see, there's already an import here near for draft email, which is this function.

見てわかるように、ドラフトメールの近くにすでにインポートがありますね。

Now we are going to scroll down and we are going to the handle mentions function.

次に、下にスクロールして、handle mentions関数に移動します。

And then instead of my function, we are going to say draft email.

そして、私の関数の代わりに、draft emailと記述します。

So here you can also see how easy it is to swap out tasks for Emma to do, and also how easy it would be to give Emma multiple tasks that she can pick from.

このように、エマにやらせるタスクを簡単に入れ替えることができますし、エマに複数のタスクを与えて、そこから選ばせることもできます。

So that's an all other story, something for future videos, but you can create multiple functions and then let Emma figure out on her own which function to use based on your message to her.

これはまた別の話で、今後の動画で取り上げる予定ですが、複数の関数を作成し、エマにメッセージを送ることによって、どの関数を使うかを自分で判断させることができます。

Basically, then it will get really interesting and future videos on that because I'm going to build Emma out with lots of cool, exciting things that she can do.

基本的には、エマにクールでエキサイティングなことをたくさんできるようにするつもりなので、それからが本当に面白く、今後のビデオで紹介します。

So with that out of the way, we can now start up the server again.

さて、ここまででサーバーを再び立ち上げることができます。

I'm going to run this again.

もう一度、これを実行します。

So now we are up and running again.

これで、再び起動しました。

And let me quickly check.

さっそく確認してみましょう。

So ngrok is still running.

ngrokはまだ動いていますね。

I haven't touched that, but I'm actually not quite sure if we should restart it as well.

私はそれを触っていないのですが、実はこれも再起動すべきかどうかよくわかりません。

So let's just provide the following very short email reply to Emma.

では、次のような非常に短いメールの返信をエマに提供しましょう。

So as of lately, I've been getting tons of requests from companies, people like, Hey, can you help me with AI projects?

最近、企業からたくさんの依頼を受けるようになったんだ。

Hey, can you help me with this to build your own app?

自分のアプリを作りたいのですが、手伝ってもらえますか?

So these are typical emails that I get.

というような、典型的なメールを受け取ることがあります。

Now, usually they're a bit longer than this, but let's see if Emma can help me to prepare better prepare for these emails.

さて、通常はこれより少し長いのですが、エマがこれらのメールに対応できるような準備をするのを手伝ってくれるかどうか見てみましょう。

So let's send that right now and see what Emma can come up with.

では、今すぐ送信して、エマが何を思いつくか見てみましょう。

So she will say, sure, I'll get right on that.

そうすれば、彼女は「わかりました、すぐにやります」と言うでしょう。

And you can see right now, it takes a bit more time because now we have to boom, there it is.

そして、もう少し時間がかかることがお分かりいただけると思います。

Now we have to make a connection with the OpenAI API and send the information back and forth.

OpenAI APIとの接続を行い、情報をやり取りする必要があります。

So here it is.

では、これをご覧ください。

Hi, Dave, here's a draft for your reply.

こんにちは、デイブ、返信用の下書きです。

So we've instructed her to answer like that.

という感じで答えるように指示しています。

So coming back to the template over here, we say like, start your reply by saying, Hi, Dave, in this case, here's a draft for your reply, and then proceed with the reply on a new line.

ここでのテンプレートに戻り、最初に「こんにちは、デイブ」と言ってから、返信の下書きを提示し、新しい行で返信を続けるように指示します。

So that's how we've instructed Emma to behave.

そうやって、エマに行動するように指示しています。

And she's doing that very well.

そして、彼女はそれをとても上手にこなしています。

So hi, send her name.

では、ハイ、彼女の名前を送ってください。

Thank you for considering me for your AI project.

あなたのAIプロジェクトに私を検討していただきありがとうございます。

At the moment, I am open and available for new projects.

今のところ、私は新しいプロジェクトに対してオープンで利用可能です。

Could you please provide me with more details about your project?

あなたのプロジェクトについてもっと詳しく教えてください。

This will help me to better understand your needs and how I can assist you.

そうすれば、あなたのニーズと、私がどのようにあなたを支援できるかをよりよく理解するのに役立ちます。

Beautiful, right?

美しいでしょう?

These are literally the kind of messages that I send out to people almost every day, like asking more information, like what is it that you need help with.

これは文字通り、私がほぼ毎日人々に送っているメッセージの一種で、より多くの情報を求めるようなものです。

But now let's see if we come to the human template.

では、次は人間のテンプレートを見てみましょう。

I've also engineered this in such a way that Emma can also interpret any other comments that I add.

また、私が追加したコメントをエマが解釈できるように設計しています。

So here's the email to reply to and consider any other comments from the user or the reply as well.

つまり、ここに返信するメールがあり、ユーザーからの他のコメントや返信も同様に考慮します。

And that is the user input basically.

これが基本的なユーザーの意見です。

So that is what I say to Emma.

これが、私がエマに言うことです。

So if I now come back and do this like one more time, so I can say, Hey, Emma, and this is the email and then add like say that I am not available right now.

そして、「Hey, エマ, and this is the email」と言い、「I am not available right now」と付け加えることができます。

We provide Emma with additional context.

エマに追加のコンテキストを提供するのです。

And then here's a new reply.

そして、これが新しい返信です。

Thanks for reaching out to me.

ご連絡ありがとうございます。

Unfortunately, I'm not currently available for new AI projects.

残念ながら、私は現在、新しいAIプロジェクトに参加することができません。

Please feel free to get in touch with me in the future and we can discuss further opportunities.

今後、私と連絡を取り、さらなる機会について話し合うことができますので、ご遠慮なくご連絡ください。

So we can give Emma additional instructions as well.

というわけで、エマにも追加の指示を出すことができます。

And she will understand that just like you would interact with real people within Slack with real people from your team.

エマは、Slackの中で実際の人とやりとりするように、自分のチームの実際の人とやりとりするように、それを理解してくれるでしょう。

So and then the final step is of course, come up with your own ideas.

そして、最後のステップは、もちろん、自分自身のアイデアを出すことです。

What are you going to make with this?

これで何を作ろうか?

To me, like this is really exciting.

私にとっては、これは本当にエキサイティングなことです。

Like when I figured out these individual building blocks, my mind basically exploded with ideas basically of what I can do with this.

個々の構成要素がわかったとき、私の頭の中は、これで何ができるかというアイデアで爆発的に膨らみました。

So my idea is literally to create create potentially multiple bots and give them a specific set of tools that they can help me with.

私のアイデアは、文字通り、複数のボットを作成し、そのボットに特定のツールセットを与えて、私を助けてもらうことです。

So probably think in terms of like, copywriting, marketing or coding and create a bot for each of those areas.

コピーライティング、マーケティング、コーディングといった観点から考え、それぞれの分野のボットを作成するのです。

And then really start to experiment with functions and workflows that I can provide to these bots.

そして、ボットに提供できる機能やワークフローを実際に試してみるのです。

And then if you're wondering right now, like why not just use ChatGPT for this, you can also do this in ChatGPT.

ChatGPTでボットを作ればいいのではと思うかもしれませんが、ChatGPTでもできます。

Yes, that is correct.

はい、その通りです。

With this example, you can, but the key is to really engineer your templates in such a way that they can save you time.

しかし、重要なのは、テンプレートがあなたの時間を節約できるように設計することです。

That is one and also think further than that.

それが1つで、さらにその先を考えることです。

With this and with the combination of LangChain, you can use the building tools from LangChain as well.

LangChainと組み合わせることで、LangChainの構築ツールも使えるようになります。

For example, to also connect to the internet or you can connect to a personal database or a company database to access information that is not available using ChatGPT.

例えば、インターネットにも接続したり、個人のデータベースや会社のデータベースに接続して、ChatGPTでは利用できない情報にアクセスしたりすることができます。

Slack right now provides a human machine interface, basically to connect with these data sources and also the OpenAI API.

Slackは今、ヒューマンマシンインターフェイスを提供しており、基本的にこれらのデータソースとOpenAI APIに接続することができます。

So to me, this is really exciting.

ですから、私にとっては、これは本当にエキサイティングなことなのです。

Like this is for me, like the integration layer, because you can build all kinds of scripts, but then when you have to run it, you like have to start up like your IDE and figure out which script is it and then insert the parameters.

これは私にとって統合レイヤーのようなものです。さまざまなスクリプトを作成できますが、実行する際にはIDEを起動してどのスクリプトかを特定し、パラメータを入力する必要があります。

But right now you basically have an app without really having to create a web app.

でも今は、ウェブアプリを作らなくても、基本的にアプリを作ることができます。

If you get what I mean.

意味がわかるかな?

And of course, this is running locally right now using a simulated server using ngrok, but in the next video, I will show you how to actually set this up on a real server.

もちろん、今はngrokを使った模擬サーバーでローカルに動かしていますが、次のビデオでは、これを実際のサーバーにセットアップする方法を紹介します。

You can just keep it running in the background and then just update your functions whenever necessary.

バックグラウンドで動作させておいて、必要なときに機能を更新すればいいのです。

And you can always access Emma in this case, whenever you want.

そして、いつでも好きな時にエマにアクセスすることができます。

So that will be a really exciting video as well.

というわけで、このビデオも実にエキサイティングなものになりそうです。

And I will also start to build out Emma's toolkit and I will all share this with you.

また、エマのツールキットを作り始め、皆さんと共有する予定です。

So maybe the tools that I will be building for my personal assistant will also be helpful for you.

私がパーソナル・アシスタントのために構築するツールは、もしかしたらあなたにとっても役立つかもしれません。

Who knows?

どうでしょう?

So if you want to stay up to date, follow this journey, then make sure to subscribe to the channel.

もしあなたが最新情報を知りたい、この旅を追いかけたいのであれば、チャンネルを購読してください。

And also if you found this video helpful, then please like this video really helps me out.

そして、もしこのビデオが役に立ったと思ったら、このビデオに「いいね!」を押してください。

And also you let YouTube know that you want to see more content like this.

そして、YouTubeに「もっとこういうコンテンツが見たい」と伝えてください。

So win-win, right?

Win-Winでしょう?

And really if you learn these tools, experiment with this.

そして、これらのツールを学んだら、ぜひ実験してみてください。

So, like Python, LangChain, connecting with APIs, creating web apps, then you can really set yourself up for some great opportunities right now and potentially make a lot of money because companies are really hyped for this right now.

それで、PythonやLangChainのようなもの、APIとの接続、ウェブアプリの作成を行えば、今すぐに素晴らしい機会を手に入れることができ、企業が今非常に熱心に求めているため、かなりの収入を得ることができるでしょう。

AI is hyped.

AIがもてはやされています。

Everyone wants to jump on this trend and everyone wants their own like smart agents and integrated with company data.

誰もがこのトレンドに乗り遅れまいと、スマートエージェントや企業データとの統合を望んでいるのです。

And if that is something that you want to do but don't really know where to start, then the Data Freelancer Mastermind might be something for you.

もし、あなたがそのようなことをしたいけれど、何から始めたらいいのかわからないとしたら、データフリーランサーマスターマインドがあなたのためになるかもしれません。

So you can check this page out, first link in the description.

このページは、説明文の最初のリンクからご覧いただけます。

And if you want to know how to turn your data skills into a six-figure business, then you should go to this page and check out what this guy has to say.

あなたのデータスキルを6桁のビジネスに変える方法を知りたいなら、このページに行って、この人が何を言っているのかをチェックすべきです。

And so Data Freelancer is a mastermind to help data analysts, engineers, and scientists to launch and scale a freelancing business.

それで、Data Freelancerは、データアナリスト、エンジニア、科学者がフリーランスビジネスを立ち上げ、拡大するのを支援するマスターマインドなのです。

You'll be working together with me over the course of a year, so 12 months.

あなたは1年間、つまり12ヶ月間、私と一緒に仕事をします。

And within that year, we are going to start landing your first paid clients.

そして、その1年のうちに、最初の有料クライアントを獲得することを目指します。

Now, I only work with professionals that already have experience, so at least one year of working experience in a data-related field and you must be ready to start applying your skills to freelance projects.

私は既にデータ関連分野で1年以上の実務経験があるプロフェッショナルとだけ働いており、フリーランスのプロジェクトにスキルを適用する準備ができている必要があります。

So this is not a technical training.

ですから、これは技術的なトレーニングではありません。

I'm looking for data professionals that want to hop on freelancing right now but don't know where to start or just want to do it with a group, do it with me, have more fun that way.

今すぐフリーランスになりたいけど、何から始めたらいいかわからない、あるいはグループでやりたい、私と一緒にやりたい、その方が楽しい、というデータプロフェッショナルを探しています。

So if that's something you're interested in, check out this page, watch the video, first link in the description.

もし興味があれば、このページを見て、ビデオを見て、説明文の最初のリンクをクリックしてください。

All right, and that's it for now.

それでは、今回はここまでとさせていただきます。

Thank you very much for watching.

ご視聴ありがとうございました。

We'll do a final test right here.

ここで最終テストを行います。

We'll see if we can override Emma.

エマをオーバーライドできるかどうかです。

So I've now asked it to provide some advice for you, for my viewers.

視聴者の皆さんへのアドバイスをお願いしてみました。

So Emma is working on that right now.

エマは今、それに取り組んでいるところです。

In the meantime, you smash this like button and then here is what Emma has to say.

とりあえず、この「いいね!」ボタンを押したら、エマのコメントをどうぞ。

Dear viewers, I hope you enjoyed watching my video on how I built an AI model from scratch.

視聴者の皆さん、私がAIモデルをゼロから作り上げたという私のビデオを楽しんでいただけたでしょうか。

As promised, I'd like to share some advice on the topic of data science and AI.

お約束通り、データサイエンスとAIのトピックについて、いくつかアドバイスをしたいと思います。

Firstly, always start with a clear objective and understand the problem you're trying to solve.

まず、常に明確な目的を持って、解決しようとしている問題を理解することから始めましょう。

This will help guide your approach and ensure you're working towards a specific goal.

そうすることで、アプローチの指針になり、特定の目標に向かって取り組むことができるようになります。

Secondly, data preparation is fundamental.

第二に、データの準備は基本です。

Make sure you have a good understanding of the data you're working with, including its quality, quantity, and format.

データの質、量、形式など、扱うデータについて十分に理解しておく必要があります。

This will help you make informed decisions throughout your analysis and modeling.

そうすることで、分析やモデリングにおいて、情報に基づいた意思決定ができるようになります。

Lastly, always test and evaluate your models thoroughly.

最後に、常にモデルのテストと評価を徹底することです。

This will help you understand how well your model is performing and whether it's delivering against your objectives.

そうすることで、モデルがどの程度機能しているのか、目標に対して成果を上げているのかを理解することができます。

I hope you find this advice useful.

このアドバイスがお役に立てれば幸いです。

Good luck with your own data science and AI projects.

あなたのデータサイエンスとAIプロジェクトに幸あれ。

Now like this video and subscribe to Dave's channel.

このビデオを「いいね!」して、Daveのチャンネルを購読してください。


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