针对自定义 LangServe 模型服务器运行 Playground
LangSmith Playground 允许您使用自己的自定义模型。您可以部署一个模型服务器,通过 LangServe(一个用于为 LangChain 应用程序提供服务的开源库)公开模型的 API。 在幕后,Playground 将与你的模型服务器交互以生成响应。
部署自定义模型服务器
为方便起见,我们提供了一个示例模型服务器,您可以将其用作参考。您可以在此处找到示例模型服务器我们强烈建议使用示例模型服务器作为起点。
根据您的模型是 instruct 式模型还是 chat-style 模型,您需要实现custom_model.py或custom_chat_model.py分别。
添加可配置字段
使用不同的参数配置模型通常很有用。这些可能包括温度、model_name、max_tokens等。
要使模型在 LangSmith 园地中可配置,您需要将可配置字段添加到模型服务器。这些字段可用于更改 Playground 中的模型参数。
您可以通过实现with_configurable_fields函数中的config.py文件。您可以
def with_configurable_fields(self) -> Runnable:
"""Expose fields you want to be configurable in the playground. We will automatically expose these to the
playground. If you don't want to expose any fields, you can remove this method."""
return self.configurable_fields(n=ConfigurableField(
id="n",
name="Num Characters",
description="Number of characters to return from the input prompt.",
))
在 LangSmith Playground 中使用模型
部署模型服务器后,您可以在 LangSmith Playground 中使用它。进入 Playground 并选择ChatCustomModel或CustomModel聊天式模型或 Instruct 式模型的提供程序。
输入URL.Playground 将自动检测可用的终端节点和可配置字段。然后,您可以使用所需的参数调用模型。

如果一切都设置正确,您应该会在 Playground 中看到模型的响应以及with_configurable_fields.
在此处了解如何存储模型配置以供以后使用。