Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def go():
io = ConsoleIO()
io.error("Building...")
async with stan.common.httpstan_server() as (host, port):
# Check to see if model is in cache.
model_name = httpstan.models.calculate_model_name(program_code)
path, payload = f"/v1/{model_name}/params", {"data": data}
async with aiohttp.request("POST", f"http://{host}:{port}{path}", json=payload) as resp:
model_in_cache = resp.status != 404
io.error_line(" Found model in cache." if model_in_cache else " This may take some time.")
# Note: during compilation `httpstan` redirects stderr to /dev/null, making `print` impossible.
path, payload = "/v1/models", {"program_code": program_code}
async with aiohttp.request("POST", f"http://{host}:{port}{path}", json=payload) as resp:
if resp.status != 201:
raise RuntimeError((await resp.json())["message"])
assert model_name == (await resp.json())["name"]
path, payload = f"/v1/{model_name}/params", {"data": data}
async with aiohttp.request("POST", f"http://{host}:{port}{path}", json=payload) as resp:
if resp.status != 200:
raise RuntimeError((await resp.json())["message"])
params_list = (await resp.json())["params"]