17.9k Star!Langflow :LLM开源低代码工具、拖放式UI定制AI Agent,支持与LangChain协作!

技术

Aitrainee | 公众号:AI进修生

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

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

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

⚡️Langflow构建的对话应用

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

picture.image

  • picture.image

picture.image *

创建流程

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

picture.image

创建流程的地址

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

picture.image

参考链接:

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

知音难求,自我修炼亦艰

抓住前沿技术的机遇,与我们一起成为创新的超级个体

(把握AIGC时代的个人力量)

picture.image

点这里👇关注我,记得标星哦~

一键三连「分享」、「点赞」和「在看」

科技前沿进展日日相见 ~

0
0
0
0
关于作者
关于作者

文章

0

获赞

0

收藏

0

相关资源
从 ClickHouse 到 ByteHouse
《从ClickHouse到ByteHouse》白皮书客观分析了当前 ClickHouse 作为一款优秀的开源 OLAP 数据库所展示出来的技术性能特点与其典型的应用场景。
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论