73 lines
2.1 KiB
Plaintext
73 lines
2.1 KiB
Plaintext
ns = {
|
|
"id":params_kw.get('modelinstanceid'),
|
|
"modeltypeid":params_kw.get('modeltypeid')
|
|
}
|
|
sql = """
|
|
select a.*,
|
|
b.name,
|
|
b.title,
|
|
b.icon_url,
|
|
b.providerid,
|
|
c.modeltypeid,
|
|
e.input_fields,
|
|
e.input_view,
|
|
e.output_view,
|
|
e.name as modeltypename,
|
|
d.use_session,
|
|
d.response_mode,
|
|
d.system_msg_format,
|
|
d.user_msg_format,
|
|
d.llm_msg_format,
|
|
d.apiinfo
|
|
from modelinstance a, models b, modelapi c, httpapi d, modeltype e
|
|
where
|
|
c.modeltypeid = e.id
|
|
and a.modelid = c.modelid
|
|
and a.modelid = b.id
|
|
and c.apiid = d.id
|
|
and a.id = ${id}$
|
|
and c.modeltypeid = ${modeltypeid}$
|
|
"""
|
|
|
|
db = DBPools()
|
|
async with db.sqlorContext('sage') as sor:
|
|
r = await sor.sqlExe(sql, ns.copy())
|
|
if len(r) == 0:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Error",
|
|
"timeout":3,
|
|
"message":f"{ns},{sql} model not found"
|
|
}
|
|
}
|
|
row = r[0]
|
|
print(f'{row.input_fields=}, {row.input_view=}, {row.user_msg_format=}, {row.llm_msg_format=}, {row.system_msg_format=}')
|
|
input_fields = json.loads(row.input_fields)
|
|
return {
|
|
"widgettype":"LlmIO",
|
|
"options":{
|
|
"height":"100%",
|
|
"estimate_url":"/estimate/model_estimate.dspy",
|
|
"input_fields":input_fields,
|
|
"input_view":json.loads(row.input_view),
|
|
"models":[
|
|
{
|
|
"modelinstanceid":row.id,
|
|
"modeltypeid":row.modeltypeid,
|
|
"output_view":json.loads(row.output_view),
|
|
"use_session":True if row.use_session == '1' else False,
|
|
"input_from":"userinput",
|
|
"response_mode":row.response_mode,
|
|
"system_message_format":{'role':'system', 'content':'${content}'} if row.system_msg_format is None or row.system_msg_format == '' else json.loads(row.system_msg_format),
|
|
"user_message_format":{'role':'user', 'content':'${prompt}'} if row.user_msg_format is None or row.user_msg_format == '' else json.loads(row.user_msg_format),
|
|
"llm_message_format":{'role':'assistant', 'content':'${content}'} if row.llm_msg_format is None or row.llm_msg_format == '' else json.loads(row.llm_msg_format),
|
|
"icon":entire_url(row.icon_url),
|
|
"url":entire_url('/llm/universe_llm.dspy'),
|
|
"model":row.name
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|