MCPcopy Index your code
hub / github.com/google/adk-python / stream_query

Function stream_query

src/google/adk/cli/fast_api.py:890–932  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

888 response_class=StreamingResponse,
889 )
890 async def stream_query(request: Request):
891 try:
892 body = await request.json()
893 except json.JSONDecodeError as exc:
894 raise HTTPException(status_code=400, detail=f"Invalid JSON: {exc}")
895 try:
896 parsed = _QueryRequest.model_validate(body)
897 except _ValidationError as exc:
898 raise HTTPException(status_code=400, detail=exc.errors())
899 if not adk_app._tmpl_attrs.get("runner"):
900 adk_app._tmpl_attrs["runner"] = await adk_web_server.get_runner_async(
901 app_name=gemini_enterprise_app_name
902 )
903 if parsed.class_method is None:
904 raise HTTPException(
905 status_code=400, detail="class_method cannot be None"
906 )
907 if parsed.class_method not in _ALLOWED_AGENT_ENGINE_CLASS_METHODS:
908 raise HTTPException(
909 status_code=400,
910 detail=f"class_method {parsed.class_method} is not allowed",
911 )
912 method = getattr(adk_app, parsed.class_method)
913 output = await _invoke_callable_or_raise(method, parsed.input or {})
914
915 if inspect.isgenerator(output):
916
917 async def _aiter_from_iter(iterator):
918 while True:
919 try:
920 chunk = await run_in_threadpool(next, iterator)
921 yield chunk
922 except StopIteration:
923 break
924
925 content_iter = _aiter_from_iter(output)
926 else:
927 content_iter = output
928
929 return StreamingResponse(
930 content=json_generator(content_iter),
931 media_type="application/json",
932 )
933
934 return app

Callers

nothing calls this directly

Calls 9

getattrFunction · 0.85
_aiter_from_iterFunction · 0.85
json_generatorFunction · 0.85
jsonMethod · 0.80
model_validateMethod · 0.80
get_runner_asyncMethod · 0.80
errorsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected