MCPcopy Index your code
hub / github.com/dataease/SQLBot / stream_sql

Function stream_sql

backend/apps/chat/api/chat.py:370–407  ·  view source on GitHub ↗
(session: SessionDep, current_user: CurrentUser, request_question: ChatQuestion,
                     current_assistant: Optional[CurrentAssistant] = None, in_chat: bool = True, stream: bool = True,
                     finish_step: ChatFinishStep = ChatFinishStep.GENERATE_CHART, embedding: bool = False,
                     return_img: bool = True)

Source from the content-addressed store, hash-verified

368
369
370async def stream_sql(session: SessionDep, current_user: CurrentUser, request_question: ChatQuestion,
371 current_assistant: Optional[CurrentAssistant] = None, in_chat: bool = True, stream: bool = True,
372 finish_step: ChatFinishStep = ChatFinishStep.GENERATE_CHART, embedding: bool = False,
373 return_img: bool = True):
374 try:
375 llm_service = await LLMService.create(session, current_user, request_question, current_assistant,
376 embedding=embedding)
377 llm_service.init_record(session=session)
378 llm_service.run_task_async(in_chat=in_chat, stream=stream, finish_step=finish_step, return_img=return_img)
379 except Exception as e:
380 traceback.print_exc()
381
382 if stream:
383 def _err(_e: Exception):
384 yield 'data:' + orjson.dumps({'content': str(_e), 'type': 'error'}).decode() + '\n\n'
385
386 return StreamingResponse(_err(e), media_type="text/event-stream")
387 else:
388 return JSONResponse(
389 content={'message': str(e)},
390 status_code=500,
391 )
392 if stream:
393 return StreamingResponse(llm_service.await_result(), media_type="text/event-stream")
394 else:
395 res = llm_service.await_result()
396 raw_data = {}
397 for chunk in res:
398 if chunk:
399 raw_data = chunk
400 status_code = 200
401 if not raw_data.get('success'):
402 status_code = 500
403
404 return JSONResponse(
405 content=raw_data,
406 status_code=status_code,
407 )
408
409
410@router.post("/record/{chat_record_id}/{action_type}", summary=f"{PLACEHOLDER_PREFIX}analysis_or_predict")

Callers 1

question_answer_innerFunction · 0.85

Calls 6

_errFunction · 0.85
init_recordMethod · 0.80
run_task_asyncMethod · 0.80
await_resultMethod · 0.80
createMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected