Skip to content

Commit 00c3490

Browse files
committed
Correct fraction handling
1 parent 0fd1858 commit 00c3490

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/openai_messages_token_helper/images_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def get_image_dims(image_uri: str) -> tuple[int, int]:
1717
raise ValueError("Image must be a base64 string.")
1818

1919

20-
def count_tokens_for_image(image_uri: str, detail: str = "auto", model: str = None) -> int:
20+
def count_tokens_for_image(image_uri: str, detail: str = "auto", model: str | None = None) -> int:
2121
# From https://github.com/openai/openai-cookbook/pull/881/files
2222
# Based on https://platform.openai.com/docs/guides/vision
23-
multiplier = 1
23+
multiplier = Fraction(1, 1)
2424
if model == "gpt-4o-mini":
25-
multiplier = 33 + Fraction(1, 3)
25+
multiplier = Fraction(100, 3)
2626
COST_PER_TILE = 85 * multiplier
2727
LOW_DETAIL_COST = COST_PER_TILE
2828
HIGH_DETAIL_COST_PER_TILE = COST_PER_TILE * 2

tests/verify_openai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import azure.identity
55
import openai
66
from dotenv import load_dotenv
7-
from image_messages import IMAGE_MESSAGE_COUNTS
8-
from messages import MESSAGE_COUNTS
7+
from image_messages import IMAGE_MESSAGE_COUNTS # type: ignore[import-not-found]
8+
from messages import MESSAGE_COUNTS # type: ignore[import-not-found]
99

1010
# Setup the OpenAI client to use either Azure OpenAI or OpenAI API
1111
load_dotenv()

0 commit comments

Comments
 (0)