Cloud inference engine — OpenAI, Anthropic, and Google API backends.
Classes
CloudEngine
Bases: InferenceEngine
Cloud inference via OpenAI, Anthropic, and Google SDKs.
Source code in src/openjarvis/engine/cloud.py
| def __init__(self) -> None:
self._openai_client: Any = None
self._anthropic_client: Any = None
self._google_client: Any = None
self._init_clients()
|
Functions
estimate_cost
estimate_cost(model: str, prompt_tokens: int, completion_tokens: int) -> float
Estimate USD cost based on the hardcoded pricing table.
Source code in src/openjarvis/engine/cloud.py
| def estimate_cost(model: str, prompt_tokens: int, completion_tokens: int) -> float:
"""Estimate USD cost based on the hardcoded pricing table."""
# Try exact match first, then prefix match
prices = PRICING.get(model)
if prices is None:
for key, val in PRICING.items():
if model.startswith(key):
prices = val
break
if prices is None:
return 0.0
input_cost = (prompt_tokens / 1_000_000) * prices[0]
output_cost = (completion_tokens / 1_000_000) * prices[1]
return input_cost + output_cost
|