見出し画像

LangChainのBabyAGIクラスを試してみる 〜朝食について聞いたら、自家製梅干しの製法まで教えてくれました😍

langchain.experimental から BabyAGIクラスを手軽にインポートできるようなったとのアナウンスがあったので、さっそく試してみました。
データストアの前準備などは必要ですが、実質はインスタンス作成部分の3行ほどをコーディングするだけですぐ使えるという…。いやはや、お手軽すぎでしょ。

BabyAGIクラスの実装部分のコードはまだ読み込んでいないので、詳しいことはまだ理解していませんが、おそらくプロンプトのフォーマットの部分を好みに書き換えれば、色々応用の幅はとても広がりそうです。
それにしてもLangChainの開発スピードには目を見張りますね。次回のバージョンアップも楽しみです。

ライブラリーのインポート・環境変数の設定

!pip install langchain > /dev/null
!pip install openai > /dev/null
!pip install faiss-cpu > /dev/null
!pip install tiktoken > /dev/null
# 環境変数の準備
import os
os.environ["OPENAI_API_KEY"] = "your OPENAI_API_KEY"
from langchain.experimental import BabyAGI
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import FAISS
from langchain.docstore import InMemoryDocstore
from langchain import OpenAI
from langchain.chat_models import ChatOpenAI

from typing import Optional

ベクターストアの準備

# ベクターストアに接続する
# Define your embedding model
embeddings_model = OpenAIEmbeddings()

# Initialize the vectorstore as empty
import faiss
embedding_size = 1536
index = faiss.IndexFlatL2(embedding_size)
vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})

LLMの準備

llm = ChatOpenAI( model="gpt-3.5-turbo", temperature=0) 

BabyAGI インスタンスの生成

verbose = False
max_iterations: Optional[int] = 3
baby_agi = BabyAGI.from_llm(
    llm=llm, vectorstore=vectorstore, 
    verbose=verbose,
    max_iterations = max_iterations

これだけでいいのか?仮にもAGIの眷属であることを自称してるんやぞ。大丈夫か?

目標設定

OBJECTIVE = "健康的な日本食の朝食のレシピを出力。なおTASK LISTの項目数は常に10以下にすること"

いよいよ推論開始!

baby_agi({"objective":  OBJECTIVE})

*****TASK LIST*****
1: Make a todo list

*****NEXT TASK*****
1: Make a todo list

*****TASK RESULT*****
1. Research healthy Japanese breakfast recipes
2. Select 3-5 recipes that meet the health criteria
3. Create a grocery list for the selected recipes
4. Purchase necessary ingredients
5. Prepare breakfast according to the chosen recipe
6. Take a photo of the finished dish
7. Write a brief description of the dish and its health benefits
8. Post the photo and description on social media
9. Clean up the kitchen
10. Evaluate the recipe and make any necessary adjustments for next time.
(deepl和訳)
task result
1. 健康的な日本の朝食レシピを調査する
2. 健康基準を満たすレシピを3~5つ選択する
3. 選択したレシピのための食料品リストを作成する
4. 必要な食材を購入する
5. 選択したレシピに従って朝食を準備する
6. 出来上がった料理を写真に撮る
7. 料理とその健康効果について簡単な説明を書く
8. 写真と説明をソーシャルメディアに投稿する
9. キッチンを片付ける
10. レシピを評価し、次回のために必要な調整をする。

あれっ、日本語で考えて欲しかったんだけど…。こちらの指示が曖昧な表現だったでしょうか。ともかく、得意な英語で推論を進めてもらいましょう。

*****TASK LIST*****
1: Research traditional Japanese breakfast recipes.
2: Analyze the nutritional value of each recipe.
3: Select 3-5 recipes that meet the health criteria and have a balanced nutritional profile.
4: Create a grocery list for the selected recipes.
5: Purchase necessary ingredients from a local market or online store.
6: Prepare breakfast according to the chosen recipe.
7: Take a photo of the finished dish.
8: Write a brief description of the dish and its health benefits.
9: Post the photo and description on social media platforms such as Instagram and Facebook.
10: Evaluate the recipe and make any necessary adjustments for next time, such as reducing sodium or increasing fiber.
(deepl和訳)
1:日本の伝統的な朝食レシピを調べる
2:各レシピの栄養価を分析する
3:健康基準を満たし、栄養バランスのとれたレシピを3~5個選ぶ
4:選んだレシピの食材リストを作成する
5:地元の市場やオンラインストアで必要な食材を購入する
6:選んだレシピに従って朝食を作る
7:完成した料理の写真を撮る
8:料理と健康効果について簡単な説明を書く
9:InstagramやFacebookなどのソーシャルメディアに写真と説明を掲載する
7:完成した料理の写真を撮る
8:料理とその健康効果について簡単な説明を書く
9:写真と説明をInstagramやFacebookなどのソーシャルメディアに投稿する
10:レシピを評価し、ナトリウムを減らす、食物繊維を増やすなど、次回に必要な調整をする。

*****NEXT TASK*****
1: Research traditional Japanese breakfast recipes.

*****TASK RESULT*****
Based on my research, here are some traditional Japanese breakfast recipes:
1. Tamagoyaki (Japanese omelette)
2. Miso soup with tofu and seaweed
3. Grilled fish (such as salmon or mackerel)
4. Natto (fermented soybeans)
5. Rice (either white or brown)
6. Pickled vegetables (such as cucumber or daikon)
7. Nori (dried seaweed)
8. Green tea
9. Tsukemono (Japanese pickles)
10. Okonomiyaki (savory pancake with various toppings)

I hope this helps you in creating a healthy and delicious Japanese breakfast recipe!

(deepl和訳)
私の調査に基づき、日本の伝統的な朝食のレシピを紹介します:
1. 玉子焼き
2. 豆腐と海藻の味噌汁
3. 焼き魚(鮭や鯖など)
4. 納豆
5. ご飯(白米、玄米)
6. 漬け物(キュウリや大根など)
7. 海苔
8. 緑茶
9. 漬物
10. お好み焼き
ヘルシーでおいしい日本の朝食のレシピを作るのにお役に立てれば幸いです!

朝からお好み焼きはナゾですが、割といい感じの候補を出してきますね。

*****TASK LIST*****
2: Analyze the cultural significance of traditional Japanese breakfast recipes.
3: Identify the key ingredients and their nutritional benefits in alternative Japanese breakfast recipes.
4: Create a meal plan for a week's worth of Japanese breakfasts.
5: Incorporate seasonal ingredients into the meal plan.
6: Experiment with different cooking techniques to enhance flavor and nutrition.
7: Develop a recipe for a homemade miso paste.
8: Explore the health benefits of matcha green tea and incorporate it into a breakfast recipe.
9: Research the benefits of fermented foods and develop a recipe for homemade pickles.
10: Create a guide for selecting and preparing fresh fish for breakfast dishes.

*****NEXT TASK*****

2: Analyze the cultural significance of traditional Japanese breakfast recipes.

*****TASK RESULT*****
As an AI, I have analyzed the cultural significance of traditional Japanese breakfast recipes. Japanese breakfast is considered to be one of the healthiest and most balanced meals in the world. It typically consists of rice, miso soup, grilled fish, pickled vegetables, and tamagoyaki (rolled omelet).

The cultural significance of this meal lies in its history and the values it represents. Japanese breakfast has been a part of Japanese culture for centuries and is deeply rooted in the country's traditions and customs. It reflects the Japanese philosophy of "harmony" and "balance" in food, which emphasizes the importance of a balanced diet and the use of fresh, seasonal ingredients.

Moreover, Japanese breakfast is also a reflection of the country's geography and climate. Japan is an island nation with a long coastline, and seafood has always been a staple in the Japanese diet. The use of rice and vegetables in the meal also reflects the country's agricultural heritage.

In conclusion, traditional Japanese breakfast recipes are not only nutritious and healthy but also reflect the country's rich cultural heritage and values.

(deepl翻訳)私はAIとして、日本の伝統的な朝食レシピの文化的意義を分析しました。日本の朝食は、世界で最も健康的でバランスの取れた食事のひとつと考えられています。一般的には、ご飯、味噌汁、焼き魚、漬物、玉子焼きで構成されています。この食事が文化的に重要なのは、その歴史と価値観にあります。日本の朝食は、何世紀にもわたって日本文化の一部であり、日本の伝統と習慣に深く根ざしています。また、日本の朝食は、日本の地理や気候を反映したものでもあります。日本は海岸線の長い島国であり、昔から魚介類は日本人の食生活の主食であった。日本の伝統的な朝食は、栄養価が高く健康的であるだけでなく、日本の豊かな文化遺産や価値観を反映しているのです。

作った朝食レシピの検討結果の文化的な観点でのバックチェックまで行っています。あなたは料理研究家か!?

*****TASK LIST*****
1: Analyze the nutritional value of each recipe.
2: Select 3-5 recipes that meet the health criteria and have a balanced nutritional profile.
3: Create a grocery list for the selected recipes.
4: Purchase necessary ingredients from a local market or online store.
5: Prepare breakfast according to the chosen recipe.
6: Take a photo of the finished dish.
7: Write a brief description of the dish and its health benefits.
8: Post the photo and description on social media platforms such as Instagram and Facebook.
9: Evaluate the recipe and make any necessary adjustments for next time, such as reducing sodium or increasing fiber.
10: Research alternative traditional Japanese breakfast recipes.
11: Analyze the cultural significance of each recipe.
12: Identify the key ingredients and their nutritional benefits.
13: Create a meal plan for a week's worth of Japanese breakfasts.
14: Incorporate seasonal ingredients into the meal plan.
15: Experiment with different cooking techniques to enhance flavor and nutrition.
16: Develop a recipe for a homemade miso paste.
17: Explore the health benefits of matcha green tea and incorporate it into a breakfast recipe.
18: Research the benefits of fermented foods and develop a recipe for homemade pickles.
19: Create a guide for selecting and preparing fresh fish for breakfast dishes.

*****NEXT TASK*****
1: Analyze the nutritional value of each recipe.

*****TASK RESULT*****
Based on my analysis of the nutritional value of the traditional Japanese breakfast recipes, I have found that they are generally high in protein, fiber, and vitamins, while being low in saturated fat and added sugars. Some of the key ingredients in these recipes include rice, miso soup, grilled fish, tofu, and various vegetables such as seaweed, daikon radish, and green onions. Overall, these recipes provide a balanced and healthy start to the day.
(deepl和訳)
日本の伝統的な朝食レシピの栄養価を分析した結果、一般的にタンパク質、食物繊維、ビタミンを多く含み、飽和脂肪酸や加糖は少ないことがわかりました。これらのレシピの主な材料には、ご飯、味噌汁、焼き魚、豆腐、そして海藻、大根、ネギなどの様々な野菜が含まれます。これらのレシピは、1日の始まりにバランスのとれた健康的な食事を提供するものです。

健康基準を満足しているかのチェック。あなたは栄養士ですか!?

****TASK LIST*****
3: Develop a recipe for a homemade umeboshi (pickled plum) to add to the pickled vegetable component of the breakfast.
4: Research the health benefits of natto (fermented soybeans) and develop a recipe for incorporating it into a breakfast dish.
5: Experiment with different types of miso paste and develop a recipe for a unique miso soup variation.
6: Create a guide for selecting and preparing seasonal vegetables for Japanese breakfast dishes.
7: Research the benefits of incorporating seaweed into the breakfast meal plan and develop a recipe for a seaweed-based dish.
8: Develop a recipe for a homemade soy milk to use in breakfast dishes.
9: Analyze the nutritional benefits of different types of fish and incorporate a variety of fish dishes into the meal plan.
10: Research the benefits of incorporating sesame seeds into the breakfast meal plan and develop a recipe for a sesame-based dish.
1: Research the history and cultural significance of tamagoyaki in Japanese breakfast and develop a recipe for a unique variation of the dish.
2: Analyze the nutritional benefits of different types of rice and incorporate a variety of rice dishes into the meal plan.

*****NEXT TASK*****
3: Develop a recipe for a homemade umeboshi (pickled plum) to add to the pickled vegetable component of the breakfast.
(deepl翻訳)朝食の野菜の漬物成分に加える、自家製梅干しのレシピを開発する。

****TASK RESULT*****
Sure, I can help you with that! Here's a recipe for homemade umeboshi:

Ingredients:
- 1 pound of fresh, unripe plums
- 1 cup of sea salt
- 1/2 cup of red shiso leaves (optional)
- 1/4 cup of sugar (optional)

Instructions:
1. Rinse the plums and pat them dry.
2. Cut each plum in half and remove the pit.
3. In a large bowl, mix the sea salt and red shiso leaves (if using).
4. Add the plums to the bowl and toss them in the salt mixture until they are well coated.
5. Transfer the plums and salt mixture to a clean, airtight container.
6. Cover the container and let it sit at room temperature for 2-3 days.
7. After 2-3 days, remove the plums from the container and rinse them thoroughly with cold water.
8. Place the plums back in the container and sprinkle them with sugar (if using).
9. Cover the container and let it sit in a cool, dark place for at least 1 month.

And there you have it! Homemade umeboshi that you can add to your pickled vegetable component of your healthy Japanese breakfast. Let me know if you need any further assistance.

(deepl和訳)
もちろん、そのお手伝いはできますよ!自家製梅干しのレシピをご紹介します。材料:-新鮮な未熟な梅1ポンド-海塩1カップ-赤紫蘇1/2カップ(オプション)-砂糖1/4カップ(オプション)手順:1.梅を洗い、乾燥させる。2.梅を半分に切り、穴を開ける。3.大きなボールに、海塩と赤紫蘇(使用する場合)を混ぜる。4.梅をボールに加え、よく混ざるまで混ぜ合わせた塩で混ぜる。5。 梅と塩を混ぜたものを清潔な密閉容器に移し、6.容器に蓋をして室温で2~3日置く。7.2~3日後、容器から梅を取り出し、冷水でよく洗う。8.梅を容器に戻し、砂糖(必要に応じて)を振りかける。9.容器に蓋をして冷暗所で少なくとも1ヶ月間置く!自家製梅干しは、健康的な日本の朝食の漬物野菜に加えることができます。また何かあったら教えてくださいね。

今の時代、自家製の梅干を作る人はなかなかいないと思いますけど、こだわりを感じます。わかりました、あなたは料理研究家ですね。

*****TASK ENDING*****
{'objective': '健康的な日本食の朝食のレシピを出力。なおTASK LISTの項目数は常に10以下にすること'}

おまけ情報として自家製梅干しの作り方まで出力したところで、やり切ったと判断したのでしょうか。ここでタスクはきちんと自動終了しました。いやはや感動です。

この記事が参加している募集

#AIとやってみた

28,976件

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