在自定义 LangServe 模型服务器上运行沙盒
LangSmith playground 允许您使用自己的自定义模型。您可以部署一个模型服务器,通过 LangServe(一个用于部署 LangChain 应用的开源库)暴露您的模型的 API。 在后台,playground 将与您的模型服务器交互以生成响应。
部署自定义模型服务器
为了方便您使用,我们提供了一个示例模型服务器,您可以将其作为参考。您可以在此处找到该示例模型服务器 here。 我们强烈建议您以该示例模型服务器为起点开始使用。
根据您的模型是指令风格(instruct-style)还是对话风格(chat-style)模型,您需要分别实现 custom_model.py 或 custom_chat_model.py。
添加可配置字段
通常很有用的配置您的模型与不同的参数。这些可能包括温度,model_name, max_tokens等。
要在 LangSmith playground 中使您的模型可配置,您需要向模型服务器添加可配置字段。这些字段可用于从 playground 更改模型参数。
您可以通过在config.py文件中实现with_configurable_fields函数来添加可配置的字段。
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 提供者,以使用聊天风格模型或指令风格模型。
输入 URL。Playground 将自动检测可用的端点和可配置的字段。然后,您可以使用所需的参数调用模型。

如果一切设置正确,您应该能在沙盒中看到模型的响应,以及 with_configurable_fields 中指定的可配置字段。
查看如何保存您的模型配置以便稍后使用 此处。