Skip to content

Commit

Permalink
fix tests for prices
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturk committed Nov 24, 2023
1 parent d654db7 commit acc5f81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions tests/test_apicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_basic_call():
api_call.request("<html>")
assert create.call_count == 1
assert create.call_args.kwargs["model"] == "gpt-3.5-turbo"
assert api_call.total_cost == 0.0000035
assert api_call.total_cost == 0.000003


def test_model_fallback():
Expand All @@ -41,7 +41,7 @@ def _make_n_tokens(n):

def test_model_fallback_token_limit():
api_call = OpenAiCall(
models=["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"],
models=["gpt-4", "gpt-3.5-turbo"],
retry=RetryRule(1, 0), # disable wait
)
with patch_create() as create:
Expand All @@ -52,12 +52,12 @@ def test_model_fallback_token_limit():

# make sure we used the 16k model and only made one request
assert create.call_count == 1
assert create.call_args.kwargs["model"] == "gpt-3.5-turbo-16k"
assert create.call_args.kwargs["model"] == "gpt-3.5-turbo"


def test_model_fallback_token_limit_still_too_big():
api_call = OpenAiCall(
models=["gpt-3.5-turbo-16k", "gpt-4"],
models=["gpt-4", "gpt-3.5-turbo"],
retry=RetryRule(1, 0), # disable wait
)

Expand Down Expand Up @@ -109,7 +109,7 @@ def test_max_cost_exceeded():
prompt_tokens=1000, completion_tokens=1000
)
with pytest.raises(MaxCostExceeded):
for _ in range(300):
for _ in range(350):
api_call.request("<html>" * 1000)


Expand All @@ -123,7 +123,7 @@ def test_stats():
api_call.request("<html>")

assert api_call.stats() == {
"total_cost": pytest.approx(0.043),
"total_cost": pytest.approx(0.042),
"total_prompt_tokens": 20000,
"total_completion_tokens": 2000,
}
2 changes: 1 addition & 1 deletion tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_pagination():
assert resp.data[-1]["url"] == "/yak"

assert resp.api_responses == [resp1, resp2, resp3]
assert resp.total_cost == 0.0000105
assert resp.total_cost == 0.000009
assert resp.total_prompt_tokens == 3
assert resp.total_completion_tokens == 3
assert resp.url == "/page2; /page3; https://example.com/page1"
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"model,pt,ct,total",
[
("gpt-4", 1000, 1000, 0.09),
("gpt-3.5-turbo", 1000, 1000, 0.0035),
("gpt-3.5-turbo", 2000, 2000, 0.007), # near max
("gpt-3.5-turbo", 1000, 1000, 0.003),
("gpt-3.5-turbo", 2000, 2000, 0.006), # near max
("gpt-4", 4000, 4000, 0.36), # near max
],
)
Expand All @@ -17,5 +17,5 @@ def test_cost_calc(model, pt, ct, total):


def test_cost_estimate():
assert utils.cost_estimate("hello" * 1000, "gpt-3.5-turbo") == pytest.approx(0.0025)
assert utils.cost_estimate("hello" * 1000, "gpt-3.5-turbo") == pytest.approx(0.002)
assert utils.cost_estimate("hello" * 1000, "gpt-4") == pytest.approx(0.06)

0 comments on commit acc5f81

Please sign in to comment.