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

Function fetch_streaming

AskAgent/python/testing/mock_appsdk_tool.py:50–78  ·  view source on GitHub ↗
(
    session: aiohttp.ClientSession,
    url: str,
    params: dict[str, Any],
    payload: dict[str, Any] | None,
)

Source from the content-addressed store, hash-verified

48
49
50async def fetch_streaming(
51 session: aiohttp.ClientSession,
52 url: str,
53 params: dict[str, Any],
54 payload: dict[str, Any] | None,
55) -> list[dict[str, Any]]:
56 messages: list[dict[str, Any]] = []
57
58 request_kwargs: dict[str, Any] = {"params": params}
59 if payload is not None:
60 request_kwargs["json"] = payload
61
62 http_method = session.get if payload is None else session.post
63
64 async with http_method(url, **request_kwargs) as response:
65 response.raise_for_status()
66 async for raw_line in response.content:
67 line = raw_line.decode("utf-8", errors="ignore").strip()
68 if not line or line.startswith(":") or not line.startswith("data:"):
69 continue
70 data_str = line[5:].strip()
71 if data_str == "[DONE]":
72 break
73 try:
74 message = json.loads(data_str)
75 messages.append(message)
76 except json.JSONDecodeError:
77 continue
78 return messages
79
80
81async def fetch_non_streaming(

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected