Skip to content

Commit d9b518e

Browse files
committed
deploy
1 parent 812e43d commit d9b518e

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/model_deploy/index.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

src/model_download/index.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff 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!")

0 commit comments

Comments
 (0)