Skip to content

Commit e17d7c4

Browse files
committed
feat: add file upload method with base64 encoding in image.py
1 parent 2a09615 commit e17d7c4

File tree

2 files changed

+9
-1
lines changed
  • apps/models_provider/impl
    • aliyun_bai_lian_model_provider/model
    • volcanic_engine_model_provider/model

2 files changed

+9
-1
lines changed

apps/models_provider/impl/aliyun_bai_lian_model_provider/model/image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ def upload_file_and_get_url(self, file_stream, file_name):
8686
policy_data = self.get_upload_policy(self.openai_api_key.get_secret_value(), self.model_name)
8787
# 2. 上传文件到OSS
8888
oss_url = self.upload_file_to_oss(policy_data, file_stream, file_name)
89-
print(oss_url)
9089

9190
return oss_url
9291

apps/models_provider/impl/volcanic_engine_model_provider/model/image.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import base64
2+
import mimetypes
13
from typing import Dict
24

35
from models_provider.base_model_provider import MaxKBBaseModel
@@ -22,3 +24,10 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], **
2224
@staticmethod
2325
def is_cache_model():
2426
return False
27+
28+
29+
def upload_file_and_get_url(self, file_stream, file_name):
30+
"""上传文件并获取文件URL"""
31+
base64_video = base64.b64encode(file_stream).decode("utf-8")
32+
video_format = mimetypes.guess_type(file_name)[0]
33+
return f'data:{video_format};base64,{base64_video}'

0 commit comments

Comments
 (0)