models.ui.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * 初始化模型列表。
  3. * Initialize models list.
  4. *
  5. * @access public
  6. * @return void
  7. */
  8. window.initModelList = async function()
  9. {
  10. const isOK = await zui.AIPanel?.shared?.store.isOK();
  11. if(!isOK) return;
  12. $('#modelsList').addClass('loading');
  13. const models = await zui.AIPanel.shared.store.getLlmModels();
  14. (models || []).forEach((model, index)=>
  15. {
  16. model.index = index + 1;
  17. model.name = model.name || model.id;
  18. });
  19. const {modelLang, actionLang, converseLang, canConverse} = $('.models-view').data();
  20. const cols = [
  21. {name: 'index', title: 'ID', type: 'id', sortType: false},
  22. {name: 'name', title: modelLang},
  23. {name: 'actions', title: actionLang, width: 90, type: 'actions', onRenderCell(_result, {col, row})
  24. {
  25. if(!canConverse) return [{html: ''}];
  26. let link = $.createLink('aiapp', 'conversation', `chat=NEW&params=${btoa(JSON.stringify({model: row.data.id}))}`);
  27. let disabledClass = '';
  28. if(!row.data.abilities.includes('chat'))
  29. {
  30. link = '';
  31. disabledClass = 'pointer-events-none disabled';
  32. }
  33. return [{html: `<a class="btn size-sm ghost text-primary ${disabledClass}" href="${link}">${converseLang}</a>`}];
  34. }},
  35. ];
  36. $('#modelsList').zui('dtable').render({cols, data: models});
  37. $('#modelsList').removeClass('loading');
  38. }
  39. /**
  40. * 为模型列表设置表格页脚。
  41. * Set models summary for table footer.
  42. *
  43. * @access public
  44. * @return object
  45. */
  46. window.setModelsStatistics = function()
  47. {
  48. const pageSummary = $('.models-view').data('pageSummary');
  49. const rows = this.layout.allRows;
  50. return {html: pageSummary.replace('%s', rows.length)};
  51. }