fix: skip token counting for multimodal inputs in process_response

This commit is contained in:
Chesars 2026-03-21 23:29:45 -03:00
parent 9c4c34177e
commit bb247685da
2 changed files with 6 additions and 3 deletions

View file

@ -312,8 +312,11 @@ def process_response(
model_response.data = openai_embeddings
model_response.model = model
input_text = get_formatted_prompt(data={"input": input}, call_type="embedding")
prompt_tokens = token_counter(model=model, text=input_text)
if _is_multimodal_input(input):
prompt_tokens = 0
else:
input_text = get_formatted_prompt(data={"input": input}, call_type="embedding")
prompt_tokens = token_counter(model=model, text=input_text)
model_response.usage = Usage(
prompt_tokens=prompt_tokens, total_tokens=prompt_tokens
)

View file

@ -192,4 +192,4 @@ class TestProcessResponse:
assert len(result.data) == 2
assert result.data[0]["index"] == 0
assert result.data[1]["index"] == 1
assert result.usage.prompt_tokens >= 0
assert result.usage.prompt_tokens == 0