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

v3.1: Register custom 'anthropic' provider in DataDesigner

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -10,7 +10,7 @@ from models import (
10
  HealthResponse, ZaiModel
11
  )
12
 
13
- # z.ai als Anthropic-Endpunkt für LiteLLM konfigurieren
14
  ZAI_API_KEY = os.environ.get("ZAI_API_KEY", "")
15
  ZAI_BASE_URL = "https://api.z.ai/api/anthropic"
16
 
@@ -19,20 +19,35 @@ os.environ["ANTHROPIC_API_KEY"] = ZAI_API_KEY
19
  os.environ["ANTHROPIC_BASE_URL"] = ZAI_BASE_URL
20
 
21
  data_designer = None
 
22
 
23
 
24
  @asynccontextmanager
25
  async def lifespan(app: FastAPI):
26
- global data_designer
27
  from data_designer.interface import DataDesigner
28
- data_designer = DataDesigner(artifact_path=tempfile.gettempdir())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  yield
30
 
31
 
32
  app = FastAPI(
33
  title="NeMo DataDesigner API",
34
  description="Synthetic data generation with DataDesigner + z.ai",
35
- version="3.0.0",
36
  lifespan=lifespan
37
  )
38
 
@@ -73,7 +88,7 @@ def build_config(request):
73
  )
74
  )
75
 
76
- # LiteLLM erkennt "anthropic/" Prefix und nutzt ANTHROPIC_BASE_URL
77
  model_config = ModelConfig(
78
  alias="zai-model",
79
  model=f"anthropic/{model_id}",
 
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
 
 
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
+ )
39
+
40
+ data_designer = DataDesigner(
41
+ artifact_path=tempfile.gettempdir(),
42
+ model_providers=[zai_provider]
43
+ )
44
  yield
45
 
46
 
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
  )
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}",