ciyidogan commited on
Commit
ed22a9d
·
verified ·
1 Parent(s): 25df053

Update config_provider.py

Browse files
Files changed (1) hide show
  1. config_provider.py +9 -41
config_provider.py CHANGED
@@ -1,11 +1,12 @@
1
  """
2
- Flare – ConfigProvider (şifreli cloud_token desteği)
3
  """
4
 
5
  from __future__ import annotations
6
  import json, os
7
  from pathlib import Path
8
  from typing import Any, Dict, List, Optional
 
9
 
10
  from pydantic import BaseModel, Field, HttpUrl, ValidationError
11
  from utils import log
@@ -50,6 +51,7 @@ class APIAuthConfig(BaseModel):
50
 
51
  class Config:
52
  extra = "allow"
 
53
 
54
 
55
  class APIConfig(BaseModel):
@@ -66,6 +68,7 @@ class APIConfig(BaseModel):
66
 
67
  class Config:
68
  extra = "allow"
 
69
 
70
 
71
  # ---------------- Intent / Param ---------
@@ -74,6 +77,7 @@ class ParameterConfig(BaseModel):
74
  caption: Optional[str] = ""
75
  type: str = Field(..., pattern=r"^(int|float|bool|str|string)$")
76
  required: bool = True
 
77
  extraction_prompt: Optional[str] = None
78
  validation_regex: Optional[str] = None
79
  invalid_prompt: Optional[str] = None
@@ -165,48 +169,12 @@ class ConfigProvider:
165
  def _load(cls) -> ServiceConfig:
166
  log(f"📥 Loading service config from {cls._CONFIG_PATH.name} …")
167
  raw = cls._CONFIG_PATH.read_text(encoding="utf-8")
168
- json_str = cls._strip_jsonc(raw)
169
  try:
170
- data = json.loads(json_str)
171
  cfg = ServiceConfig.model_validate(data)
172
  log("✅ Service config loaded.")
173
  return cfg
174
- except (json.JSONDecodeError, ValidationError) as exc:
175
  log(f"❌ Config validation error: {exc}")
176
- raise
177
-
178
- @staticmethod
179
- def _strip_jsonc(text: str) -> str:
180
- """Remove // and /* */ comments (string-aware)."""
181
- OUT, STR, ESC, SLASH, BLOCK = 0, 1, 2, 3, 4
182
- state, res, i = OUT, [], 0
183
- while i < len(text):
184
- ch = text[i]
185
- if state == OUT:
186
- if ch == '"':
187
- state, res = STR, res + [ch]
188
- elif ch == '/':
189
- nxt = text[i + 1] if i + 1 < len(text) else ""
190
- if nxt == '/':
191
- state, i = SLASH, i + 1
192
- elif nxt == '*':
193
- state, i = BLOCK, i + 1
194
- else:
195
- res.append(ch)
196
- else:
197
- res.append(ch)
198
- elif state == STR:
199
- res.append(ch)
200
- state = ESC if ch == '\\' else (OUT if ch == '"' else STR)
201
- elif state == ESC:
202
- res.append(ch)
203
- state = STR
204
- elif state == SLASH:
205
- if ch == '\n':
206
- res.append(ch)
207
- state = OUT
208
- elif state == BLOCK:
209
- if ch == '*' and i + 1 < len(text) and text[i + 1] == '/':
210
- i, state = i + 1, OUT
211
- i += 1
212
- return ''.join(res)
 
1
  """
2
+ Flare – ConfigProvider (model field düzeltmeleri)
3
  """
4
 
5
  from __future__ import annotations
6
  import json, os
7
  from pathlib import Path
8
  from typing import Any, Dict, List, Optional
9
+ import commentjson
10
 
11
  from pydantic import BaseModel, Field, HttpUrl, ValidationError
12
  from utils import log
 
51
 
52
  class Config:
53
  extra = "allow"
54
+ populate_by_name = True
55
 
56
 
57
  class APIConfig(BaseModel):
 
68
 
69
  class Config:
70
  extra = "allow"
71
+ populate_by_name = True
72
 
73
 
74
  # ---------------- Intent / Param ---------
 
77
  caption: Optional[str] = ""
78
  type: str = Field(..., pattern=r"^(int|float|bool|str|string)$")
79
  required: bool = True
80
+ variable_name: str # Add this field
81
  extraction_prompt: Optional[str] = None
82
  validation_regex: Optional[str] = None
83
  invalid_prompt: Optional[str] = None
 
169
  def _load(cls) -> ServiceConfig:
170
  log(f"📥 Loading service config from {cls._CONFIG_PATH.name} …")
171
  raw = cls._CONFIG_PATH.read_text(encoding="utf-8")
172
+ # Use commentjson instead of custom parser
173
  try:
174
+ data = commentjson.loads(raw)
175
  cfg = ServiceConfig.model_validate(data)
176
  log("✅ Service config loaded.")
177
  return cfg
178
+ except (commentjson.JSONLibraryException, ValidationError) as exc:
179
  log(f"❌ Config validation error: {exc}")
180
+ raise