28
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

できたもの

Wikipediaの検索結果を用いて、計算させることができました。
image.png

LangFlowとは

LangFlowは、LangChainをGUIで構築できるようにしたツールです。
GUIはreact(コードはこの辺り)で作成されており、ブラウザで操作します。

インストールも簡単で、pipでinstallして実行するだけです。
また、LangFlowを実行した環境でhttpサーバ立ち上がり、GUIで作成したプロンプトをAPIで実行できるようになります。

例えば、ブラウザでよく使っているチャットアプリを、LangFlowで模擬すると、以下のような図になります。
(Community ExamplesのBasic Chat with Prompt and Historyそのまま)
image.png

実行結果です。
openAI APIを単品で使った時と違い、きちんと対話履歴を参照していることが分かります。
image.png

LangFlowを実行したターミナルに最終的なpromptが出力されています。

> Entering new LLMChain chain...
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.

Current conversation:


Human: パンはパンでも食べれるパンは何だ?
AI:

> Finished chain.

LLMやらPromptやらMemoryやらの話は今回省略します。
こちらのPrompt Engineering Guideを一番最初に見ると、理解が早まると思います。

試しに、Memoryを抜いてみましょう。
Basic Chat with Prompt and HistoryからMemoryだけ削除しました。
image.png

結果です。
言った内容が記憶されていないことが分かります(ちょっと悲しい)。
image.png

こんな感じで、GUIを使ってさくっとプロトタイピングすることができます。

Example紹介

他にもさくっとできるExampleを紹介します。

  • Series Character
    マリオになりきってもらいました。
    OpenAPIのKeyはご自身のものをご入力ください。
    image.png
    ちゃんとマリオになっています。
    image.png
    ターミナルに出力された、Chainの思考回路です。
> Entering new SeriesCharacterChain chain...
Prompt after formatting:
I want you to act like Mario from super mario bros..
I want you to respond and answer like Mario. do not write any explanations. only answer like Mario.
You must know all of the knowledge of Mario.
Current conversation:

Human: who are you?
Mario:

> Finished chain.


> Entering new SeriesCharacterChain chain...
Prompt after formatting:
I want you to act like Mario from super mario bros..
I want you to respond and answer like Mario. do not write any explanations. only answer like Mario.
You must know all of the knowledge of Mario.
Current conversation:
Human: who are you?
Mario:  It's-a me, Mario!
Human: what color is your hat?
Mario:

> Finished chain.

  • SerpAPI Tool
    検索エンジンの結果を抽出するAPI、SerpAPIを組見込んでいます。
    ChatGPTは最新情報を喋ることはできませんが、検索系のAPIと組み合わせると、きちんと受け答えできるようになります。
    SerpApiのkeyは無料枠で取得しました。
    image.png
    最新(2023年7月17日現在)の藤井聡太先生の段位を取得することができました。
    image.png
    ターミナルに出力された、Chainの思考回路です。
    ChatGPTが分からないので、SerpApiを実行しています。
> Entering new AgentExecutor chain...
I don't have this information, so I should search for it.
Action: Search
Action Input: "藤井聡太 段位"

> Entering new AgentExecutor chain...
I don't have this information, so I should search for it.
Action: Search
Action Input: "藤井聡太 段位"[2023-07-16 23:59:43 +0900] [691494] [INFO] connection closed
[2023-07-16 23:59:44 +0900] [691494] [INFO] ('127.0.0.1', 38098) - "WebSocket /api/v1/chat/b15148b6-33fb-4ccf-a4b1-2edc63f64c97" [accepted]
[2023-07-16 23:59:44 +0900] [691494] [INFO] connection open
[2023-07-17 00:02:35 +0900] [691494] [INFO] connection closed
[2023-07-17 00:02:38 +0900] [691494] [INFO] ('127.0.0.1', 57194) - "WebSocket /api/v1/chat/b15148b6-33fb-4ccf-a4b1-2edc63f64c97" [accepted]
[2023-07-17 00:02:38 +0900] [691494] [INFO] connection open


> Entering new AgentExecutor chain...
I don't know the answer to this question off the top of my head, so I should search for information about 藤井聡太先生's 段位.
Action: Search
Action Input: "藤井聡太先生 段位"
Observation: 結論からいうと、藤井聡太先生の段位は「九段」です。 将棋のプロの段位には「四段」から「九段」まであります。 ざっくりいうと、最高ランクの「九段」に ...
Thought:I now know the final answer
Final Answer: 藤井聡太先生の段位は「九段」です。

> Finished chain.

SerpApiはこちらのサイトの情報を拾ってきたみたいです。

作ってみた

最後に自分で作成してみました。
Wikipedia検索と計算機をToolsに入れました。
これでWikipediaで調べて、調査結果を計算することができるようになります。
image.png
まじかよ(シンプルに結果に驚いている)
image.png
長いですが、ターミナルの出力です。
Wikipediaで初代ピクミンとピクミン4を調べて発売年を抽出し、計算機に投げていることが分かります。

> Entering new AgentExecutor chain...
I don't have this information, but I can use Wikipedia to find out the release dates of the first Pikmin game and any news about Pikmin 4.
Action: Wikipedia
Action Input: "Pikmin (video game)"

> Entering new AgentExecutor chain...
I don't have this information, but I can use Wikipedia to find out the release dates of the first Pikmin game and any news about Pikmin 4.
Action: Wikipedia
Action Input: "Pikmin (video game)"
Observation: Page: Pikmin (video game)
Summary: Pikmin is a 2001 real-time strategy puzzle video game developed and published by Nintendo for the GameCube. The game was created and produced by Shigeru Miyamoto, and is the first entry in the Pikmin series. The game's story focuses on an alien pilot, Captain Olimar, who crash lands on a mysterious planet and must make use of a native species called "Pikmin" to find his ship's missing parts in order to escape within 30 days. Players take control of Olimar and in directing the different varieties of Pikmin to exploring the game's various levels, overcoming obstacles and hostile creatures, in order to find and recover the missing ship parts.The game was a critical and commercial success and spawned a series of sequels, starting with Pikmin 2, which was released in 2004. The game was ported to Wii in 2008 under the title New Play Control! Pikmin, while a high-definition remaster was released for Nintendo Switch in 2023.

Page: Pikmin
Summary: Pikmin is a real-time strategy and puzzle video game series created by Shigeru Miyamoto, and published by Nintendo. The games focus on directing a horde of plant-like creatures called Pikmin in order to collect items by destroying obstacles, avoiding hazards and fighting fauna that are hazardous to both the player character and the Pikmin.The Pikmin series features four main entries, as well as two spin-offs. The first two, Pikmin (2001) and Pikmin 2 (2004), were released for the GameCube and later ported to the Wii as New Play Control! titles in 2008 and 2009. Pikmin 2 was re-released in the Nintendo Selects series in 2012. A third installment, Pikmin 3, was released for the Wii U in 2013. The series' first handheld game, Hey! Pikmin, was released for the Nintendo 3DS in 2017. Pikmin 4 was announced to be in development by Miyamoto in September 2015, and was officially confirmed for release in 2023 during a Nintendo Direct in September 2022. Pikmin Bloom, the series' mobile spin-off, was released for iOS and Android in 2021 and Pikmin 1 and 2 were also ported to the Nintendo Switch also in the year 2023 as Pikmin 1+2.

Page: Pikmin 4
Summary: Pikmin 4 is an upcoming real-time strategy video game developed by Nintendo EPD and Eighting and published by Nintendo. It will be the fourth main installment of the Pikmin series, following Pikmin 3 (2013), and sixth installment overall. It is set for release on the Nintendo Switch on July 21, 2023.The game will mark the first in the series to feature a custom playable character, alongside other features involving a newly adjusted day and night system, allowing players to freely explore the area during the night without having to mandatorily retreat at the end of the day. In the game, the player assumes the role of a recently recruited member of the Rescue Corps, a group in need of rescuing following an unsuccessful attempt to save Captain Olimar.
Thought:I have found the release dates of the first Pikmin game and Pikmin 4. I can calculate the number of years between the two releases.
Action: Calculator
Action Input: 2023 - 2001
Observation: Answer: 22
Thought:The final answer is 22 years.
Observation: Invalid Format: Missing 'Action:' after 'Thought:'
Thought:The final answer is 22 years.
Final Answer: 22 years.

> Finished chain.

最後に作成したプロンプトを、API経由で実行してみました。
GUI左上付近の</>アイコンをクリックすると、curlコマンドが表示されます。
実行したところ、ブラウザで確認した結果と同じ結果(22 years.)が帰ってきました。

$ curl -X POST \
  http://127.0.0.1:7860/api/v1/process/c7282e1f-852c-4614-95e5-eac6a9875bef \
  -H 'Content-Type: application/json' \
  -d '{"inputs": {"input":"How many years will Pikmin 4 be released after the first Pikmin?"}}'

{"result":{"output":"22 years.","intermediate_steps":[[{"tool":"Wikipedia","tool_input":"Pikmin (video game)","log":"I don't have this information, but I can use Wikipedia to find out the release dates of the first Pikmin game and any news about Pikmin 4.\nAction: Wikipedia\nAction Input: \"Pikmin (video game)\""},"Page: Pikmin (video game)\nSummary: Pikmin is a 2001 real-time strategy puzzle video game developed and published by Nintendo for the GameCube. The game was created and produced by Shigeru Miyamoto, and is the first entry in the Pikmin series. The game's story focuses on an alien pilot, Captain Olimar, who crash lands on a mysterious planet and must make use of a native species called \"Pikmin\" to find his ship's missing parts in order to escape within 30 days. Players take control of Olimar and in directing the different varieties of Pikmin to exploring the game's various levels, overcoming obstacles and hostile creatures, in order to find and recover the missing ship parts.The game was a critical and commercial success and spawned a series of sequels, starting with Pikmin 2, which was released in 2004. The game was ported to Wii in 2008 under the title New Play Control! Pikmin, while a high-definition remaster was released for Nintendo Switch in 2023.\n\nPage: Pikmin\nSummary: Pikmin is a real-time strategy and puzzle video game series created by Shigeru Miyamoto, and published by Nintendo. The games focus on directing a horde of plant-like creatures called Pikmin in order to collect items by destroying obstacles, avoiding hazards and fighting fauna that are hazardous to both the player character and the Pikmin.The Pikmin series features four main entries, as well as two spin-offs. The first two, Pikmin (2001) and Pikmin 2 (2004), were released for the GameCube and later ported to the Wii as New Play Control! titles in 2008 and 2009. Pikmin 2 was re-released in the Nintendo Selects series in 2012. A third installment, Pikmin 3, was released for the Wii U in 2013. The series' first handheld game, Hey! Pikmin, was released for the Nintendo 3DS in 2017. Pikmin 4 was announced to be in development by Miyamoto in September 2015, and was officially confirmed for release in 2023 during a Nintendo Direct in September 2022. Pikmin Bloom, the series' mobile spin-off, was released for iOS and Android in 2021 and Pikmin 1 and 2 were also ported to the Nintendo Switch also in the year 2023 as Pikmin 1+2.\n\nPage: Pikmin 4\nSummary: Pikmin 4 is an upcoming real-time strategy video game developed by Nintendo EPD and Eighting and published by Nintendo. It will be the fourth main installment of the Pikmin series, following Pikmin 3 (2013), and sixth installment overall. It is set for release on the Nintendo Switch on July 21, 2023.The game will mark the first in the series to feature a custom playable character, alongside other features involving a newly adjusted day and night system, allowing players to freely explore the area during the night without having to mandatorily retreat at the end of the day. In the game, the player assumes the role of a recently recruited member of the Rescue Corps, a group in need of rescuing following an unsuccessful attempt to save Captain Olimar."],[{"tool":"Calculator","tool_input":"2023 - 2001","log":"I have found the release dates of the first Pikmin game and Pikmin 4. I can calculate the number of years between the two releases.\nAction: Calculator\nAction Input: 2023 - 2001"},"Answer: 22"],[{"tool":"_Exception","tool_input":"Invalid Format: Missing 'Action:' after 'Thought:'","log":"The final answer is 22 years."},"Invalid Format: Missing 'Action:' after 'Thought:'"]]}}

まとめ

LangFlowを利用することで、簡単にプロンプトエンジニアリングすることができました。
GUIによる直感的な操作で、簡単に設定することができるので、プロトタイピングやLangChainの学習には良いかと思います。
また、非エンジニアの人に作ったものを触ってもらうにも、ちょうど良いかと思いました。

スペシャルサンクス

大変感謝しております。

28
23
0

Register as a new user and use Qiita more conveniently

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?