From 981a505f14603e4071ae4a0eef867183da18daee Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 6 Jan 2026 11:44:00 +0800 Subject: [PATCH] bugfix --- llmage/init.py | 4 ++ llmage/llmclient.py | 27 +++++++- wwwroot/show_llms_by_providers.ui | 109 ++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 wwwroot/show_llms_by_providers.ui diff --git a/llmage/init.py b/llmage/init.py index 64544d2..aa78689 100644 --- a/llmage/init.py +++ b/llmage/init.py @@ -7,7 +7,9 @@ from llmage.llmclient import ( b64media2url, get_llm, inference, + get_llmproviders, get_llmcatelogs, + get_llms_by_provider, get_llms_by_catelog ) from llmage.accounting import checkCustomerBalance @@ -22,6 +24,8 @@ def load_llmage(): env.get_llms_by_catelog = get_llms_by_catelog env.get_llmcatelogs = get_llmcatelogs env.checkCustomerBalance = checkCustomerBalance + env.get_llmproviders = get_llmproviders + env.get_llms_by_provider = get_llms_by_provider env.keling_token = keling_token rf = RegisterFunction() diff --git a/llmage/llmclient.py b/llmage/llmclient.py index 79b4086..4ce33b7 100644 --- a/llmage/llmclient.py +++ b/llmage/llmclient.py @@ -4,14 +4,14 @@ import asyncio from random import randint from functools import partial from traceback import format_exc -from sqlor.dbpools import DBPools +from sqlor.dbpools import DBPools, get_sor_context from appPublic.log import debug, exception from appPublic.uniqueID import getID from appPublic.dictObject import DictObject from appPublic.timeUtils import curDateString, timestampstr from appPublic.base64_to_file import base64_to_file, getFilenameFromBase64 from uapi.appapi import UAPI, sor_get_callerid, sor_get_uapi -from ahserver.serverenv import get_serverenv +from ahserver.serverenv import get_serverenv, ServerEnv from ahserver.filestorage import FileStorage from llmage.accounting import llm_accounting @@ -27,6 +27,29 @@ def erase_apikey(e): break return ss[0] + 'Bearer ' + newb +async def get_llmproviders(): + env = ServerEnv() + async with get_sor_context(env, 'llmage') as sor: + sql = """select a.providerid, a.iconid, b.orgname +from llm a, organization b +where a.providerid = b.id +group by a.providerid, a.iconid, b.orgname""" + return await sor.sqlExe(sql, {}) + return [] + +async def get_llms_by_provider(pid): + env = ServerEnv() + async with get_sor_context(env, 'llmage') as sor: + today = curDateString() + sql = """select * from llm +where providerid = ${pid}$ + and enabled_date <= ${today}$ + and expired_date > ${today}$ + """ + recs = await sor.sqlExe(sql, {'pid': pid, 'today': today}) + return recs + return [] + async def get_llmcatelogs(): db = DBPools() dbname = get_serverenv('get_module_dbname')('llmage') diff --git a/wwwroot/show_llms_by_providers.ui b/wwwroot/show_llms_by_providers.ui new file mode 100644 index 0000000..ae36ec5 --- /dev/null +++ b/wwwroot/show_llms_by_providers.ui @@ -0,0 +1,109 @@ +{% set userorgid = get_userorgid() %} +{ + "widgettype":"VScrollPanel", + "options":{ + "width":"100%", + "height":"100%" + }, + "subwidgets":[ +{% for p in get_llmproviders() %} + { + "widgettype": "VBox", + "options":{ + "width":"100%" + }, + "subwidgets":[ + { + "widgettype":"Title3", + "options":{ + "wrap":true, + "halign": "left", + "text":"{{p.orgname}}" + } + }, + { + "widgettype":"DynamicColumn", + "options":{ + "css":"filler", + "width":"100%" + }, + "subwidgets":[ +{% for llm in get_llms_by_provider(p.providerid) %} +{% set can_use = checkCustomerBalance(llm.id, userorgid) %} + { + "widgettype":"VScrollPanel", + "options":{ + "css":"card", +{% if not can_use %} + "disabled":true, +{% endif %} + "bgcolor": "#def0f0", + "cwidth":20, + "cheight":12 + }, + "subwidgets":[ + { + "widgettype":"HBox", + "options":{ + "cheight":2 + }, + "subwidgets":[ + { + "widgettype":"Svg", + "options":{ + "rate":1.5, + "url":"{{entire_url('/appbase/show_icon.dspy')}}?id={{llm.iconid}}" + } + }, + { + "widgettype":"Title6", + "options":{ + "text":"{{llm.name}}" + } + } + ] + }, + { + "widgettype":"Text", + "options":{ + "text":{{json.dumps(llm.description, ensure_ascii=False)}}, + "wrap":true, + "halign":"left" + } + } + ], + "binds":[ + { + "wid":"self", + "event":"click", + "actiontype":"urlwidget", + "target":"PopupWindow", + "popup_options":{ + "title":"{{llm.name}}", +{% if int(params_kw._is_mobile) %} + "width": "100%", + "height": "100%" +{% else %} + "width": "40%", + "height":"85%" +{% endif %} + }, + "options":{ + "params":{ + "id":"{{llm.id}}" + }, + "url":"{{entire_url('./llm_dialog.ui')}}" + } + } + ] + } +{% if not loop.last %}, {% endif %} +{% endfor %} + ] + } + ] + } +{% if not loop.last %}, {% endif %} +{% endfor %} + ] +}