web3cyberservices commited on
Commit
6d77fe8
·
unverified ·
1 Parent(s): 6d76533

Update index.py

Browse files
Files changed (1) hide show
  1. api/index.py +7 -3
api/index.py CHANGED
@@ -44,7 +44,6 @@ github = GitHubClient(
44
  )
45
 
46
  assistant_factory = AssistantFactory(logger_agent=None, rules_path='api/coding_rules.json')
47
- plugin_execution_lock = asyncio.Lock()
48
 
49
  class ChromeExtensionPayload(BaseModel):
50
  message: str
@@ -61,6 +60,8 @@ async def lifespan(app: FastAPI):
61
  limits=httpx.Limits(max_connections=100, max_keepalive_connections=20)
62
  )
63
  app.state.plugin_needs_reload = True
 
 
64
 
65
  # Гарантия наличия структуры директорий
66
  os.makedirs("api", exist_ok=True)
@@ -186,7 +187,8 @@ async def background_evolution_worker(instruction: str, chat_id: int, target_fil
186
  f"Текущий исходный код файла:\n{source if source else '# Файл пуст или создается с нуля'}"
187
  )
188
 
189
- base_prompt = assistant_factory.create_assistant_prompt(raw_prompt)
 
190
  evolution_models = ["llama-3.3-70b-versatile", "llama-3.3-70b-specdec", "llama3-70b-8192", "mixtral-8x7b-32768"]
191
  last_runtime_error = ""
192
 
@@ -222,6 +224,7 @@ async def background_evolution_worker(instruction: str, chat_id: int, target_fil
222
  code = match.group(1).strip() if match else raw_text.strip()
223
 
224
  is_valid, error_msg = await validate_python_code(code, target_file)
 
225
  if is_valid:
226
  is_committed = await asyncio.to_thread(
227
  github.commit_file, target_file, code,
@@ -331,7 +334,8 @@ async def execute_core_intelligence(
331
  """Централизованный проход по кастомным плагинам с адаптивной инжекцией контекста веб-страниц"""
332
  resp = ""
333
 
334
- async with plugin_execution_lock:
 
335
  if getattr(app.state, "plugin_needs_reload", True):
336
  try:
337
  importlib.invalidate_caches()
 
44
  )
45
 
46
  assistant_factory = AssistantFactory(logger_agent=None, rules_path='api/coding_rules.json')
 
47
 
48
  class ChromeExtensionPayload(BaseModel):
49
  message: str
 
60
  limits=httpx.Limits(max_connections=100, max_keepalive_connections=20)
61
  )
62
  app.state.plugin_needs_reload = True
63
+ # Безопасная инициализация лока внутри запущенного event loop
64
+ app.state.plugin_execution_lock = asyncio.Lock()
65
 
66
  # Гарантия наличия структуры директорий
67
  os.makedirs("api", exist_ok=True)
 
187
  f"Текущий исходный код файла:\n{source if source else '# Файл пуст или создается с нуля'}"
188
  )
189
 
190
+ # ИСПРАВЛЕНО: Добавлен await для асинхронного метода фабрики промптов
191
+ base_prompt = await assistant_factory.create_assistant_prompt(raw_prompt)
192
  evolution_models = ["llama-3.3-70b-versatile", "llama-3.3-70b-specdec", "llama3-70b-8192", "mixtral-8x7b-32768"]
193
  last_runtime_error = ""
194
 
 
224
  code = match.group(1).strip() if match else raw_text.strip()
225
 
226
  is_valid, error_msg = await validate_python_code(code, target_file)
227
+ if_valid = is_valid # Для сохранения консистентности локального имени
228
  if is_valid:
229
  is_committed = await asyncio.to_thread(
230
  github.commit_file, target_file, code,
 
334
  """Централизованный проход по кастомным плагинам с адаптивной инжекцией контекста веб-страниц"""
335
  resp = ""
336
 
337
+ # ИСПРАВЛЕНО: Безопасное использование лока через app.state
338
+ async with app.state.plugin_execution_lock:
339
  if getattr(app.state, "plugin_needs_reload", True):
340
  try:
341
  importlib.invalidate_caches()