Mistral 入门指南
本指南展示如何设置一个最小化部署,以通过Mistral API使用TensorZero网关。
简易设置
除非您需要备用方案或自定义凭证等高级功能,否则可以使用简写形式mistral::model_name
在TensorZero中使用Mistral模型。
您可以在TensorZero变体中使用Mistral模型,只需将model
字段设置为mistral::model_name
。
例如:
[functions.my_function_name.variants.my_variant_name]type = "chat_completion"model = "mistral::ministral-8b-2410"
此外,您可以在推理请求中设置model_name
来使用特定的Mistral模型,而无需在TensorZero中配置函数和变体。
curl -X POST http://localhost:3000/inference \ -H "Content-Type: application/json" \ -d '{ "model_name": "mistral::ministral-8b-2410", "input": { "messages": [ { "role": "user", "content": "What is the capital of Japan?" } ] } }'
高级设置
在更复杂的场景中(例如回退机制、自定义凭证),您可以在TensorZero中配置自己的模型和Mistral提供商。
对于这个最小化配置,您的项目目录中只需要两个文件:
Directoryconfig/
- tensorzero.toml
- docker-compose.yml
关于生产环境部署,请参阅我们的部署指南。
配置
创建一个最小化的配置文件,定义模型和一个简单的聊天功能:
[models.ministral_8b_2410]routing = ["mistral"]
[models.ministral_8b_2410.providers.mistral]type = "mistral"model_name = "ministral-8b-2410"
[functions.my_function_name]type = "chat"
[functions.my_function_name.variants.my_variant_name]type = "chat_completion"model = "ministral_8b_2410"
Credentials
在运行网关之前,您必须设置MISTRAL_API_KEY
环境变量。
您可以通过将api_key_location
设置为env::YOUR_ENVIRONMENT_VARIABLE
或dynamic::ARGUMENT_NAME
来自定义凭证存储位置。
更多信息请参阅凭证管理指南和配置参考。
部署 (Docker Compose)
创建一个最小化的Docker Compose配置:
# This is a simplified example for learning purposes. Do not use this in production.# For production-ready deployments, see: https://www.tensorzero.com/docs/gateway/deployment
services: gateway: image: tensorzero/gateway volumes: - ./config:/app/config:ro command: --config-file /app/config/tensorzero.toml environment: - MISTRAL_API_KEY=${MISTRAL_API_KEY:?Environment variable MISTRAL_API_KEY must be set.} ports: - "3000:3000" extra_hosts: - "host.docker.internal:host-gateway"
您可以通过docker compose up
命令启动网关。
推理
向网关发起推理请求:
curl -X POST http://localhost:3000/inference \ -H "Content-Type: application/json" \ -d '{ "function_name": "my_function_name", "input": { "messages": [ { "role": "user", "content": "What is the capital of Japan?" } ] } }'