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

Class NLWebHandler

AskAgent/python/core/baseHandler.py:36–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34API_VERSION = "0.1"
35
36class NLWebHandler:
37
38 def __init__(self, query_params, http_handler):
39
40 print("\n=== NLWebHandler INIT ===")
41 print(f"Query params: {query_params}")
42 print("=========================\n")
43 self.http_handler = http_handler
44 self.query_params = query_params
45
46 # Track initialization time for time-to-first-result
47 self.init_time = time.time()
48 self.first_result_sent = False
49
50 # the site that is being queried
51 self.site = get_param(query_params, "site", str, "all")
52
53 # Parse comma-separated sites
54 if self.site and isinstance(self.site, str) and "," in self.site:
55 self.site = [s.strip() for s in self.site.split(",") if s.strip()]
56
57 # the query that the user entered
58 self.query = get_param(query_params, "query", str, "")
59
60 # the previous queries that the user has entered
61 raw_prev_queries = get_param(query_params, "prev", list, [])
62 # Extract just the query text from previous queries
63 self.prev_queries = self._extract_query_texts(raw_prev_queries)
64
65 # the last answers (title and url) from previous queries
66 self.last_answers = get_param(query_params, "last_ans", list, [])
67
68 # the model that is being used
69 self.model = get_param(query_params, "model", str, "gpt-4.1-mini")
70
71 # the request may provide a fully decontextualized query, in which case
72 # we don't need to decontextualize the latest query.
73 self.decontextualized_query = get_param(query_params, "decontextualized_query", str, "")
74
75 # the url of the page on which the query was entered, in case that needs to be
76 # used to decontextualize the query. Typically left empty
77 self.context_url = get_param(query_params, "context_url", str, "")
78
79 # this allows for the request to specify an arbitrary string as background/context
80 self.context_description = get_param(query_params, "context_description", str, "")
81
82 # Conversation ID for tracking messages within a conversation
83 self.conversation_id = get_param(query_params, "conversation_id", str, "")
84
85 # OAuth user ID for conversation storage
86 self.oauth_id = get_param(query_params, "oauth_id", str, "")
87
88 # Thread ID for conversation grouping
89 self.thread_id = get_param(query_params, "thread_id", str, "")
90
91 streaming = get_param(query_params, "streaming", str, "True")
92 self.streaming = streaming not in ["False", "false", "0"]
93

Callers 8

single_turnFunction · 0.90
run_multiturn_benchmarkFunction · 0.90
run_single_testMethod · 0.90
handle_tools_callMethod · 0.90
handle_queryMethod · 0.90
handle_streaming_askFunction · 0.90
handle_regular_askFunction · 0.90

Calls

no outgoing calls

Tested by 1

run_single_testMethod · 0.72