Eden AI x LangChain: Harnessing LLMs, Embeddings, and AI

Eden AI x LangChain:利用 LLM、嵌入和 AI

9 分钟阅读

编辑注:这篇文章是与 Eden AI 团队合作撰写的。我们对 Eden 简化 AI 实施的方法感到非常兴奋,这样我们就可以将更多应用程序投入生产!它允许访问各种 AI 功能,涵盖文本和图像生成、OCR、语音转文本和图像分析,所有这些都只需一个 API 密钥和最少的代码即可实现。它们与 LangChain 的集成提供了对大量 LLM 和嵌入的轻松访问。

介绍 Eden AI:引领 AI 可访问性

Eden AI 作为一个新的革命性平台,旨在应对日益增长的 AI 解决方案的复杂性和多样性,使用户能够通过单个 API 密钥和几行代码访问各种 AI 工具

无论您需要 文本或图像生成OCR(光学字符识别)语音转文本转换图像分析 等等,Eden AI 都能满足您的需求。告别过去在复杂的 API 和身份验证流程中迷宫般导航的日子;Eden AI 将这一切整合到一个便捷的平台中。


免费获取您的 API 密钥

Eden AI 旨在用户友好且易于各个熟练程度的个人(无论是 AI 新手还是专家)访问,无缝满足各种业务需求,包括但不限于:数据分析、NLP 功能、计算机视觉、自动化优化和自定义模型训练。


Eden AI 和 LangChain:强大的 AI 集成合作伙伴关系

LangChain 是一个开源库,提供多种工具来构建由大型语言模型 (LLM) 驱动的应用程序,使其成为 Eden AI 的完美组合。

在 LangChain 生态系统中,Eden AI 使​​用户能够充分利用 LLM 提供商,而不会遇到任何限制。以下是如何实现:

1. 访问多个 LLM 和嵌入的统一平台

每个 LLM 都具有独特的优势,使其适用于特定的用例。但是,在市场上最好的 LLM 之间自由切换可能具有挑战性。

通过与 LangChain 集成,Eden AI 打开了通往广泛的 LLM 和嵌入模型的大门。这种集成使​​用户能够利用各种提供商的功能,甚至包括未直接集成到 LangChain 框架中的模型。
这种组合的核心优势在于其简单性。只需一个 API 密钥和一行代码,LangChain 用户就可以通过 Eden AI 访问各种 LLM。这不仅增强了 LangChain 的模型,而且还提供了极大的灵活性和适应性,以满足不同的 AI 需求。

2. 优化您的 AI 投资的强大仪表板

Eden AI 不仅限于简化对 AI 模型的访问;它还提供强大的监控和成本管理功能。

通过我们直观的仪表板,您可以监控多个 AI API 之间的 AI 使用情况,深入了解资源分配并有效地优化成本。此外,您还可以访问日志记录等功能以增强调试和 API 缓存以减少使用量并避免冗余费用。
这种简化的成本管理方法确保您在预算内充分利用您的 AI 投资,而不会有任何意外。

3. 增强您的应用程序的先进 AI 功能

Eden AI 集成到 LangChain 代表了使用 LangChain Agent Tools 的开发人员的重大突破,使他们能够利用更高级的功能来增强其应用程序。

LangChain Agents 充当 LLM 和各种工具之间的中介,促进 AI 驱动的应用程序中的各种任务,例如网络搜索、计算和代码执行。它们对于创建通用且响应迅速的应用程序尤为重要,允许开发人员根据特定的用户查询动态执行功能并与外部 API 交互。

这种集成的关键好处是,LangChain 用户现在可以轻松地将这些 高级工具 集成到他们的应用程序中,包括 显式内容检测 (用于文本和图像)、发票ID 解析对象检测文本转语音语音转文本 等功能。

因此,这种合作伙伴关系使开发人员能够使用可通过标准 API 密钥访问的最佳 AI 模型和提供商来增强其应用程序,从而在执行各种功能和与外部 API 交互方面提供前所未有的多功能性和响应能力。
如何在 LangChain 中使用 Eden AI LLM 和嵌入模型?

这里不仅有一个,而且还有两个教程,它们将使您能够重新定义您处理 AI 驱动的应用程序的方式。如果您正在寻找 Eden AI 的 LLM嵌入 的基本入门,我们建议您按照第一个教程进行操作。另一方面,如果您对高级集成感兴趣,您可以直接进行第二个教程!

教程 1:开始使用 Eden AI 访问多个 LLM 和嵌入

在我们的第一个教程中,您将学习如何利用 LangChain 和 Eden AI 的组合力量来访问多个大型语言模型 (LLM) 和嵌入。

通过掌握嵌入和 LLM 的复杂性,您将解锁创建各种令人印象深刻的功能的能力。从构建基本的 AI 助手到创建自定义聊天机器人,可能性仅受您的想象力限制。

步骤 1:安装

首先,确保您已安装 Python。然后,通过运行以下命令安装 LangChain

Pip install langchain


步骤 2:设置您的 Eden AI 帐户

要开始使用 Eden AI,您需要在 Eden AI 平台上创建一个帐户。创建帐户后,通过运行以下命令将您的 API KEY 设置为环境变量

export Eden AI_API_KEY="your_api_key_here"


步骤 3:导入 Eden AI LLM 和嵌入

Eden AI API 汇集了各种提供商,每个提供商都提供多种模型。让我们导入 Eden AI LLM 和嵌入所需的模块

from langchain.llms import EdenAI
from langchain.embeddings.edenai import EdenAiEmbeddings


步骤 4:使用 Eden AI LLM

现在,让我们实例化一个 Eden AI LLM,在本例中为 OpenAI 的 LLM。Eden AI LLM 可以配置多个提供商。

```
llm=EdenAI(provider="openai", params={"temperature" : 0.2,"max_tokens" : 250})
prompt = """
how can i create ai powered chatbots with LLMS
""
llm(prompt)



我们提出了一个问题,LLM 提供了详细的回复

"\n\nCreating an AI-powered chatbot with LLMS is relatively straightforward. First, you need to create a chatbot using the LLMS platform. This involves selecting a template, customizing the chatbot's conversation flow, and setting up the chatbot's natural language processing (NLP) capabilities. Once the chatbot is set up, you can then integrate it with your existing systems, such as customer service software, to enable it to interact with customers. Finally, you can use the LLMS platform to monitor and analyze the chatbot's performance, allowing you to make adjustments as needed."


您可以在此处查看 LLM 的其他示例以及如何使用 Eden AI 设置链:here

步骤 5:探索 Eden AI 嵌入

接下来,我们将探索 Eden AI 的嵌入

embeddings = EdenAiEmbeddings(provider="openai")

docs = ["Eden AI is integrated in LangChain", "AskYoda is Available"]
document_result = embeddings.embed_documents(docs)


这是响应,浮点数是我们在输入中包含的文本的表示形式

[[0.013804426, -0.0032499523, -0.020794097, -0.01929681, -0.024726225, 0.015966397, -0.04086054, 0.0057792477, 0.0024628271, -0.01493089, 0.0055343644, 0.01719781, 0.008808806, -0.010725892, 0.007696335, 0.034283675, -0.0023963589, -0.006744788, -0.0066433363, 0.015700523, -0.024796192, 0.024334412, -0.018233318, -0.009914279, -0.001967813,
...
0.016727816, 0.0047793766, -0.015208363, -0.019269451, ...]]

😎 您已准备就绪! 凭借如何使用嵌入和 LLM 的知识,您现在拥有创建各种令人印象深刻的功能的能力,从基本的 AI 助手到自定义聊天机器人的开发。

教程 2:使用高级 AI 功能增强您的应用程序

在我们的第二个教程中,您将学习如何轻松地将 Eden AI 功能(特别是文档解析)集成到您的应用程序中。

这种集成将使您的应用程序跃升到多功能性和响应性的新高度,确保您在不断发展的 AI 领域中保持创新的前沿。

步骤 1:准备您的环境

首先,确保您的系统上安装了 Python。然后,通过运行以下命令安装 LangChain

pip install langchain


步骤 2:获取 Eden AI API 密钥

在您开始之前,您需要从 Eden AI 平台获取 API 密钥

步骤 3:导入必要的模块

让我们导入我们的高级 AI 功能(此处为解析 ID 和发票工具)所需的 模块

from langchain.llms import EdenAI
from langchain.agents import initialize_agent, AgentType
from langchain.tools.edenai import (
EdenAiParsingIDTool,
EdenAiParsingInvoiceTool
)


import os



步骤 4:设置您的 Eden AI API 密钥

在您的系统中将您的 Eden AI API 密钥设置为环境变量。将其替换为您自己的 API 密钥。

os.environ['Eden AI_API_KEY'] = "*******************" # 替换为您自己的 API 密钥


步骤 5:初始化 LLM

Eden AI 提供一系列提供商,您可以在此处浏览:here。在本教程中,我们将选择 Eden AI LLM 来设置 LLM 提供商(此处为 OpenAI,text-davinci-003)

llm=EdenAI(provider="openai", model="text-davinci-003", params={"temperature" : 0.2,"max_tokens" : 250})


步骤 6:设置工具和代理

现在,是时候配置工具和代理了

tools = [
    EdenAiParsingIDTool(providers=["amazon","klippa"],language="en"),
    EdenAiParsingInvoiceTool(providers=["amazon","google"],language="en"),
]

agent_chain = initialize_agent(
    tools,
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
    return_intermediate_steps=True,
)


步骤 7:执行 Agent

让我们启动 Agent,使用文档解析机器人来分析身份证明或发票文档。

我们的数据包含 2 个图像 URL

  • 身份证明图像

https://www.citizencard.com/images/sample-cards/uk-id-card-for-over-18s-2023.png

现在,让我们从身份证明中提取信息并创建欢迎文本

id_result=agent_chain(""" i have this url of an id: "https://www.citizencard.com/images/sample-cards/uk-id-card-for-over-18s-2023.png"
                        extract the information in it.
                        create a text welcoming the person.
                  """)

> Entering new AgentExecutor chain...


结果

Action: Eden AI_identity_parsing
Action Input: "https://www.citizencard.com/images/sample-cards/uk-id-card-for-over-18s-2023.png" Observation:
last_name : value : ANGELA
given_names : value : GREENE
birth_place :
birth_date : value : 2000-11-09
issuance_date :
expire_date : value : 2025-07-31
document_id : value : 5843
issuing_state :
address :
age :
country :
document_type : value : DRIVER LICENSE FRONT
gender :

Thought: I now have the information from the ID and can create a welcoming text. Final Answer: Welcome Angela Greene!


然后,让我们从发票中提取信息并进行总结

invoice_result=agent_chain(""" i have this url of an invoice document: "https://app.Eden AI.run/assets/img/data_2.d6af6d85.png"
                        extract the information in it.
Summarize them.
                  """)

> Entering new AgentExecutor chain...

结果: 


Action: Eden AI_invoice_parsing
Action Input: "https://app.Eden AI.run/assets/img/data_2.d6af6d85.png"
Observation:
customer_information :
customer_name : Wiseman Water
customer_address : Wiseman Water,151 Narrows Parkway,Birmingham West Midlands B11,United Kingdom
merchant_information :
merchant_name : Gravity PDF
merchant_address : ABN: 74 212 487 581,48 Federation Way,Telegraph Point NSW 2441, Australia
merchant_website : gravitypdf.com
merchant_tax_id : 74 212 487 581
invoice_number : PDF47-WEB
taxes :
date : 2017-01-31
locale :
currency : GBP
bank_informations :
item_lines :
product_code : Laptop
description : Laptop Upgrades: 2GB Extra Ram,
Laptop Upgrades: Second 512GB Hard Drive
description : Accessories,Accessories: Laser Mouse / Keyboard Combo

Thought: I now have all the information from the invoice

Final Answer: The invoice from Wiseman Water to Gravity PDF (invoice number PDF47-WEB) contains the following items: Laptop Upgrades: 2GB Extra Ram, Laptop Upgrades: Second 512GB Hard Drive, Accessories: Laser Mouse / Keyboard Combo. The merchant is Gravity PDF, located at ABN: 74 212 487 581, 48 Federation Way, Telegraph Point NSW 2441, Australia, with website gravitypdf.com and tax ID 74 212 487 581. The customer is Wiseman Water, located at 151 Narrows Parkway, Birmingham West Midlands B11, United Kingdom. The invoice was issued on 2017-01-31 and the currency is GBP.


👏 恭喜你,一切就绪!将 Eden AI 功能集成到 LangChain 工具中,为开发者开启了无限可能。借助发票解析、ID 解析以及对象检测甚至显式内容检测等功能,开发者可以使用先进的 AI 功能来增强其应用程序。

结论

总而言之,Eden AI 简化了 AI 的集成,提供了一个用户友好的平台,简化了 API 和身份验证的迷宫。它授予访问各种 AI 功能的权限,范围涵盖文本和图像生成、OCR、语音转文本和图像分析,所有这些都只需一个 API 密钥和最少的代码即可实现。

与 LangChain 的集成进一步增强了这一点,它提供了对各种 LLM 和嵌入的轻松访问。此外,Eden AI 还提供强大的成本管理功能,确保您有效地优化您的 AI 投资。

无论您是从基础知识入手还是深入研究高级集成,您现在都拥有利用 Eden AI 和 LangChain 功能简化 AI 集成并为您的应用程序提供超强动力的工具和知识。免费获取您的 API 密钥,立即开始革新您的 AI 集成!