Advertisement

Use Eden AI tools in Langchain Agent

Today, I will share the use of Eden AI tools in Langchain Agent.

Eden AI aggregates various AI providers, enabling users to unlock unlimited possibilities and fully harness the potential of artificial intelligence. Users can quickly deploy AI capabilities into production environments and easily access the full range of AI functionalities through a single API.

By adding the Edenai tool to the list of tools provided by the Agent, you can enable the Agent to perform multiple tasks, such as:

  • Speech-to-text
  • Text-to-speech
  • Text inappropriate content detection
  • Image inappropriate content detection
  • Object detection
  • OCR invoice parsing
  • OCR ID card parsing

You can see how to use the Edenai tool to create an Agent capable of performing some of the aforementioned tasks.

First, complete the preparation work.

  1. Register for an Edenai account.
  2. Obtain the API Key.

Configure the environment and initialize the 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)

At this point, provide the agent with an image and ask some questions:

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_)

At this moment, we can see

It is also possible to

result['output']

The output is as follows:

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