Playground 允许您使用您自己的自定义模型。您可以部署一个模型服务器,通过以下方式公开您模型的 API LangServe,这是一个用于服务 LangChain 应用程序的开源库。在后台,Playground 将与您的模型服务器交互以生成响应。
部署自定义模型服务器
为了您的方便,我们提供了一个 示例模型服务器 ,您可以将其作为参考。我们强烈建议使用示例模型服务器作为起点。
根据您的模型是指令式模型还是聊天式模型,您需要实现以下之一 custom_model.py or custom_chat_model.py respectively.
添加可配置字段
It is often useful to configure your model with different parameters. These might include temperature, model\_name, max\_tokens 等
要使您的模型在 Playground 中可配置,您需要向模型服务器添加可配置字段。这些字段可用于从 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.",
))
在 Playground 中使用模型
部署模型服务器后,您可以在 Playground 中使用它。进入 Playground 并选择 ChatCustomModel 或 CustomModel 提供程序,用于聊天式模型或指令式模型。
输入 URL。Playground 将自动检测可用的端点和可配置字段。然后,您可以使用所需的参数调用模型。
!Playground 中的 ChatCustomModel
如果一切设置正确,您应该在 Playground 中看到模型的响应以及在中指定的可配置字段 with_configurable_fields.
有关更多信息,请参阅 如何存储模型配置以供以后使用.