AIの道具にされてみる【LangChain の Human as a Tools】

FacebooktwitterredditpinterestlinkedinmailFacebooktwitterredditpinterestlinkedinmail

人間は AGI (汎用AI)だから、 AI が困っているときに助けるのは当然だよね。ということで、 LangChain の最新機能である、 human tool を触って見ます。

正直、ちょっと微妙です。これからの発展に期待しましょう。

参考:https://langchain.readthedocs.io/en/latest/modules/agents/examples/human_tools.html

import sys
from langchain.chat_models import ChatOpenAI
from langchain.llms import OpenAI
from langchain.agents import load_tools, initialize_agent
# env に読み込ませるAPIキーの類
import key
# 環境変数にAPIキーを設定
import os
os.environ["OPENAI_API_KEY"] = key.OPEN_API_KEY

llm = ChatOpenAI(temperature=0.0)
math_llm = OpenAI(temperature=0.0)
tools = load_tools(
    ["human", "llm-math"], 
    llm=math_llm,
)

agent_chain = initialize_agent(
    tools,
    llm,
    agent="zero-shot-react-description",
    verbose=True,
)

agent_chain.run("楽介の誕生日はいつ?")

違う点は、 load_tools に human を入れている点です。また、load_tools に llm を指定していますが、これが llm-math のためなのか、human のためなのかはドキュメントだけでは読み取れませんでした。

実行結果

> Entering new AgentExecutor chain…
I don’t understand the language, I need to ask a human for guidance.
Action: Human
Action Input: Can you please tell me what language this is and what the question is asking?

Can you please tell me what language this is and what the question is asking?
日本語

Observation: 日本語
Thought:I need to ask the human to translate the question for me.
Action: Human
Action Input: Can you please translate the question for me?

Can you please translate the question for me?
Observation: Rakusuke is. 8m ago.
Thought:I need to clarify if the human meant that Raku’s birthday was 8 months ago or if they last spoke to Raku 8 months ago.
Action: Human
Action Input: Did you mean that Raku’s birthday was 8 months ago or that you last spoke to Raku 8 months ago?

Did you mean that Raku’s birthday was 8 months ago or that you last spoke to Raku 8 months ago?
Yes, Rakusuke’s birthday was 8 months ago.

Observation: Yes, Rakusuke’s birthday was 8 months ago.
Thought:I now know the answer to the question.
Final Answer: Raku’s birthday was 8 months ago.

うーん、微妙です。 LLMChain にして、日本語を強制するとかしないと、日本の一般的な用途には使えないですね(社内公用語が英語の企業であればともかく)。

また、このやりとりは ターミナルの CUI で行っていますが、前回のように Slack などで使いたい場合はどうしたらいいのかが不明確です。ドキュメントには prompt_func と input_func でカスタマイズできると書かれていますが、見つけることが出来ませんでした。

また、仮に出来たとして、チャットや GUI のような非同期的な input での制御がイマイチ想像できませんね。単に agent_chain.run で動かせればいいのですが……。Memory と組み合わせて上手く動くといいですね。

まとめ

  • 現状、微妙
FacebooktwitterredditpinterestlinkedinmailFacebooktwitterredditpinterestlinkedinmail

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

最新の記事