| |
| import litellm |
| from crewai import Crew, Process |
|
|
| |
| litellm.num_retries = 4 |
| litellm.retry_policy = { |
| "TimeoutError": 4, |
| "APIError": 3, |
| "OpenRouterException": 3, |
| "Exception": 2, |
| } |
| litellm.request_timeout = 120 |
| litellm.drop_params = True |
|
|
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| import json |
| import time |
|
|
|
|
| def safe_run_cached(inputs, cached_crew, retries: int = 4): |
| """ |
| يلف حوالين cached_crew.kickoff ويحاول يعمل JSON parsing كذا مرة |
| ويرجع (generated_content, sources) |
| """ |
| |
| for attempt in range(1, retries + 1): |
| result = cached_crew.kickoff(inputs=inputs) |
|
|
| try: |
| |
| raw = json.loads(result.raw) |
| return raw.get("generated_content", ""), raw.get("sources", []) |
| except Exception: |
| print(f"❌ JSON Error attempt {attempt}") |
| |
| print(str(result)[:300]) |
| time.sleep(0.7) |
|
|
| return "", [] |
|
|