Skip to content

Commit

Permalink
ref: remove cost_map from config
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik4949 committed Feb 12, 2025
1 parent 706d266 commit 3eb1922
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
17 changes: 11 additions & 6 deletions src/bespokelabs/curator/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
class _LitellmCostProcessor:
def __init__(self, config, batch=False) -> None:
self.batch = batch
self.cost_per_token_map = config.cost_per_token_map
if self.cost_per_token_map:
if config.in_mtok_cost is not None:
cost_per_input_token = config.in_mtok_cost / 1e6
if config.out_mtok_cost is not None:
cost_per_output_token = config.out_mtok_cost / 1e6
else:
cost_per_output_token = cost_per_input_token

litellm.register_model(
{
config.model: {
"max_tokens": self.cost_per_token_map.max_tokens,
"input_cost_per_token": self.cost_per_token_map.input,
"output_cost_per_token": self.cost_per_token_map.output,
"litellm_provider": self.cost_per_token_map.provider,
"max_tokens": 8192,
"input_cost_per_token": cost_per_input_token,
"output_cost_per_token": cost_per_output_token,
"litellm_provider": "openai",
}
}
)
Expand Down
15 changes: 4 additions & 11 deletions src/bespokelabs/curator/request_processor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
logger = logging.getLogger(__name__)


class _CostMap(BaseModel):
"""BaseModel for cost map."""

input: int
output: int
provider: str = "openai"
max_tokens: int = 8192


class RequestProcessorConfig(BaseModel):
"""Configuration for request processors.
Expand All @@ -28,7 +19,8 @@ class RequestProcessorConfig(BaseModel):
require_all_responses: Whether to require successful responses for all requests
generation_params: Dictionary of model-specific generation parameters
api_key: Optional API key for authentication
cost_per_token_map: Optional cost map for input and output tokens
in_mtok_cost: Optional cost per million input tokens
out_mtok_cost: Optional cost per million output tokens
"""

model: str
Expand All @@ -39,7 +31,8 @@ class RequestProcessorConfig(BaseModel):
generation_params: dict = Field(default_factory=dict)
return_completions_object: bool = False
api_key: str | None = None
cost_per_token_map: _CostMap | None = None
in_mtok_cost: int | None = None
out_mtok_cost: int | None = None

class Config:
"""BaseModel Setup class."""
Expand Down

0 comments on commit 3eb1922

Please sign in to comment.