@@ -93,80 +93,74 @@ def register_model(base_path):
9393 model_attributes = get_model_attributes (base_path )
9494 model_data = llm_fact_sheet [llm_fact_sheet ['model_id' ] == base_path ]
9595 if model_data .empty :
96- print (f"The selected LLM: { base_path } is not vailable in the llm_fact_sheet.csv. This is a required entry!" )
96+ print (f"WARNING: The selected LLM: { base_path } is not vailable in the llm_fact_sheet.csv." )
97+ print ('WARNING: This entry is required for the Logging/Monitoring to work properly!' )
98+ # Add additional model metadata from the llm_fact_sheet.csv
99+ model_attributes ['llmModelType' ] = model_attributes .get ('llmModelType' , 'GPT' )
100+ model_data_dict = model_data .to_dict ('records' )[0 ]
101+ model_attributes ['provider' ] = model_data_dict .get ('provider' , 'Unkown' )
102+ model_attributes ['endPoint' ] = f"{ args .scr_endpoint } /{ base_path } /{ base_path } "
103+ cost_estimation_type = model_data_dict .get ('cost_type' , 'Tokens' )
104+ costPerCall = 0
105+ if (cost_estimation_type == 'Tokens' ):
106+ costPerCall = (float (model_data_dict .get ('input_token_price' , '0' )) + float (model_data_dict .get ('output_token_price' , '0' ))) / 2
107+ elif (cost_estimation_type == 'Seconds' ):
108+ costPerCall = float (model_data_dict .get ('second_cost' , '0' ))
97109 else :
98- # Add additional model metadata from the llm_fact_sheet.csv
99- model_attributes ['llmModelType' ] = model_attributes .get ('llmModelType' , 'GPT' )
100- model_data_dict = model_data .to_dict ('records' )[0 ]
101- model_attributes ['provider' ] = model_data_dict .get ('provider' , 'Unkown' )
102- model_attributes ['endPoint' ] = f"{ args .scr_endpoint } /{ base_path } /{ base_path } "
103- cost_estimation_type = model_data_dict .get ('cost_type' , 'Tokens' )
104- costPerCall = 0
105- if (cost_estimation_type == 'Tokens' ):
106- costPerCall = (float (model_data_dict .get ('input_token_price' , '0' )) + float (model_data_dict .get ('output_token_price' , '0' ))) / 2
107- elif (cost_estimation_type == 'Seconds' ):
108- costPerCall = float (model_data_dict .get ('second_cost' , '0' ))
109- else :
110- print (f"The cost type for LLMs has to be either Tokens or Seconds, the value provided was: { cost_estimation_type } for { base_path } " )
111- model_attributes ['costPerCall' ] = costPerCall
112- model_object = mr .create_model (model = model_attributes , project = project_attributes ['project_name' ])
110+ print (f"The cost type for LLMs has to be either Tokens or Seconds, the value provided was: { cost_estimation_type } for { base_path } " )
111+ model_attributes ['costPerCall' ] = costPerCall
112+ model_object = mr .create_model (model = model_attributes , project = project_attributes ['project_name' ])
113113
114- time .sleep (1 )
115- # Score script
116- file = open (f"{ base_path } /{ model_attributes ['scoreCodeFile' ]} " , 'rb' )
117- mr .add_model_content (model_object ,
118- file ,
119- name = model_attributes ['name' ] + '.py' ,
120- role = 'score' )
121- file .close ()
122-
123- # Dependencies
124- file = open (f"{ base_path } /requirements.json" , 'rb' )
125- mr .add_model_content (model_object ,
126- file ,
127- name = 'requirements.json' ,
128- role = 'python pickle' )
129- file .close ()
130-
131- # Output variables
132- file = open (f"{ base_path } /outputVar.json" , 'rb' )
133- mr .add_model_content (model_object , file , name = 'outputVar.json' )
134- file .close ()
114+ time .sleep (1 )
115+ # Score script
116+ file = open (f"{ base_path } /{ model_attributes ['scoreCodeFile' ]} " , 'rb' )
117+ mr .add_model_content (model_object , file , name = model_attributes ['name' ] + '.py' , role = 'score' )
118+ file .close ()
119+
120+ # Dependencies
121+ file = open (f"{ base_path } /requirements.json" , 'rb' )
122+ mr .add_model_content (model_object , file , name = 'requirements.json' , role = 'python pickle' )
123+ file .close ()
124+
125+ # Output variables
126+ file = open (f"{ base_path } /outputVar.json" , 'rb' )
127+ mr .add_model_content (model_object , file , name = 'outputVar.json' )
128+ file .close ()
135129
136- # Input variables
137- file = open (f"{ base_path } /inputVar.json" , 'rb' )
138- mr .add_model_content (model_object , file , name = 'inputVar.json' )
139- file .close ()
140-
141- # Options information
142- file = open (f"{ base_path } /options.json" , 'rb' )
143- mr .add_model_content (model_object , file , name = 'options.json' , role = 'documentation' )
144- file .close ()
145-
146- # Upload the optional model card
147- if os .path .exists (f"{ base_path } /Model-Card.pdf" ):
148- file = open (f"{ base_path } /Model-Card.pdf" , 'rb' )
149- mr .add_model_content (model_object , file , name = 'Model-Card.pdf' , role = 'documentation' )
150- elif os .path .exists (f"{ base_path } /Model-Card.md" ):
151- file = open (f"{ base_path } /Model-Card.md" , 'rb' )
152- mr .add_model_content (model_object , file , name = 'Model-Card.md' , role = 'documentation' )
153- else :
154- print (f"No model card added for { base_path } " )
155-
156- # Upload toknizer filesif they exist
157- if os .path .exists (f"{ base_path } /tokenizer_config.json" ):
158- file = open (f"{ base_path } /tokenizer_config.json" , 'rb' )
159- mr .add_model_content (model_object , file , name = 'tokenizer_config.json' , role = 'documentation' )
160- if os .path .exists (f"{ base_path } /special_tokens_map.json" ):
161- file = open (f"{ base_path } /special_tokens_map.json" , 'rb' )
162- mr .add_model_content (model_object , file , name = 'special_tokens_map.json' , role = 'documentation' )
163- if os .path .exists (f"{ base_path } /tokenizer.json" ):
164- file = open (f"{ base_path } /tokenizer.json" , 'rb' )
165- mr .add_model_content (model_object , file , name = 'tokenizer.json' , role = 'documentation' )
166-
167- update_model_tags (model_attributes , model_object .id )
168- print (f"Link to the model in SAS Model Manager: { args .viya_server } /SASModelManager/models/{ model_object .id } " )
169- return model_object
130+ # Input variables
131+ file = open (f"{ base_path } /inputVar.json" , 'rb' )
132+ mr .add_model_content (model_object , file , name = 'inputVar.json' )
133+ file .close ()
134+
135+ # Options information
136+ file = open (f"{ base_path } /options.json" , 'rb' )
137+ mr .add_model_content (model_object , file , name = 'options.json' , role = 'documentation' )
138+ file .close ()
139+
140+ # Upload the optional model card
141+ if os .path .exists (f"{ base_path } /Model-Card.pdf" ):
142+ file = open (f"{ base_path } /Model-Card.pdf" , 'rb' )
143+ mr .add_model_content (model_object , file , name = 'Model-Card.pdf' , role = 'documentation' )
144+ elif os .path .exists (f"{ base_path } /Model-Card.md" ):
145+ file = open (f"{ base_path } /Model-Card.md" , 'rb' )
146+ mr .add_model_content (model_object , file , name = 'Model-Card.md' , role = 'documentation' )
147+ else :
148+ print (f"No model card added for { base_path } " )
149+
150+ # Upload toknizer filesif they exist
151+ if os .path .exists (f"{ base_path } /tokenizer_config.json" ):
152+ file = open (f"{ base_path } /tokenizer_config.json" , 'rb' )
153+ mr .add_model_content (model_object , file , name = 'tokenizer_config.json' , role = 'documentation' )
154+ if os .path .exists (f"{ base_path } /special_tokens_map.json" ):
155+ file = open (f"{ base_path } /special_tokens_map.json" , 'rb' )
156+ mr .add_model_content (model_object , file , name = 'special_tokens_map.json' , role = 'documentation' )
157+ if os .path .exists (f"{ base_path } /tokenizer.json" ):
158+ file = open (f"{ base_path } /tokenizer.json" , 'rb' )
159+ mr .add_model_content (model_object , file , name = 'tokenizer.json' , role = 'documentation' )
160+
161+ update_model_tags (model_attributes , model_object .id )
162+ print (f"Link to the model in SAS Model Manager: { args .viya_server } /SASModelManager/models/{ model_object .id } " )
163+ return model_object
170164
171165# Establish a session
172166try :
0 commit comments