LangFlow——一款可轻松实验和原型化 LangChain流水线的AI项目。
前言
在人工智能兴起的当下,AI正在重塑着很多行业。今天介绍的是一款近期登上github热门的一款可轻松实验和原型化 LangChain[1] 流水线的AI项目—LangFlow。
Flowise——通过拖放界面构建定制的LLM流程
- ⛓️ LangFlow
- 一种轻松实验和原型化 LangChain[2] 流水线的方式 ~
体验地址:https://huggingface.co/spaces/Logspace/LangFlow
📦 安装
本地安装
您可以通过pip安装LangFlow:
pip install langflow
然后运行:
python -m langflow
或者
langflow
在Google Cloud Platform上部署Langflow
请按照我们的逐步指南,在Google Cloud Platform (GCP) 上使用Google Cloud Shell部署Langflow。该指南可在Langflow在Google Cloud Platform上的部署[3]文档中找到。
或者,点击下面的 "在Cloud Shell中打开"按钮,在Google Cloud Shell中启动,并克隆Langflow存储库,然后启动一个交互式教程 ,引导您完成设置所需资源和在GCP项目上部署Langflow的过程。链接[4]
在Jina AI Cloud[5]上部署Langflow
Langflow与langchain-serve集成,提供了一键部署到Jina AI Cloud的功能。
首先使用以下命令安装langchain-serve:
pip install -U langchain-serve
然后运行:
langflow --jcloud
🎉 Langflow服务器成功部署在Jina AI Cloud上 🎉
🔗 点击链接打开服务器(请允许服务器启动大约1-2分钟):https://.wolf.jina.ai/
📖 了解更多关于管理服务器的信息:https://github.com/jina-ai/langchain-serve
完成的示例:
API使用方法
您可以直接在浏览器中使用Langflow,也可以使用Jina AI Cloud上的API端点与服务器进行交互。
用python api的使用方式:
import requestsBASE_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"] = tweaksresponse = 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!"
}
🎨 创建流程
使用LangFlow创建流程非常简单。只需将侧边栏的组件拖放到画布上,并将它们连接在一起以创建您的流水线。LangFlow提供了一系列的LangChain组件[6]可供选择,包括LLMs、提示序列化器、代理和链。
通过编辑提示参数、链接链式和代理、跟踪代理的思考过程以及导出流程,来进行探索。
完成后,您可以将流程导出为JSON文件,以与LangChain一起使用。要这样做,请单击画布右上角的“导出”按钮,然后在Python中,您可以使用以下代码加载流程:
from langflow import load_flow_from_jsonflow = load_flow_from_json("path/to/flow.json")
# 现在您可以像使用任何链式一样使用它
flow("Hey, have you heard of LangFlow?")
👋 贡献
我们欢迎来自各个层次的开发者为我们在GitHub上的开源项目做出贡献。如果您想要贡献,请查阅我们的贡献指南[7]并帮助我们使LangFlow更加易用。
加入我们的Discord[8]服务器,提问、提建议和展示您的项目!🦾
📄 许可证
LangFlow使用MIT许可证发布。有关详细信息,请参阅LICENSE文件。
参考资料
https://github.com/logspace-ai/langflow