
Langforge是一種開源工具包,旨在使創建和部署Langchain應用程序易於使用。
要安裝Langforge,只需運行以下命令:
pip install langforge-ai使用創建命令生成一個新的Langchain應用程序。
Langforge會問您幾個問題,然後設置虛擬環境,安裝所需的軟件包並配置API鍵,並為您的應用程序提供現成的基礎。
langforge create myapp提示編輯API鍵時,請輸入OpenAI API鍵。
接下來,運行Langforge Lab命令啟動Jupyter Lab。
cd myapp
langforge lab您的項目帶有用於各種用例的現成模板,以及可以讓您直接在Jupyter中與鏈條聊天的集成。
在此示例中,我們選擇“創意chatgpt”模板。

現在我們已經打開筆記本,讓我們運行代碼。
選擇Kernel > Restart Kernel and Run All Cells...
該模板將使Chatgpt的行為像一個舊的冒險遊戲。要使用它,請單擊右上角的微笑機器人臉以打開聊天窗口。

偉大的!請注意,運行第一個單元格後,將出現顯示顯示API鍵的表。如果在創建應用程序期間未設置OpenAI鍵,請單擊“編輯”按鈕並輸入鍵。
# make sure all packages are installed and environment variables are set
% setup langchain openai 
讓我們更改提示以自定義我們的冒險。您可以提出想要的任何情況。在本教程中,我們將進行太空冒險。
template = """This is a conversation between a human and a system called AdventureGPT.
AdventureGPT is designed to create immersive and engaging text-based adventure games.
AdventureGPT is capable of understanding both simple commands, such as 'look,' and more
complex sentences, allowing it to effectively interpret the player's intent.
This adventure takes place in space. The player steps into the role of Captain Bravado,
a fearless and charismatic leader of the starship 'Infinity Chaser'.
Tasked with navigating the uncharted reaches of the cosmos, Captain Bravado and their
loyal crew must overcome various challenges, solve intricate puzzles, and make critical
decisions that will shape the fate of their mission and the future of interstellar
exploration.
"""現在,重新運行牢房,發現自己正在沉浸式太空冒險中!
Langforge會自動為您的應用程序生成REST接口,從而易於與他人部署和共享。當您對應用程序感到滿意時,請使用serve命令”,然後使用筆記本的名稱開始服務您的應用程序。
langforge serve chat-creative.ipynb現在,我們可以使用Curl將HTTP請求發送到我們的應用程序:
curl -X POST -H "Content-Type: application/json" -d '{"input": "look", "memory": []}' http://localhost:2204/chat/gpt_adventure
請注意,我們在JSON:INPUT中包含兩個鍵,該鍵代表用戶的命令或消息以及內存,該鍵保留了對話歷史記錄以維持交互中的上下文和連續性。
我們歡迎社區的捐款!如果您想為Langforge做出貢獻,請隨時在我們的GitHub存儲庫上提交拉動請求或公開問題。
Langforge根據MIT許可發布。