
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许可发布。