From 668ab8f585ea1415100e3b46316ff56749a3db3d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 1 Sep 2025 18:55:16 +0800 Subject: [PATCH] bugfix --- json/llm.json | 5 +++-- llmage/llmclient.py | 22 +++++++++++++++++++--- wwwroot/llminference.dspy | 3 +++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/json/llm.json b/json/llm.json index b9e3579..4225bb7 100644 --- a/json/llm.json +++ b/json/llm.json @@ -3,12 +3,13 @@ "title":"大语言模型", "params": { "sortby":"name", + "logined_userorgid": "ownerid", "browserfields": { - "exclouded": ["id"], + "exclouded": ["id", "ownerid"], "alters": {} }, "editexclouded": [ - "id" + "id", "ownerid" ], "subtables":[ { diff --git a/llmage/llmclient.py b/llmage/llmclient.py index e4de1d7..e9cbf9b 100644 --- a/llmage/llmclient.py +++ b/llmage/llmclient.py @@ -1,3 +1,4 @@ +from random import randint from functools import partial from traceback import format_exc from sqlor.dbpools import DBPools @@ -57,13 +58,28 @@ where x.id = ${llmid}$ r.inputfields = api.input_fields return recs[0] return None +async def get_owner_userid(sor, llm): + sql = '''select a.ownerid as userid from upappkey a, upapp b +where a.upappid=b.id + and a.orgid = b.ownerid + and a.orgid = ${ownerid}$''' + recs = await sor.sqlExe(sql, {'ownerid': llm.ownerid}) + i = randint(0, len(recs)-1) + return recs[i].userid -async def inference(request, env): +async def uapi_request(request, sor, caller_orgid, uapi, llm, params): + userid = await get_owner_userid(sor, llm) + async for l in uapi.stream_linify(llm.upappid, llm.apiname, userid, params=params): + yield l + + +async def inference(request, *args, **kw): + env = request._run_ns + caller_orgid = await get_userorgid() params = env.params_kw llmid = params.llmid prompt = params.prompt stream = params.stream or True - env.update(env.params_kw) dbname = env.get_module_dbname('llmage') db = env.DBPools() async with db.sqlorContext(dbname) as sor: @@ -71,5 +87,5 @@ async def inference(request, env): env.update(llm) uapi = UAPI(request, sor=sor) userid = await env.get_user() - f = partial(uapi.stream_linify, llm.upappid, llm.apiname, userid) + f = partial(uapi_request, request, sor, caller_orgid, llm, params=params) return await env.stream_response(request, f) diff --git a/wwwroot/llminference.dspy b/wwwroot/llminference.dspy index 1b357a2..7e3d716 100644 --- a/wwwroot/llminference.dspy +++ b/wwwroot/llminference.dspy @@ -1,3 +1,6 @@ debug(f'{params_kw=}') +userid = await get_user() +if userid is None: + return UiError(title='llm inference', message='Please login first') env = DictObject(**globals()) return await inference(request, env=env)