LangSmith playground 允许您使用自己的自定义模型。您可以部署模型服务器,该服务器通过开源库公开模型的 API,用于提供 LangChain 应用程序。在幕后,playground 将与您的模型服务器交互以生成响应。

部署自定义模型服务器

为了您的方便,我们提供了一个示例模型服务器,您可以将其用作参考。您可以在此处找到示例模型服务器。我们强烈建议使用示例模型服务器作为起点。 根据您的模型是指令式模型还是聊天式模型,您需要分别实现 custom_model.pycustom_chat_model.py

添加可配置字段

使用不同参数配置模型通常很有用。这些可能包括 temperature、model_name、max_tokens 等。 要使模型在 LangSmith playground 中可配置,您需要向模型服务器添加可配置字段。这些字段可用于从 playground 更改模型参数。 您可以通过在 config.py 文件中实现 with_configurable_fields 函数来添加可配置字段。您可以
def with_configurable_fields(self) -> Runnable:
    """公开您希望在 playground 中可配置的字段。我们将自动将这些字段公开到
    playground。如果您不想公开任何字段,可以删除此方法。"""
    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 并为聊天式模型或指令式模型选择 ChatCustomModelCustomModel 提供商。 输入 URL。playground 将自动检测可用的端点和可配置字段。然后,您可以使用所需的参数调用模型。 ChatCustomModel in Playground 如果一切设置正确,您应该在 playground 中看到模型的响应以及在 with_configurable_fields 中指定的可配置字段。 请参阅此处了解如何存储您的模型配置以供以后使用。
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.