Skip to content
Open
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
8 changes: 7 additions & 1 deletion patchwork/common/client/llm/openai_.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class OpenAiLlmClient(LlmClient):
"o1-mini": 128_000,
"gpt-4o-mini": 128_000,
"gpt-4o": 128_000,
"o3-mini": 128_000,
}

def __init__(self, api_key: str, base_url=None, **kwargs):
Expand Down Expand Up @@ -87,7 +88,12 @@ def is_prompt_supported(

model_limit = self.__get_model_limits(model)
token_count = 0
encoding = tiktoken.encoding_for_model(model)
try:
encoding = tiktoken.encoding_for_model(model)
except KeyError:
# Fallback to gpt-4 tokenizer if model-specific tokenizer is not found
encoding = tiktoken.encoding_for_model("gpt-4")

for message in messages:
message_token_count = len(encoding.encode(message.get("content")))
token_count = token_count + message_token_count
Expand Down