为模型提供商使用环境变量
许多模型提供商支持通过环境变量设置凭据和其他配置选项。这对于自托管部署非常有用,可以避免在代码或配置文件中硬编码敏感信息。在 LangSmith 中,大多数模型交互都是通过 playground
服务完成的,该服务允许您直接在 Pod 本身配置许多环境变量。这有助于避免在 UI 中设置凭据。
要求
- 一个运行着
playground
服务的自托管 LangSmith 实例。 - 您要配置的提供商必须支持用于配置的环境变量。请查看提供商的聊天模型 文档 以获取更多信息。
- 您可能希望附加到
playground
服务的密钥/角色。- 请注意,对于 IRSA,您可能需要授予
langsmith-playground
服务帐户访问云提供商中密钥或角色的必要权限。
- 请注意,对于 IRSA,您可能需要授予
配置
利用上述参数,您可以配置 LangSmith 实例以使用环境变量作为模型提供商。您可以通过修改 LangSmith Helm Chart 安装的 langsmith_config.yaml
文件或 Docker 安装的 docker-compose.yaml
文件来完成此操作。
- Helm
- Docker
playground:
deployment:
extraEnv:
- name: OPENAI_BASE_URL
value: https://<my_proxy_url>
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: <your_secret_name>
key: api_key
serviceAccount: # Can be useful if you want to use IRSA or workload identity
annotations:
eks.amazonaws.com/role-arn: <your_role_arn>
# In your docker-compose.yaml file
langchain-playground:
environment:
.. # Other environment variables
- OPENAI_BASE_URL=https://<my_proxy_url>
- OPENAI_API_KEY=<your_key> # This will be set in the .env file