Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- inference.py +40 -9
inference.py
CHANGED
|
@@ -743,19 +743,50 @@ async def _run_single_task(task_id: int, llm_client: OpenAI) -> None:
|
|
| 743 |
|
| 744 |
|
| 745 |
async def main() -> None:
|
| 746 |
-
|
| 747 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 748 |
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 754 |
|
| 755 |
_stderr("Planned tasks: " + ", ".join(f"task_{task_id}" for task_id in task_ids))
|
| 756 |
for task_id in task_ids:
|
| 757 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
|
| 759 |
|
| 760 |
if __name__ == "__main__":
|
| 761 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 743 |
|
| 744 |
|
| 745 |
async def main() -> None:
|
| 746 |
+
try:
|
| 747 |
+
_validate_required_env_vars()
|
| 748 |
+
except Exception as exc:
|
| 749 |
+
_stderr(
|
| 750 |
+
f"startup_error: {exc.__class__.__name__}: "
|
| 751 |
+
f"{_as_single_line(str(exc))}"
|
| 752 |
+
)
|
| 753 |
+
return
|
| 754 |
|
| 755 |
+
try:
|
| 756 |
+
task_ids = _parse_task_ids(os.getenv("RAG_DEBUG_TASK_IDS", "all"))
|
| 757 |
+
except Exception as exc:
|
| 758 |
+
_stderr(
|
| 759 |
+
f"startup_warning: invalid RAG_DEBUG_TASK_IDS; defaulting to all ({exc.__class__.__name__}: "
|
| 760 |
+
f"{_as_single_line(str(exc))})"
|
| 761 |
+
)
|
| 762 |
+
task_ids = DEFAULT_TASK_IDS
|
| 763 |
+
|
| 764 |
+
try:
|
| 765 |
+
# Required by user request: initialize OpenAI client directly from injected env vars.
|
| 766 |
+
llm_client = OpenAI(
|
| 767 |
+
base_url=os.environ["API_BASE_URL"],
|
| 768 |
+
api_key=os.environ["API_KEY"],
|
| 769 |
+
)
|
| 770 |
+
except Exception as exc:
|
| 771 |
+
_stderr(
|
| 772 |
+
f"startup_error: failed to initialize OpenAI client ({exc.__class__.__name__}: "
|
| 773 |
+
f"{_as_single_line(str(exc))})"
|
| 774 |
+
)
|
| 775 |
+
return
|
| 776 |
|
| 777 |
_stderr("Planned tasks: " + ", ".join(f"task_{task_id}" for task_id in task_ids))
|
| 778 |
for task_id in task_ids:
|
| 779 |
+
try:
|
| 780 |
+
await _run_single_task(task_id=task_id, llm_client=llm_client)
|
| 781 |
+
except Exception as exc:
|
| 782 |
+
_stderr(
|
| 783 |
+
f"task_runtime_error: task_{task_id} failed with {exc.__class__.__name__}: "
|
| 784 |
+
f"{_as_single_line(str(exc))}"
|
| 785 |
+
)
|
| 786 |
|
| 787 |
|
| 788 |
if __name__ == "__main__":
|
| 789 |
+
try:
|
| 790 |
+
asyncio.run(main())
|
| 791 |
+
except Exception as exc:
|
| 792 |
+
_stderr(f"fatal_error: {exc.__class__.__name__}: {_as_single_line(str(exc))}")
|