diff --git a/llmage/init.py b/llmage/init.py index f257362..1df2b95 100644 --- a/llmage/init.py +++ b/llmage/init.py @@ -1,3 +1,11 @@ +from llmage.llmclient import get_llm, inference, get_llmcatelogs, \ + get_llms_by_catelog +from ahserver.serverenv import ServerEnv def load_llmage(): - pass + env = ServerEnv() + env.get_llm = get_llm + env.inference = inference + env.get_llms_by_catelog = get_llms_by_catelog + eng.get_llmcatelogs = get_llmcatelogs + diff --git a/llmage/llmclient.py b/llmage/llmclient.py index 083961c..e480291 100644 --- a/llmage/llmclient.py +++ b/llmage/llmclient.py @@ -1,8 +1,49 @@ from traceback import format_exc +from sqlor.dbpools import DBPools from appPublic.log import debug, exception -from uapi.appapi import UAPI +from uapi.appapi import UAPI, sor_get_callerid, sor_get_uapi from ahserver.serverenv get_serverenv +async def get_llmcatelogs(): + db = DBPools() + dbname = get_serverenv('get_module_dbname')('llmage') + async with db.sqlorContext(dbname) as sor: + recs = await sor.R('llmcatelog', {}) + return recs + + return [] + +async def get_llms_by_catelog(catelogid): + db = DBPools() + dbname = get_serverenv('get_module_dbname')('llmage') + async with db.sqlorContext(dbname) as sor: + recs = await sor.R('llm', {'catelogid': catelogid}) + return recs + return [] + +async def get_llm(llmid): + db = DBPools() + dbname = get_serverenv('get_module_dbname')('llmage') + async with db.sqlorContext(dbname) as sor: + sql = """select a.*, +b.input_view, b.output_view, b.system_message, +b.user_message, +b.assisant_message from llm a, llmcatelog b +where a.catelogid = b.id + and a.id = ${llmid}$""" + recs = await sor.sqlExe(sql, {'llmid': llmid}) + if len(recs) > 0: + r = recs[0] + apis = await sor_get_uapi(sor, r.upappid, r.apiname) + if len(apis) == 0: + e = Exception(f'{r.upappid=},{r.apiname=} uapi not found') + exception(f'{e=}\n{format_exc()}') + raise e + api = apis[0] + r.inputfields = api.paramsdesc + return recs[0] + return None + async def inference(request, env): uapi = UAPI(request, env) params = env.params_kw diff --git a/models/llmcatelog.xlsx b/models/llmcatelog.xlsx index ad1c259..544be48 100644 Binary files a/models/llmcatelog.xlsx and b/models/llmcatelog.xlsx differ diff --git a/wwwroot/llm_dialog.ui b/wwwroot/llm_dialog.ui new file mode 100644 index 0000000..5bb9eea --- /dev/null +++ b/wwwroot/llm_dialog.ui @@ -0,0 +1,30 @@ +{% set llm = get_llm(params_kw.id) %} +{% if llm %} +{ + "widgettype":"LlmIO", + "options":{ + "width":"100%", + "height":"100%", + "list_models_url":"{{entire_url('list_mti_models.dspy')}}", + "estimate_url":"/estimate/model_estimate.dspy", + "input_fields":{{llm.input_fields}}, + "input_view":{{llm.input_view}}, + "models":[ + { + "llmidid":"{{llm.id}}", + "modeltypeid":"{{llm.catelogid}}", + "output_view":{{llm.output_view}}, + "input_from":"userinput", + "system_message_format":{{llm.system_message}}, + "user_message_format":{{llm.user_message}}, + "llm_message_format":{{llm.assisant_message}}, + "icon":"{{entire_url('/appbase/get_icon.dspy')}}?id={{llm.iconid}}", + "url":"{{entire_url('/llmage/llminference.dspy')}}", + "model":"{{llm.model}}", + "modelname":"{{llm.name}}" + } + ] + } +} +{% else %} +{% endif %} diff --git a/wwwroot/llminference.dspy b/wwwroot/llminference.dspy new file mode 100644 index 0000000..05d4c8f --- /dev/null +++ b/wwwroot/llminference.dspy @@ -0,0 +1,2 @@ +env = DictObject(**globals()) +return inference(request, env=env) diff --git a/wwwroot/show_llms.ui b/wwwroot/show_llms.ui new file mode 100644 index 0000000..559d491 --- /dev/null +++ b/wwwroot/show_llms.ui @@ -0,0 +1,76 @@ +{ + "widgettype":"VBox", + "options":{ + "width":"100%", + "height":"100%" + }, + "subwidgets":[ +{% for cate in get_llmcatelogs() %} + { + "widgettype": "VBox", + "options":{ + "width":"100%" + }, + "subwidgets":[ + { + "widgettype":"Title3", + "options":{ + "text":"{{cate.name}}" + } + }, + { + "widgettype":"DynamicColumn", + "options":{ + "css":"filler", + "width":"100%" + }, + "subwidgets":[ +{% for llm in get_llms_by_catelog(cate.id) %} + { + "widgettype":"VBox", + "options":{ + "cwidth":16, + "cheight":8 + }, + "subwidgets":[ + { + "widgettype":"Title5", + "options":{"text":"{{llm.name}}" + }, + { + "widgettype":"Text", + "options":{ + "text":"{{llm.description}}", + "wrap":true, + "halign":"left" + } + } + ], + "binds":[ + { + "wid":"self", + "event":"click", + "actiontype":"urlwidget", + "target":"PopupWindow", + "popup_options":{ + "width":"90%", + "height":"90%" + }, + "options":{ + "params":{ + "id":"{{llm.id}}" + }, + "url":"{{entire_url('./llminference.dspy')}}" + } + } + ] + } +{% if not loop.last %}, {% endif %} +{% endfor %} + ] + } + ] + } +{% endfor %} + ] +}