66with fallback to character-based approximation.
77"""
88
9+ from typing import TYPE_CHECKING , Any
10+
11+ if TYPE_CHECKING :
12+ from mcp_as_a_judge .db import ConversationRecord
13+
914from mcp_as_a_judge .db .dynamic_token_limits import get_llm_input_limit
1015from mcp_as_a_judge .logging_config import get_logger
1116
1621_cached_model_name : str | None = None
1722
1823
19- async def detect_model_name (ctx = None ) -> str | None :
24+ async def detect_model_name (ctx : Any = None ) -> str | None :
2025 """
2126 Unified method to detect model name from either LLM config or MCP sampling.
2227
@@ -62,7 +67,7 @@ async def detect_model_name(ctx=None) -> str | None:
6267
6368 # Extract model name from response
6469 if hasattr (result , "model" ) and result .model :
65- return result .model
70+ return str ( result .model )
6671
6772 except ImportError :
6873 logger .debug ("MCP types not available for sampling" )
@@ -74,7 +79,7 @@ async def detect_model_name(ctx=None) -> str | None:
7479 return None
7580
7681
77- async def get_current_model_limits (ctx = None ) -> tuple [int , int ]:
82+ async def get_current_model_limits (ctx : Any = None ) -> tuple [int , int ]:
7883 """
7984 Simple wrapper: detect current model and return its token limits.
8085
@@ -100,7 +105,7 @@ async def get_current_model_limits(ctx=None) -> tuple[int, int]:
100105
101106
102107async def calculate_tokens_in_string (
103- text : str , model_name : str | None = None , ctx = None
108+ text : str , model_name : str | None = None , ctx : Any = None
104109) -> int :
105110 """
106111 Calculate accurate token count from text using LiteLLM's token_counter.
@@ -145,7 +150,7 @@ async def calculate_tokens_in_string(
145150
146151
147152async def calculate_tokens_in_record (
148- input_text : str , output_text : str , model_name : str | None = None , ctx = None
153+ input_text : str , output_text : str , model_name : str | None = None , ctx : Any = None
149154) -> int :
150155 """
151156 Calculate total token count for input and output text.
@@ -181,7 +186,7 @@ def calculate_tokens_in_records(records: list) -> int:
181186
182187
183188async def filter_records_by_token_limit (
184- records : list , current_prompt : str = "" , ctx = None
189+ records : list , current_prompt : str = "" , ctx : Any = None
185190) -> list :
186191 """
187192 Filter conversation records to stay within token and record limits.
0 commit comments