mindchain commited on
Commit
40d8a9a
·
verified ·
1 Parent(s): 164f456

v3.2: Fix Anthropic API endpoint for z.ai

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -10,29 +10,26 @@ from models import (
10
  HealthResponse, ZaiModel
11
  )
12
 
13
- # z.ai API Konfiguration
14
  ZAI_API_KEY = os.environ.get("ZAI_API_KEY", "")
15
- ZAI_BASE_URL = "https://api.z.ai/api/anthropic"
16
 
17
- # LiteLLM Anthropic-Konfiguration
18
  os.environ["ANTHROPIC_API_KEY"] = ZAI_API_KEY
19
- os.environ["ANTHROPIC_BASE_URL"] = ZAI_BASE_URL
20
 
21
  data_designer = None
22
- zai_provider = None
23
 
24
 
25
  @asynccontextmanager
26
  async def lifespan(app: FastAPI):
27
- global data_designer, zai_provider
28
  from data_designer.interface import DataDesigner
29
  from data_designer.config.models import ModelProvider
30
 
31
- # Custom "anthropic" Provider registrieren
32
- # provider_type="openai" ist Pflicht, aber LiteLLM erkennt "anthropic/" Prefix
33
  zai_provider = ModelProvider(
34
  name="anthropic",
35
- endpoint=ZAI_BASE_URL,
36
  provider_type="openai",
37
  api_key="ZAI_API_KEY",
38
  )
@@ -47,7 +44,7 @@ async def lifespan(app: FastAPI):
47
  app = FastAPI(
48
  title="NeMo DataDesigner API",
49
  description="Synthetic data generation with DataDesigner + z.ai",
50
- version="3.1.0",
51
  lifespan=lifespan
52
  )
53
 
@@ -88,7 +85,6 @@ def build_config(request):
88
  )
89
  )
90
 
91
- # "anthropic/" Prefix sagt LiteLLM, dass es das Anthropic-Protokoll nutzen soll
92
  model_config = ModelConfig(
93
  alias="zai-model",
94
  model=f"anthropic/{model_id}",
 
10
  HealthResponse, ZaiModel
11
  )
12
 
13
+ # z.ai API - LiteLLM expects ANTHROPIC_BASE_URL without /v1
14
  ZAI_API_KEY = os.environ.get("ZAI_API_KEY", "")
 
15
 
16
+ # LiteLLM wird {ANTHROPIC_BASE_URL}/v1/messages aufrufen
17
  os.environ["ANTHROPIC_API_KEY"] = ZAI_API_KEY
18
+ os.environ["ANTHROPIC_BASE_URL"] = "https://api.z.ai/api/anthropic"
19
 
20
  data_designer = None
 
21
 
22
 
23
  @asynccontextmanager
24
  async def lifespan(app: FastAPI):
25
+ global data_designer
26
  from data_designer.interface import DataDesigner
27
  from data_designer.config.models import ModelProvider
28
 
29
+ # Custom Provider mit z.ai Endpunkt
 
30
  zai_provider = ModelProvider(
31
  name="anthropic",
32
+ endpoint="https://api.z.ai/api/anthropic",
33
  provider_type="openai",
34
  api_key="ZAI_API_KEY",
35
  )
 
44
  app = FastAPI(
45
  title="NeMo DataDesigner API",
46
  description="Synthetic data generation with DataDesigner + z.ai",
47
+ version="3.2.0",
48
  lifespan=lifespan
49
  )
50
 
 
85
  )
86
  )
87
 
 
88
  model_config = ModelConfig(
89
  alias="zai-model",
90
  model=f"anthropic/{model_id}",