LangchainエージェントでEden AIツールを使用する

今日は Langchain Agent で Eden AI ツールを使用する方法を紹介します。

Eden AI はさまざまなAIプロバイダーを集約し、ユーザーが無限の可能性を解き放ち、人工知能の真の力を最大限に発揮できるようにします。ユーザーは単一のAPIを通じてAI機能の全範囲に簡単にアクセスでき、迅速に生産環境にAI機能を展開できます。

Agent に利用可能なツールリストに Edenai ツールを追加することで、Agent を使用して複数のタスクを実行させることができます。例えば:

  • 音声をテキストに変換
  • テキストを音声に変換
  • テキストの不適切な内容検出
  • 画像の不適切な内容検出
  • 物体検出
  • OCRによる請求書解析
  • OCRによる身分証明書解析

Edenai ツールを利用して、上記の一部タスクを実行できるAgentを作成する方法を見てみましょう。

まず準備を行います。

  1. Edenai アカウントを登録する
  2. API Key を取得する

環境を設定し、Agent を初期化する

# Import necessary libraries
# No need to install libraries in this environment, so !pip command has been removed

# Import required modules from the langchain library
from langchain.llms import EdenAI
from langchain.agents import initialize_agent, AgentType
from langchain.tools.edenai import (
EdenAiSpeechToTextTool,
EdenAiTextToSpeechTool,
EdenAiExplicitImageTool,
EdenAiObjectDetectionTool,
EdenAiParsingIDTool,
EdenAiParsingInvoiceTool,
EdenAiTextModerationTool,
)

import os

# Set environment variables for API keys
os.environ["OPENAI_API_KEY"] = "Replace_your_key"
os.environ["EDENAI_API_KEY"] = "Replace_your_key"

# Initialize the EdenAI with specific feature and provider settings
llm = EdenAI(feature="text", provider="openai", params={"temperature": 0.2, "max_tokens": 250})

# List of tools to be used, with their specific configurations
tools = [
EdenAiTextModerationTool(providers=["openai"], language="en"),
EdenAiObjectDetectionTool(providers=["google", "api4ai"]),
EdenAiTextToSpeechTool(providers=["amazon"], language="en", voice="MALE"),
EdenAiExplicitImageTool(providers=["amazon", "google"]),
EdenAiSpeechToTextTool(providers=["amazon"]),
EdenAiParsingIDTool(providers=["amazon", "klippa"], language="en"),
EdenAiParsingInvoiceTool(providers=["amazon", "google"], language="en"),
]

# Initialize the agent with the tools and the defined EdenAI instance
agent_chain = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, return_intermediate_steps=True)

この時点で、Agent に画像を与え、いくつかの質問をします:

input_ = """
i have this url of an invoice document: "https://app.edenai.run/assets/img/data_1.72e3bdcc.png"
i want to extract the information in it.
and answer these questions :
who is the customer ?
what is the company name ?
"""

result = agent_chain(input_)

この時点で、私たちは以下のように確認できます:

また、

result['output']

以下の通り出力されます:

The customer is Damita J Goldsmith and the company name is SNG Engineering Inc.