This commit is contained in:
yumoqing 2026-05-22 11:33:02 +08:00
parent 7e6054c230
commit 66ed700261
3 changed files with 32 additions and 58 deletions

View File

@ -19,7 +19,6 @@ from .utils import (
get_tpac_balance, get_tpac_balance,
get_user_tpac_apikey, get_user_tpac_apikey,
get_llm, get_llm,
BufferedLLMs
) )
from .llmclient import ( from .llmclient import (

View File

@ -278,24 +278,8 @@ async def get_llms_by_catelog(catelogid=None, orderby='providerid'):
return d return d
return [] return []
class BufferedLLMs: async def get_llm(llmid, catelogid=None):
llms = {}
@classmethod
def clear_cache(cls, data=None):
"""Clear all cached LLM configurations.
Called as EventDispatcher handler, so accepts optional data param.
"""
cls.llms.clear()
debug('BufferedLLMs cache cleared')
async def get_llm(self, llmid, catelogid=None):
today = curDateString() today = curDateString()
"""
暂时不要buffered
k = f'{llmid}.{today}'
d = BufferedLLMs.llms.get(k)
if d:
return d
"""
env = ServerEnv() env = ServerEnv()
async with get_sor_context(env, 'llmage') as sor: async with get_sor_context(env, 'llmage') as sor:
sql = """select a.id, sql = """select a.id,
@ -324,12 +308,12 @@ from llm a
,uapi e on c.apisetid = e.apisetid and m.apiname = e.name ,uapi e on c.apisetid = e.apisetid and m.apiname = e.name
,uapiio f on e.ioid = f.id ,uapiio f on e.ioid = f.id
where a.id = m.llmid where a.id = m.llmid
and a.upappid = c.id and a.upappid = c.id
and c.apisetid = e.apisetid and m.apiname = e.name and c.apisetid = e.apisetid and m.apiname = e.name
and e.ioid = f.id and e.ioid = f.id
and a.id = ${llmid}$ and a.id = ${llmid}$
and a.expired_date > ${today}$ and a.expired_date > ${today}$
and a.enabled_date <= ${today}$ and a.enabled_date <= ${today}$
""" """
ns = {'llmid': llmid, 'today': today} ns = {'llmid': llmid, 'today': today}
if catelogid: if catelogid:
@ -341,27 +325,12 @@ where a.id = m.llmid
if len(recs) > 0: if len(recs) > 0:
r = recs[0] r = recs[0]
return r return r
# 暂时不buffer
dates = BufferedLLMs.llms.get(llmid, [])
dates.append(today)
cnt = len(dates)
if cnt > 2:
for i in range(0, cnt -2):
dat = dates[i]
del BufferedLLMs.llms[f'{llmid}.{dat}']
dates = dates[-2:]
BufferedLLMs.llms[llmid] = dates
BufferedLLMs.llms[k] = r
return r
else: else:
debug(f'{llmid=} not found, {ns=}, {sql=}') debug(f'{llmid=} not found, {ns=}, {sql=}')
return None return None
exception(f'Error: {format_exc()}') exception(f'Error: {format_exc()}')
return None return None
async def get_llm(llmid, catelogid=None):
bllms = BufferedLLMs()
return await bllms.get_llm(llmid, catelogid=catelogid)
async def write_llmusage(llmusage): async def write_llmusage(llmusage):
env = ServerEnv() env = ServerEnv()

View File

@ -48,6 +48,12 @@
"name": "ppid", "name": "ppid",
"type": "varchar(32)", "type": "varchar(32)",
"comment": "计费程序ID关联pricing_program表" "comment": "计费程序ID关联pricing_program表"
},
{
"name": "isdefaultcatelog",
"type": "varchar(1)",
"not_null": true,
"comment": "缺省分类"
} }
], ],
"indexes": [ "indexes": [