MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / EndpointStatsHandler

Class EndpointStatsHandler

AskAgent/python/testing/test_endpoint_results.py:20–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19# Capture endpoint statistics from logs
20class EndpointStatsHandler(logging.Handler):
21 def __init__(self):
22 super().__init__()
23 self.stats = defaultdict(int)
24 self.current_query = None
25
26 def emit(self, record):
27 # Look for "Got X results from endpoint_name" messages
28 if "Got" in record.getMessage() and "results from" in record.getMessage():
29 match = re.search(r'Got (\d+) results from (\w+)', record.getMessage())
30 if match:
31 count = int(match.group(1))
32 endpoint = match.group(2)
33 self.stats[endpoint] = count
34
35 def reset(self):
36 self.stats = defaultdict(int)
37
38
39async def run_query_with_stats(query: str, site: str = "all", num_results: int = 50):

Callers 1

run_query_with_statsFunction · 0.85

Calls

no outgoing calls

Tested by 1

run_query_with_statsFunction · 0.68