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