@@ -5,9 +5,9 @@ import { addPriceBadgeToNode, hasModelInput } from "./model_price.js";
55const BIZYAIR_MODEL_TYPE_KEY = "bizyair_model_type" ;
66
77// 获取node 的模型配置input
8- export async function applyBadgeToNode ( _this ) {
9- // 优先从节点属性中恢复模型类型(用于工作流加载场景)
10- if ( _this . properties && _this . properties [ BIZYAIR_MODEL_TYPE_KEY ] ) {
8+ export async function applyBadgeToNode ( _this , forceRefresh = false ) {
9+ // 如果不是强制刷新, 优先从节点属性中恢复模型类型(用于工作流加载场景)
10+ if ( ! forceRefresh && _this . properties && _this . properties [ BIZYAIR_MODEL_TYPE_KEY ] ) {
1111 const modelType = _this . properties [ BIZYAIR_MODEL_TYPE_KEY ] ;
1212 await addPriceBadgeToNode ( _this , modelType ) ;
1313 return ;
@@ -26,8 +26,8 @@ export async function applyBadgeToNode(_this) {
2626 return ;
2727 }
2828
29- // 解析模型类型
30- const modelType = getModelTypeFromHiddenInput ( hiddenOutput ) ;
29+ // 解析模型类型(传入节点对象以获取用户选择的model)
30+ const modelType = getModelTypeFromHiddenInput ( hiddenOutput , _this ) ;
3131
3232 // 将hiddenOutput临时存储在节点上,方便后续使用
3333 _this . _bizyairHiddenOutput = hiddenOutput ;
@@ -48,10 +48,30 @@ export async function applyBadgeToNode(_this) {
4848}
4949
5050// 从hiddenInput中获取模型类型
51- function getModelTypeFromHiddenInput ( hiddenOutput ) {
51+ function getModelTypeFromHiddenInput ( hiddenOutput , node ) {
5252 const modelJson = JSON . parse ( hiddenOutput . type ) ;
53+
54+ // 从节点的widgets中获取用户选择的model
55+ let selectedModel = null ;
56+ const possibleWidgetNames = [ "model" , "model_name" ] ;
57+
58+ if ( node . widgets && Array . isArray ( node . widgets ) ) {
59+ for ( const widget of node . widgets ) {
60+ if ( possibleWidgetNames . includes ( widget . name ) && widget . value ) {
61+ selectedModel = widget . value ;
62+ break ;
63+ }
64+ }
65+ }
66+
67+ // 如果找到了用户选择的model,使用它作为key
68+ if ( selectedModel && modelJson [ selectedModel ] ) {
69+ return modelJson [ selectedModel ] ;
70+ }
71+
72+ // 如果没找到或key不存在,回退到使用第一个键(兼容旧逻辑)
5373 const modelsList = Object . keys ( modelJson ) ;
54- return modelJson [ modelsList [ 0 ] ]
74+ return modelJson [ modelsList [ 0 ] ] ;
5575}
5676
5777// 自定义节点创建处理函数
0 commit comments