File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,4 +13,22 @@ def handler(event, context):
1313 family = os .getenv ('MODEL_FAMILY' , '' )
1414 served_model_name = os .getenv ('SERVED_MODEL_NAME' , '' )
1515
16- return {'served_model_name' : served_model_name }
16+ cmd = f'cd { cache_dir } /ollama-linux && sudo chmod 777 ./ollama-modelscope-install.sh && ./ollama-modelscope-install.sh'
17+ os .system (cmd )
18+ cmd = 'ollama serve &'
19+ os .system (cmd )
20+
21+ if modelfile and len (modelfile ):
22+ os .system (f'cat { modelfile } > { cache_dir } /ModelFile' )
23+ elif family and len (family ):
24+ os .system (f'wget https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/{ family } .modelfile' )
25+ command_gen_modelfile = f'cat { family } .modelfile | sed "s/' + '{gguf_file}' + f'/{ gguf_file } /" > ./ModelFile'
26+ os .system (command_gen_modelfile )
27+ else :
28+ raise ValueError (f'modelfile 和 model_family至少需要配置一个。用于ollama模型初始化。' )
29+
30+ # run ollama
31+ cmd = f'ollama create { served_model_name } --file ./ModelFile'
32+ os .system (cmd )
33+ cmd = f'ollama run { served_model_name } '
34+ os .system (cmd )
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ def handler(event, context):
99 sdk_token = os .getenv ('MODELSCOPE_TOKEN' , '' )
1010 image_tag = os .getenv ('IMAGE_TAG' , '' )
1111 gguf_file = os .getenv ('GGUF_FILE' , '' )
12- modelfile = os .getenv ('MODELFILE' , '' )
13- family = os .getenv ('MODEL_FAMILY' , '' )
1412
1513 # login first.
1614 HubApi ().login (sdk_token )
@@ -29,14 +27,5 @@ def handler(event, context):
2927
3028 command_download_model = f'modelscope download --model={ model_id } --local_dir { cache_dir } ${ gguf_file } '
3129 os .system (command_download_model )
32-
33- if modelfile and len (modelfile ):
34- os .system (f'cat { modelfile } > { cache_dir } /ModelFile' )
35- elif family and len (family ):
36- os .system (f'wget https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/{ family } .modelfile' )
37- command_gen_modelfile = f'cat { family } .modelfile | sed "s/' + '{gguf_file}' + f'/{ gguf_file } /" > { cache_dir } /ModelFile'
38- os .system (command_gen_modelfile )
39- else :
40- raise ValueError (f'modelfile 和 model_family至少需要配置一个。用于ollama模型初始化。' )
4130
4231 print ("download model scuccess!" )
You can’t perform that action at this time.
0 commit comments