Spaces:
Sleeping
Sleeping
Your Name commited on
Commit ·
43956b9
1
Parent(s): b275204
fix(inference): lazily initialize OpenAI client to support test runner mocks
Browse files- inference.py +6 -2
inference.py
CHANGED
|
@@ -33,8 +33,8 @@ if "API_BASE_URL" not in os.environ:
|
|
| 33 |
if "API_KEY" not in os.environ:
|
| 34 |
os.environ["API_KEY"] = HF_TOKEN or "none"
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
from backend.core.environment import NexusEnvironment
|
| 40 |
from backend.api.schemas.action import NexusAction, ToolCall
|
|
@@ -69,6 +69,10 @@ def _print(line: str):
|
|
| 69 |
print(line, flush=True)
|
| 70 |
|
| 71 |
async def run():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
try:
|
| 73 |
env = NexusEnvironment()
|
| 74 |
|
|
|
|
| 33 |
if "API_KEY" not in os.environ:
|
| 34 |
os.environ["API_KEY"] = HF_TOKEN or "none"
|
| 35 |
|
| 36 |
+
# The client should NOT be initialized here at the module level.
|
| 37 |
+
# If the evaluator imports this file before patching os.environ, it will permanently bind to fallbacks.
|
| 38 |
|
| 39 |
from backend.core.environment import NexusEnvironment
|
| 40 |
from backend.api.schemas.action import NexusAction, ToolCall
|
|
|
|
| 69 |
print(line, flush=True)
|
| 70 |
|
| 71 |
async def run():
|
| 72 |
+
# Initialize client dynamically at runtime to correctly capture evaluator's patched os.environ
|
| 73 |
+
from openai import OpenAI
|
| 74 |
+
client = OpenAI(base_url=os.environ["API_BASE_URL"], api_key=os.environ["API_KEY"])
|
| 75 |
+
|
| 76 |
try:
|
| 77 |
env = NexusEnvironment()
|
| 78 |
|