? ? ? ? 本文基于langgraph的預制件?Agent Chat UI和《搭建一個本地langgraph服務》中的本地服務構建一個簡單的agent系統。
? ? ? ? 說明:Agent Chat UI需要nodejs版本18及以上,而nodejs18需要的glibc版本為2.28,本人使用操作系統為ubuntu18.04,glibc版本最高支持2.27,所以對glibc作了升級。最好使用ubuntu20.04。因為期間運行環境花了很多時間,在此一并把環境搭建內容寫出來。
? ? ? ? 一、安裝node
? ? ? ? 雖然安裝方法很多,為避免版本問題,直接手動安裝。
? ? ? ? 1)從官網下載安裝18.20.8版本安裝包
? ? ? ? 地址:https://nodejs.org/download/release/latest-hydrogen/node-v18.20.8-linux-x64.tar.gz?
? ? ? ? 2)解壓到指定目錄
? ? ? ? #sudo tar cxf?node-v18.20.8-linux-x64.tar.gz? -C /usr/local/node
? ? ? ? 3)設置node和npm軟鏈
? ? ? ? #sudo ln -s /usr/local/node/bin/node /usr/local/bin/node
? ? ? ? #sudo ln -s /usr/local/node/bin/npm /usr/local/bin/npm
? ? ? ? ?二、安裝pnpm
? ? ? ? ?因github訪問問題,需要手動下載安裝文件,并修改安裝包地址。
? ? ? ? 1)下載install.sh文件
? ? ? ? #curl??
https://get.pnpm.io/install.sh -o install.sh
? ? ? ?2)修改install.sh中的archive_url
? ? ? ? #vi install.sh? ? ? ?archive_url="https://hub.gitmirror.com/https://github.com/pnpm/pnpm/releases/download/v${version}/pnpm-${platform}-${arch}"
?
? ? ? ?3)執行安裝
? ? ? ? #chmod u+x install.sh
? ? ? ? #./install.sh
? ? ? ?三、安裝前端
? ? ? ? 1)下載Agent Chat UI代碼
? ? ? ? #git? clone? ?https://github.com/langchain-ai/agent-chat-ui.git
? ? ? ? 2)修改配置文件
? ? ? ? 進入應用主目錄,并執行如下操作:
? ? ? ? #cp .env.example .env
? ? ? ? #vi .env
? ? ? ? #修改如下環境變量的值
? ? ? ? NEXT_PUBLIC_API_URL=http://{langgraph服務所在主機地址}:2024?
? ? ? ? NEXT_PUBLIC_ASSISTANT_ID=agent? ?#本地服務agent名(見本地服務config.json)
? ? ? ? 3)啟動前端服務
? ? ? ? #pnpm dev
? ? ? ? 輸出如下圖所示:
? ? ? ? 四、重啟langgraph服務
? ? ? ? 使用langgraph dev啟動后端服務時,缺省使用地址為127.0.0.1,此時從瀏覽器訪問不到,所以重啟langgraph服務,并使用0.0.0.0地址。
#langgraph? dev? --host 0.0.0.0
? ? ? ? 五、使用Agent? Chat? UI聊天