This commit is contained in:
yumoqing 2026-01-06 11:44:00 +08:00
parent fcea81fc1d
commit 981a505f14
3 changed files with 138 additions and 2 deletions

View File

@ -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()

View File

@ -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')

View File

@ -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 %}
]
}