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

Function run

AskAgent/python/testing/mock_appsdk_tool.py:110–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108
109
110async def run() -> dict[str, Any]:
111 args = parse_args()
112
113 if args.streaming and args.non_streaming:
114 raise SystemExit("Choose either --streaming or --non-streaming, not both.")
115
116 streaming = False
117 if args.streaming:
118 streaming = True
119 if args.non_streaming:
120 streaming = False
121
122 params: dict[str, Any] = {"query": args.query}
123 if args.site:
124 params["site"] = args.site
125 if args.mode:
126 params["mode"] = args.mode
127 if args.prev:
128 params["prev"] = args.prev
129 params["streaming"] = "true" if streaming else "false"
130
131 payload: dict[str, Any] | None = None
132 if args.method == "post":
133 payload = {
134 key: value
135 for key, value in params.items()
136 if key not in {"streaming"}
137 }
138 payload["streaming"] = streaming
139 params = {}
140
141 async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=60)) as session:
142 url = args.base_url.rstrip("/") + "/ask"
143 if streaming:
144 messages = await fetch_streaming(session, url, params, payload)
145 response_payload: Any | None = None
146 else:
147 response_payload = await fetch_non_streaming(session, url, params, payload)
148 messages = extract_messages(response_payload)
149
150 adapted = convert_messages_to_appsdk_response(
151 messages,
152 query=args.query,
153 partial_warning=None,
154 legacy_payload=response_payload if isinstance(response_payload, dict) else None,
155 )
156
157 if response_payload and isinstance(response_payload, dict):
158 adapted["structuredContent"]["legacyResponse"] = response_payload
159
160 if args.output:
161 Path(args.output).write_text(json.dumps(adapted, indent=2), encoding="utf-8")
162
163 print(json.dumps(adapted, indent=2))
164 return adapted
165
166
167def main() -> None:

Callers 1

mainFunction · 0.85

Calls 5

parse_argsFunction · 0.85
fetch_streamingFunction · 0.85
fetch_non_streamingFunction · 0.85
extract_messagesFunction · 0.85

Tested by

no test coverage detected