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

Function generate

backend/apps/system/api/aimodel.py:27–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25@require_permissions(permission=SqlbotPermission(role=['admin']))
26async def check_llm(info: AiModelCreator, trans: Trans):
27 async def generate():
28 try:
29 additional_params = {item.key: prepare_model_arg(item.val) for item in info.config_list if
30 item.key and item.val}
31 config = LLMConfig(
32 model_type="openai" if info.protocol == 1 else "vllm",
33 model_name=info.base_model,
34 api_key=info.api_key,
35 api_base_url=info.api_domain,
36 additional_params=additional_params,
37 )
38 llm_instance = LLMFactory.create_llm(config)
39 async for chunk in llm_instance.llm.astream("1+1=?"):
40 SQLBotLogUtil.info(chunk)
41 if chunk and isinstance(chunk, str):
42 yield json.dumps({"content": chunk}) + "\n"
43 if chunk and isinstance(chunk, dict) and chunk.content:
44 yield json.dumps({"content": chunk.content}) + "\n"
45
46 except Exception as e:
47 SQLBotLogUtil.error(f"Error checking LLM: {e}")
48 error_msg = trans('i18n_llm.validate_error', msg=str(e))
49 yield json.dumps({"error": error_msg}) + "\n"
50
51 return StreamingResponse(generate(), media_type="application/x-ndjson")
52

Callers 1

check_llmFunction · 0.70

Calls 5

prepare_model_argFunction · 0.90
LLMConfigClass · 0.90
create_llmMethod · 0.80
errorMethod · 0.80
infoMethod · 0.45

Tested by

no test coverage detected