From 41f89cf7f3c643d2abd6c11b853af30e9c4e667c Mon Sep 17 00:00:00 2001 From: Debanjum Date: Mon, 11 Aug 2025 19:31:33 -0700 Subject: [PATCH] Handle price, responses of models served via Groq Their tool call response may not strictly follow expected response format. Let researcher handle incorrect arguments to code tool (i.e triggers type error) --- src/khoj/processor/conversation/openai/utils.py | 3 +++ src/khoj/routers/research.py | 2 +- src/khoj/utils/constants.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/khoj/processor/conversation/openai/utils.py b/src/khoj/processor/conversation/openai/utils.py index 27b5d9cd..6f8af68c 100644 --- a/src/khoj/processor/conversation/openai/utils.py +++ b/src/khoj/processor/conversation/openai/utils.py @@ -934,6 +934,9 @@ async def astream_thought_processor( if not chunk_data.get("object") or chunk_data.get("object") != "chat.completion.chunk": logger.warning(f"Skipping invalid chunk with object field: {chunk_data.get('object', 'missing')}") continue + # Handle unsupported service tiers like "on_demand" by Groq + if chunk.service_tier and chunk.service_tier == "on_demand": + chunk_data["service_tier"] = "auto" tchunk = ChatCompletionWithThoughtsChunk.model_validate(chunk_data) diff --git a/src/khoj/routers/research.py b/src/khoj/routers/research.py index d1ebe298..fc36f9d0 100644 --- a/src/khoj/routers/research.py +++ b/src/khoj/routers/research.py @@ -433,7 +433,7 @@ async def research( this_iteration.codeContext = code_results async for result in send_status_func(f"**Ran code snippets**: {len(this_iteration.codeContext)}"): yield result - except ValueError as e: + except (ValueError, TypeError) as e: this_iteration.warning = f"Error running code: {e}" logger.warning(this_iteration.warning, exc_info=True) diff --git a/src/khoj/utils/constants.py b/src/khoj/utils/constants.py index d0b52f8b..c04b7c5b 100644 --- a/src/khoj/utils/constants.py +++ b/src/khoj/utils/constants.py @@ -71,4 +71,7 @@ model_to_cost: Dict[str, Dict[str, float]] = { "grok-3-latest": {"input": 3.0, "output": 15.0}, "grok-3-mini": {"input": 0.30, "output": 0.50}, "grok-3-mini-latest": {"input": 0.30, "output": 0.50}, + # Groq pricing + "moonshotai/kimi-k2-instruct": {"input": 1.00, "output": 3.00}, + "openai/gpt-oss-120b": {"input": 0.15, "output": 0.75}, }