diff --git a/custom_components/groqd/conversation.py b/custom_components/groqd/conversation.py index 00a8167..f957c37 100644 --- a/custom_components/groqd/conversation.py +++ b/custom_components/groqd/conversation.py @@ -257,6 +257,14 @@ class GroqdConversationEntity( {"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): try: result = await client.chat.completions.create( @@ -267,7 +275,7 @@ class GroqdConversationEntity( parallel_tool_calls=options.get( 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), temperature=options.get(CONF_TEMPERATURE, DEFAULT_TEMPERATURE), frequency_penalty=options.get(