Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions engines/remote_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def __init__(self) -> None:
self._semaphore: asyncio.Semaphore | None = None
self.api_key = os.environ.get("FIREWORKS_API_KEY", "")
raw_url = os.environ.get("FIREWORKS_BASE_URL", "https://api.fireworks.ai/inference/v1")
if not raw_url.startswith("http"):
raw_url = f"https://{raw_url}"

# Normalise: ensure the URL ends at /v1
if raw_url.endswith("/v1"):
Expand All @@ -117,8 +119,6 @@ def __init__(self) -> None:

self.base_url = base

self.model_prefix = "accounts/fireworks/models/"

if not self.api_key:
logger.warning("FIREWORKS_API_KEY is not set. Remote API calls will fail with 401. Set the key in your .env file before running Phase 5.")
logger.info("Remote LLM Engine base URL → %s", self.base_url)
Expand All @@ -145,11 +145,7 @@ async def generate(
) -> str:
# Compress prompt before sending
compressed = compress_prompt(prompt, category)
model_name = select_remote_model(category)
if model_name.startswith(self.model_prefix):
model = model_name
else:
model = f"{self.model_prefix}{model_name}"
model = select_remote_model(category)
logger.info("Remote [%s] → model=%s max_tokens=%d", category, model, max_tokens)

headers = {
Expand All @@ -158,7 +154,7 @@ async def generate(
}

# Dynamically switch between Chat Completions and raw Completions
is_chat = any(x in model_name.lower() for x in ["-it", "kimi", "minimax"])
is_chat = any(x in model.lower() for x in ["-it", "kimi", "minimax"])
endpoint = f"{self.base_url}/chat/completions" if is_chat else f"{self.base_url}/completions"

if is_chat:
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def _get_results() -> list[dict[str, str]]:
async def _process(task: Task) -> None:
assert _router is not None and _lock is not None
try:
answer = await asyncio.wait_for(_router.route(task.task_id, task.prompt), timeout=25.0)
answer = await asyncio.wait_for(_router.route(task.task_id, task.prompt), timeout=120.0)
except TimeoutError:
logger.error("Task %s timed out after 25s", task.task_id)
logger.error("Task %s timed out after 120s", task.task_id)
answer = "Error: Execution timed out."
except Exception as exc:
logger.error("Task %s failed: %s", task.task_id, exc)
Expand Down
Loading