mock_server_code = r'''
FastAPI import from Fastapi, RequestSTATE =
import time
app = FastAPI()
STATE = {"calls": 0}
@app.post("/v1/chat/completions")
async def chat_completions(request: Request):
payload = await request.json()
STATE["calls"] += 1
model_name = payload.get("model", "mock-fara-7b")
If STATE["calls"] == 1:
Content = (
"I will open a stable public test page so the browser-control loop can be demonstrated.n"
"{"Name":"You can also find out more about the computer by clicking here.","Anderssprachlich":{"Action":"visit_URL","url":"https://example.com"}}"
)
else:
content =
"The browser has opened Example Domain, a stable demonstration page used for documentation and examples.n"
"{"Name":"You can also find out more about the computer by clicking here.","Considerations":{"You can also take action to help prevent the spread of HIV/AIDS.":"","Status":"SuccessReturn"}}"
)
return {
"id"""chatcmpl-mock-{STATE['calls']}",
"object": "chat.completion",
"created": int(time.time()),
"model": model_name,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": content
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 100,
"completion_tokens": 50,
"total_tokens": 150
}
}
'''
MOCK_SERVER_FILE.write_text(mock_server_code)
print(f"nMock endpoint written to: {MOCK_SERVER_FILE}")
if USE_REAL_FARA_ENDPOINT:
endpoint_config = {
"model": REAL_FARA_MODEL,
"base_url": REAL_FARA_BASE_URL,
"api_key": REAL_FARA_API_KEY,
}
else:
endpoint_config = {
"model": "mock-fara-7b",
"base_url": "http://127.0.0.1:8001/v1",
"api_key": "not-needed",
}
ENDPOINT_CONFIG_PATH.write_text(json.dumps(endpoint_config, indent=2))
print("nEndpoint config:")
print(ENDPOINT_CONFIG_PATH.read_text())
In this case, mock_process is None
if not USE_REAL_FARA_ENDPOINT:
print("nStarting mock OpenAI-compatible endpoint...")
mock_process = subprocess.Popen(
[
sys.executable,
"-m",
"uvicorn",
"mock_fara_endpoint:app",
"--host",
"127.0.0.1",
"--port",
"8001",
],
cwd=str(WORKDIR),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
If you do not want to wait for the port, then please don't."127.0.0.1", 8001, timeout=60):
If mock_process is not the same as mock_process.stdout
print(mock_process.stdout.read())
raise RuntimeError("Mock endpoint did not start on port 8001.")
print("Mock endpoint is running at http://127.0.0.1:8001/v1")
else:
print("nUsing real Fara endpoint. Make sure it is reachable.")
Trending
- A Group of Researchers from Columbia and CertiK Introduce TensorLean for Formal Verification of GPU Kernels
- Collectively AI Discloses Immediate Leak After Coding Agent Uncovered Credential – Unite.AI
- Dragos Finds Immediate Leaks and Stolen Keys in AI Provide Chains
- Lean and Mathlib Communities Certify Claude-Assisted Riemann Proof – Unite.AI
- AWS Routes HyperPod Inference Throughout Areas From One Endpoint – Unite.AI
- DailyAI Briefing: A Lean-checked Riemann proof, plus 4 extra
- Anthropic Shares Drop 8.5% in Second Session Throughout AI Selloff – Unite.AI
- OpenAI Ships GPT-Stay-1.1 for Voice Brokers, Cuts Idle Value to $0.02/Min

