Coerce max_tokens to int

This commit is contained in:
Your Name 2025-12-20 11:39:38 -06:00
parent 595c3ba9cf
commit c0018e2241

View file

@ -257,6 +257,14 @@ class GroqdConversationEntity(
{"type": "json_object"} if response_format == "json_object" else NOT_GIVEN {"type": "json_object"} if response_format == "json_object" else NOT_GIVEN
) )
max_tokens_value = options.get(CONF_MAX_TOKENS, DEFAULT_MAX_TOKENS)
try:
max_tokens_value = int(max_tokens_value)
except (TypeError, ValueError):
max_tokens_value = DEFAULT_MAX_TOKENS
if max_tokens_value <= 0:
max_tokens_value = DEFAULT_MAX_TOKENS
for _iteration in range(MAX_TOOL_ITERATIONS): for _iteration in range(MAX_TOOL_ITERATIONS):
try: try:
result = await client.chat.completions.create( result = await client.chat.completions.create(
@ -267,7 +275,7 @@ class GroqdConversationEntity(
parallel_tool_calls=options.get( parallel_tool_calls=options.get(
CONF_PARALLEL_TOOL_CALLS, DEFAULT_PARALLEL_TOOL_CALLS CONF_PARALLEL_TOOL_CALLS, DEFAULT_PARALLEL_TOOL_CALLS
), ),
max_tokens=options.get(CONF_MAX_TOKENS, DEFAULT_MAX_TOKENS), max_tokens=max_tokens_value,
top_p=options.get(CONF_TOP_P, DEFAULT_TOP_P), top_p=options.get(CONF_TOP_P, DEFAULT_TOP_P),
temperature=options.get(CONF_TEMPERATURE, DEFAULT_TEMPERATURE), temperature=options.get(CONF_TEMPERATURE, DEFAULT_TEMPERATURE),
frequency_penalty=options.get( frequency_penalty=options.get(