This commit is contained in:
zhanggangyong
2026-03-15 15:45:00 +00:00
parent 47dfd69808
commit 04efca74cc
4 changed files with 216 additions and 1 deletions
+41 -1
View File
@@ -1,5 +1,5 @@
# LiteLLM Azure Container Apps 生产配置
# 支持 Taiji AI Cloud 和 OpenRouter 模型供应商
# 支持 Taiji AI Cloud、OpenRouter、XMind 和 Databricks 模型供应商
# 自动生成 - 包含所有模型的显式配置
# =============================================================================
@@ -4696,6 +4696,45 @@ model_list:
model_info:
disable_background_health_check: true
# -------------------------------------------------------------------------
# Databricks 模型(Anthropic Messages API 兼容)
# 总计: 4 个模型
# 端点: https://adb-7405604858124224.4.azuredatabricks.net/serving-endpoints/anthropic/v1/messages
# 请求头: Authorization: Bearer {api_key}
# 注意: 使用 Anthropic Messages API 格式
# -------------------------------------------------------------------------
- model_name: databricks/claude-haiku-4-5
litellm_params:
model: anthropic/databricks-claude-haiku-4-5
api_base: https://adb-7405604858124224.4.azuredatabricks.net/serving-endpoints/anthropic/v1
api_key: os.environ/DATABRICKS_TOKEN
model_info:
disable_background_health_check: true
- model_name: databricks/claude-opus-4-5
litellm_params:
model: anthropic/databricks-claude-opus-4-5
api_base: https://adb-7405604858124224.4.azuredatabricks.net/serving-endpoints/anthropic/v1
api_key: os.environ/DATABRICKS_TOKEN
model_info:
disable_background_health_check: true
- model_name: databricks/claude-sonnet-4-5
litellm_params:
model: anthropic/databricks-claude-sonnet-4-5
api_base: https://adb-7405604858124224.4.azuredatabricks.net/serving-endpoints/anthropic/v1
api_key: os.environ/DATABRICKS_TOKEN
model_info:
disable_background_health_check: true
- model_name: databricks/claude-opus-4-1
litellm_params:
model: anthropic/databricks-claude-opus-4-1
api_base: https://adb-7405604858124224.4.azuredatabricks.net/serving-endpoints/anthropic/v1
api_key: os.environ/DATABRICKS_TOKEN
model_info:
disable_background_health_check: true
# =============================================================================
# 路由器设置
# =============================================================================
@@ -4726,6 +4765,7 @@ router_settings:
# - REDIS_SSL: 是否启用 Redis SSL(true/false)
# - TAIJI_API_KEY: Taiji AI Cloud API 密钥
# - OPENROUTER_API_KEY: OpenRouter API 密钥
# - DATABRICKS_TOKEN: Databricks Personal Access Token (PAT)
# - XMIND_API_KEY_OPENAI: XMind OpenAI 兼容 API 密钥(默认: 6b761f38b4bf4c829390d82a43f8f32f)
# - XMIND_API_KEY_ANTHROPIC: XMind Anthropic 兼容 API 密钥(默认: 9b123e68b3734856a6983fa229a1f94d)
# - XMIND_API_KEY_VERTEX_AI: XMind Vertex AI 兼容 API 密钥(默认: 854a5b589db44fb0a08c988dd2dd57f8)
Binary file not shown.
+65
View File
@@ -0,0 +1,65 @@
import json
import os
import sys
from typing import Any, Dict, List
import requests
# Required: export DATABRICKS_TOKEN with a valid Databricks PAT before running.
DATABRICKS_TOKEN = "dapied25006cd5ec824b138dfa5e82e2630c" #User1
if not DATABRICKS_TOKEN:
raise RuntimeError("Set DATABRICKS_TOKEN with a valid Databricks PAT.")
# Optional: override DATABRICKS_BASE_URL to point at your workspace host.
BASE_URL = os.environ.get(
"DATABRICKS_BASE_URL",
"https://adb-7405604858124224.4.azuredatabricks.net",
)
ENDPOINT = f"{BASE_URL.rstrip('/')}/serving-endpoints/anthropic/v1/messages"
# Adjust DEFAULT_MODEL if your workspace exposes a different deployed model name.
DEFAULT_MODEL = "databricks-claude-sonnet-4-5"
def build_payload(prompt: str, model: str, max_tokens: int) -> Dict[str, Any]:
return {
"model": model,
"max_tokens": max_tokens,
"messages": [{"role": "user", "content": prompt}],
}
def call_message_api(
prompt: str, model: str = DEFAULT_MODEL, max_tokens: int = 500
) -> Dict[str, Any]:
payload = build_payload(prompt, model, max_tokens)
headers = {
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
"Content-Type": "application/json",
}
response = requests.post(ENDPOINT, headers=headers, json=payload, timeout=30)
response.raise_for_status()
return response.json()
def extract_text(content: Any) -> str:
if isinstance(content, list):
text_blocks: List[str] = []
for block in content:
if isinstance(block, dict) and block.get("type") == "text":
text_blocks.append(str(block.get("text", "")))
if text_blocks:
return "\n".join(text_blocks)
return str(content)
def main(argv: List[str]) -> None:
prompt = " ".join(argv) if argv else "What is an LLM agent?"
result = call_message_api(prompt)
content = result.get("content")
output = extract_text(content)
print(output or json.dumps(result, indent=2))
if __name__ == "__main__":
main(sys.argv[1:])
+110
View File
@@ -0,0 +1,110 @@
[
{
"model": "databricks-claude-haiku-4-5",
"status": "success",
"response": {
"model": "claude-haiku-4-5-20251001",
"id": "msg_bdrk_019rU8d2HJVgDz7LT2MSz3z9",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! 2 + 2 = 4."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 16,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"cache_creation": {
"ephemeral_5m_input_tokens": 0,
"ephemeral_1h_input_tokens": 0
},
"output_tokens": 16
}
}
},
{
"model": "databricks-claude-opus-4-5",
"status": "success",
"response": {
"model": "claude-opus-4-5-20251101",
"id": "msg_bdrk_01B3qYeKwWRkCkvhLLErQzUr",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! 2+2 equals 4."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 16,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"cache_creation": {
"ephemeral_5m_input_tokens": 0,
"ephemeral_1h_input_tokens": 0
},
"output_tokens": 14
}
}
},
{
"model": "databricks-claude-sonnet-4-5",
"status": "success",
"response": {
"model": "claude-sonnet-4-5-20250929",
"id": "msg_bdrk_01UhJcpUBwPKqPpgz7SuerbV",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! 2 + 2 = 4"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 16,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"cache_creation": {
"ephemeral_5m_input_tokens": 0,
"ephemeral_1h_input_tokens": 0
},
"output_tokens": 15
}
}
},
{
"model": "databricks-claude-opus-4-1",
"status": "success",
"response": {
"model": "claude-opus-4-1-20250805",
"id": "msg_bdrk_01W344zBQvnZpLh1YUi2yeYF",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "2 + 2 = 4"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 16,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"output_tokens": 13
}
}
}
]