主题
为模型提供商使用环境变量
NOTE
此功能仅在 Helm chart 0.10.27(应用版本 0.10.74)及更高版本中可用。
许多模型提供商支持通过环境变量设置凭据和其他配置选项。对于自托管部署,如果你希望避免在代码或配置文件中硬编码敏感信息,这会很有用。在 LangSmith 中,大多数模型交互通过 playground 服务完成,它允许你直接在 pod 上配置其中许多环境变量。这有助于避免在 UI 中设置凭据。
要求
- 一个正在运行
playground服务的自托管 LangSmith 实例。 - 你要配置的提供商必须支持通过环境变量进行配置。更多信息请查看提供商的 Chat Model 文档。
- 你可能想附加到
playground服务的 secrets/roles。- 注意,对于 IRSA,你可能需要向
langsmith-playgroundservice account 授予访问云提供商中 secrets 或 roles 所需的权限。
- 注意,对于 IRSA,你可能需要向
配置
有了上述参数,你就可以将 LangSmith 实例配置为对模型提供商使用环境变量。为此,请修改 LangSmith Helm Chart 安装的 langsmith_config.yaml 文件。
yaml
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>Gemini Enterprise Agent Platform 配置
你可以使用环境变量加 secrets,或 GKE 的 GCP Workload Identity,为 playground 服务配置 Gemini Enterprise Agent Platform 凭据。
使用 secrets
使用 Kubernetes secrets 配置 Gemini Enterprise Agent Platform 凭据:
yaml
playground:
deployment:
extraEnv:
# Playground-specific secret (recommended)
- name: GOOGLE_VERTEX_AI_WEB_CREDENTIALS
valueFrom:
secretKeyRef:
name: gcp-vertexai-secret
key: credentials_json # Your full service account JSON as string
# Standard fallback option
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /secrets/gcp-key.json
# Optional: Set project/location if not in model config
- name: GOOGLE_CLOUD_PROJECT
value: "your-gcp-project-id"
- name: VERTEXAI_PROJECT_ID
value: "your-gcp-project-id"
- name: VERTEXAI_LOCATION
value: "us-central1"
extraVolumeMounts:
- name: gcp-secret-volume
mountPath: /secrets
readOnly: true
extraVolumes:
- name: gcp-secret-volume
secret:
secretName: gcp-key-json # JSON file secret
defaultMode: 0444使用 workload identity
你可以将 playground service account 配置为使用 GCP Workload Identity 来担任 GCP service account 角色,而无需存储凭据。这是 GKE 集群的推荐做法。
GCP Workload Identity(GKE)
对于 GKE 集群,请使用 GCP Workload Identity:
yaml
playground:
deployment:
extraEnv:
# Optional: Set project/location if not in model config
- name: GOOGLE_CLOUD_PROJECT
value: "your-gcp-project-id"
- name: VERTEXAI_PROJECT_ID
value: "your-gcp-project-id"
- name: VERTEXAI_LOCATION
value: "us-central1"
# No credentials needed - pod assumes GCP SA role via annotation
serviceAccount:
create: true # Enable if not exists
annotations:
iam.gke.io/gcp-service-account: "vertexai-sa@your-gcp-project.iam.gserviceaccount.com"NOTE
使用 GCP Workload Identity 时,请确保 GCP service account 具有所需的 Gemini Enterprise Agent Platform 权限(例如 roles/aiplatform.user)。
AWS IRSA(EKS)
对于 EKS 集群,你可以使用 AWS IRSA(IAM Roles for Service Accounts)让 playground service account 访问 AWS 资源,而无需存储凭据。为 service account 标注你的 IAM role ARN:
yaml
playground:
serviceAccount:
create: true # Enable if not exists
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::<account>:role/LangSmith-Playground-RoleNOTE
请确保你的 AWS IAM role 具有 playground 服务所需访问的 AWS 资源对应的必要权限。