AI知识库

53AI知识库

学习大模型的前沿技术与行业应用场景


17.9k Star!Langflow :LLM开源低代码工具、拖放式UI定制AI Agent,支持与LangChain协作!
发布日期:2024-05-18 20:38:39 浏览次数: 2100



LangChain是一个热门的LLM开源项目,它可以更容易地将大语言模型的功能与应用程序的逻辑结合起来。然而,如果没有用户友好的界面,设计和测试LangChain流可能是具有挑战性的。

LangFlow是一个针对LangChain的GUI,它采用了反应流设计,提供了一种轻松的方式,通过拖放组件和聊天框来实验和原型化流程,将llm嵌入到您的应用程序中,无需代码。

LangFlow允许您探索不同的大语言模型、prompt参数、链配置和代理行为,并跟踪代理的思维过程。您还可以将流导出为JSON文件,以便与LangChain一起使用。

⚡️Langflow构建的对话应用

Langflow构建的对话应用的一些例子



  • • 文档:https://docs.langflow.org

  • • Discord:https://discord.com/invite/EqksyE2EX9

创建流程

Langflow 提供了一系列LangChain 组件可供选择,包括 LLM、提示序列化器、代理和链。

创建流程的地址

https://docs.langflow.org/getting-started/creating-flows

下面是视频教程以及地址:

https://www.youtube.com/watch?v=sC9SV06gsDM

API使用方法

您可以直接在浏览器中使用Langflow,也可以使用Jina AI Cloud上的API端点与服务器进行交互。

用Python API的使用方式:

import requests

BASE_API_URL = "https://langflow-e3dd8820ec.wolf.jina.ai/api/v1/predict"
FLOW_ID = "864c4f98-2e59-468b-8e13-79cd8da07468"
# You can tweak the flow by adding a tweaks dictionary
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
TWEAKS = {
"ChatOpenAI-g4jEr": {},
"ConversationChain-UidfJ": {}
}

def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict:
  """
  Run a flow with a given message and optional tweaks.

  :param message: The message to send to the flow
  :param flow_id: The ID of the flow to run
  :param tweaks: Optional tweaks to customize the flow
  :return: The JSON response from the flow
  """

  api_url = f"{BASE_API_URL}/{flow_id}"

  payload = {"message": message}

  if tweaks:
      payload["tweaks"] = tweaks

  response = requests.post(api_url, json=payload)
  return response.json()

# Setup any tweaks you want to apply to the flow
print(run_flow("Your message", flow_id=FLOW_ID, tweaks=TWEAKS))

返回结果示例:

{
  "result": "Great choice! Bangalore in the 1920s was a vibrant city with a rich cultural and political scene. Here are some suggestions for things to see and do:\n\n1. Visit the Bangalore Palace - built in 1887, this stunning palace is a perfect example of Tudor-style architecture. It was home to the Maharaja of Mysore and is now open to the public.\n\n2. Attend a performance at the Ravindra Kalakshetra - this cultural center was built in the 1920s and is still a popular venue for music and dance performances.\n\n3. Explore the neighborhoods of Basavanagudi and Malleswaram - both of these areas have retained much of their old-world charm and are great places to walk around and soak up the atmosphere.\n\n4. Check out the Bangalore Club - founded in 1868, this exclusive social club was a favorite haunt of the British expat community in the 1920s.\n\n5. Attend a meeting of the Indian National Congress - founded in 1885, the INC was a major force in the Indian independence movement and held many meetings and rallies in Bangalore in the 1920s.\n\nHope you enjoy your trip to 1920s Bangalore!"
}

下面提供官方的文档介绍、相关资源、部署教程等,进一步支撑你的行动,以提升本文的帮助力。

? 安装

您可以使用 pip 安装 Langflow:

确保您的系统上安装了 Python 3.10。
安装预发布版本
python -m pip install langflow --pre --force-reinstall

或者稳定版本
python -m pip install langflow -U

然后,运行 Langflow:

python -m langflow run

您还可以在 HuggingFace Spaces 中预览 Langflow。使用此链接克隆空间,在几分钟内创建您自己的 Langflow 工作区。

? 创建流程

使用 Langflow 创建流程很容易。只需从侧边栏拖动组件到画布上并连接它们,即可开始构建您的应用程序。

通过编辑提示参数、将组件分组到单个高级组件中以及构建您自己的自定义组件来进行探索。

完成后,您可以将流程导出为 JSON 文件。

使用以下代码加载流程:

from langflow.load import run_flow_from_json

results = run_flow_from_json("path/to/flow.json", input_value="Hello, World!")

?️ 命令行界面(CLI)

Langflow 提供了一个命令行界面(CLI),用于简化管理和配置。

用法

您可以使用以下命令运行 Langflow:

langflow run [OPTIONS]

环境变量

您可以使用环境变量配置许多 CLI 选项。这些可以在您的操作系统中导出,或者添加到 .env 文件中,并使用 --env-file 选项加载。

项目中包含了一个名为 .env.example 的示例 .env 文件。将此文件复制到名为 .env 的新文件中,并将示例值替换为您的实际设置。如果您同时在操作系统和 .env 文件中设置值,则 .env 设置将优先。

部署

在 Google Cloud Platform 上部署 Langflow

参考链接

https://github.com/langflow-ai/langflow



53AI,企业落地应用大模型首选服务商

产品:大模型应用平台+智能体定制开发+落地咨询服务

承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

与创始人交个朋友

回到顶部

 
扫码咨询