AI Gateway 快速入门
通过这个简单的演练,在几分钟内运行起您的 AI Gateway。
第一步:安装并启动 MLflow
安装 MLflow 及其所需的依赖项并启动服务器
bash
pip install 'mlflow[genai]'
mlflow server --port 5000
AI Gateway 内置于 MLflow 跟踪服务器中,可在 https://:5000 使用。
注意
AI Gateway 需要一个基于 SQL 的后端存储(SQLite、PostgreSQL、MySQL 或 MSSQL)和 FastAPI 跟踪服务器。默认情况下,mlflow server 使用 SQLite 和 FastAPI,因此本快速入门无需额外配置。
第二步:创建您的第一个 LLM 连接
导航至 https://:5000/#/settings 并点击 LLM Connections 选项卡。
- 点击 Create(创建)按钮
- 输入名称(例如,
my-openai-key) - 选择您的提供商(例如,OpenAI)
- 输入您从提供商处获得的 API 密钥
- 点击 Create(创建)

您的 API 密钥现已安全存储并加密。
第三步:创建您的第一个端点
切换到 Endpoints(端点)选项卡并点击 Create Endpoint(创建端点)。
- 输入端点名称(例如,
my-chat-endpoint) - 选择您的提供商(例如,OpenAI)
- 选择一个模型(例如,
gpt-4o) - 从下拉菜单中选择您的 LLM 连接(刚才创建的那一个)
- 点击 Create Endpoint(创建端点)
第四步:查询您的端点
使用简单的请求测试您的端点
- cURL
- Python
- OpenAI SDK
bash
curl -X POST https://:5000/gateway/my-chat-endpoint/mlflow/invocations \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Hello!"}]
}'
python
import requests
response = requests.post(
"https://:5000/gateway/my-chat-endpoint/mlflow/invocations",
json={"messages": [{"role": "user", "content": "Hello!"}]},
)
print(response.json())
python
from openai import OpenAI
client = OpenAI(
base_url="https://:5000/gateway/mlflow/v1",
api_key="", # Not needed - API key is configured server-side
)
response = client.chat.completions.create(
model="my-chat-endpoint",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
您应该会收到来自所配置模型的响应。
后续步骤
现在您已经拥有了一个可用的网关,请探索以下功能