cached = self.cache.get(payload)
if cached is not None:
resp = self._parse(cached, payload, cached=True)
self.usage.add(Usage(calls=1, cached_calls=1))
return resp
if offline:
raise MissingCachedResponse(
"offline mode: this request is not in the cache. Re-run without --offline "
"(and with TYPESAFE_API_KEY set) to record it.",
status=None,
)
raw, latency = self._post(payload)
if use_cache and self.cache is not None:
self.cache.put(payload, raw)
resp = self._parse(raw, payload, cached=False)
resp.latency_s = latency
self.usage.add(Usage(calls=1, input_tokens=resp.usage.input_tokens, output_tokens=resp.usage.output_tokens))
return resp
root@213-238-170-219:/home/hermes#