Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cached prompt costs feature with 50% discount #233

Open
wants to merge 123 commits into
base: main
Choose a base branch
from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Nov 7, 2024

Cached Prompt Costs Feature

Implements cached prompt costs with 50% discount as discussed in #215.

Changes

  • Added cached_cost_of_token_prompt field to ModelSpec
  • Updated register_model! to support cached costs (defaults to 50% of normal prompt cost)
  • Modified call_cost to handle cached prompts via new is_cached parameter
  • Added comprehensive documentation and examples

Test Plan

  1. Create a model with normal and cached costs
  2. Verify cost calculation for non-cached prompts
  3. Verify cost calculation for cached prompts (50% discount)
  4. Test default values and inheritance in model registration

Example:

# Register model with costs
register_model!(
    name = "test-model",
    cost_of_token_prompt = 0.02,     # $0.02 per token
    cost_of_token_generation = 0.03   # $0.03 per token
)

# Test normal vs cached costs
normal_cost = call_cost(100, 50, "test-model")           # Expected: 100 * 0.02 + 50 * 0.03 = 3.5
cached_cost = call_cost(100, 50, "test-model", is_cached=true)  # Expected: 100 * 0.01 + 50 * 0.03 = 2.5

Notes

  • Cached cost defaults to 50% of normal prompt cost if not specified
  • Backward compatible with existing model registrations
  • Documentation updated with examples showing both normal and cached cost calculations

Link to Devin run: https://preview.devin.ai/devin/e70735511ecd43f0a605f7766deecf86

If you have any feedback, you can leave comments in the PR and I'll address them in the app!

@svilupp svilupp force-pushed the feature/cached-prompt-costs branch from 92e8314 to e3eb4c1 Compare November 26, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants