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

fix: Update OpenAI pricing per https://openai.com/api/pricing/ #110

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/goose/utils/_cost_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from exchange.providers.base import Usage

PRICES = {
"gpt-4o": (5.00, 15.00),
"gpt-4o": (2.50, 10.00),
"gpt-4o-2024-08-06": (2.50, 10.00),
"gpt-4o-2024-05-13": (5.00, 15.00),
"gpt-4o-mini": (0.150, 0.600),
"gpt-4o-mini-2024-07-18": (0.150, 0.600),
"o1-preview": (15.00, 60.00),
Expand Down
15 changes: 12 additions & 3 deletions tests/utils/test_cost_calculator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from unittest.mock import patch
import pytest
from goose.utils._cost_calculator import _calculate_cost, get_total_cost_message
from exchange.providers.base import Usage


def test_calculate_cost():
@pytest.fixture
def mock_prices():
prices = {"gpt-4o": (5.00, 15.00), "gpt-4o-mini": (0.150, 0.600)}
with patch("goose.utils._cost_calculator.PRICES", prices) as mock_prices:
yield mock_prices


def test_calculate_cost(mock_prices):
cost = _calculate_cost("gpt-4o", Usage(input_tokens=10000, output_tokens=600, total_tokens=10600))
assert cost == 0.059


def test_get_total_cost_message():
def test_get_total_cost_message(mock_prices):
message = get_total_cost_message(
{
"gpt-4o": Usage(input_tokens=10000, output_tokens=600, total_tokens=10600),
Expand All @@ -22,7 +31,7 @@ def test_get_total_cost_message():
assert message == expected_message


def test_get_total_cost_message_with_non_available_pricing():
def test_get_total_cost_message_with_non_available_pricing(mock_prices):
message = get_total_cost_message(
{
"non_pricing_model": Usage(input_tokens=10000, output_tokens=600, total_tokens=10600),
Expand Down