Skip to content

Commit 37d3553

Browse files
committed
fix: files api support and file_id bug remove
1 parent f99d500 commit 37d3553

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

veadk/models/ark_llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _file_data_to_content_param(
183183
fps = getattr(video_metadata, "fps", 1)
184184

185185
is_file_id = file_uri.startswith("file_id:")
186-
value = file_uri[7:] if is_file_id else file_uri
186+
value = file_uri[8:] if is_file_id else file_uri
187187
# video
188188
if mime_type.startswith("video/"):
189189
param = {"file_id": value} if is_file_id else {"video_url": value}

veadk/utils/misc.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import sys
1919
import time
2020
import types
21-
from typing import Any, Dict, List, MutableMapping, Tuple
21+
from typing import Any, Dict, List, MutableMapping, Tuple, Optional
2222

2323
import requests
2424
from yaml import safe_load
@@ -182,3 +182,34 @@ def get_agent_dir():
182182
full_path = os.getcwd()
183183

184184
return full_path
185+
186+
187+
async def upload_to_files_api(
188+
local_path: str,
189+
fps: Optional[str] = None,
190+
poll_interval: float = 3.0,
191+
max_wait_seconds: float = 10 * 60,
192+
) -> str:
193+
from veadk.config import getenv, settings
194+
from veadk.consts import DEFAULT_MODEL_AGENT_API_BASE
195+
from volcenginesdkarkruntime import AsyncArk
196+
197+
client = AsyncArk(
198+
api_key=getenv("MODEL_AGENT_API_KEY", settings.model.api_key),
199+
base_url=getenv("DEFAULT_MODEL_AGENT_API_BASE", DEFAULT_MODEL_AGENT_API_BASE),
200+
)
201+
file = await client.files.create(
202+
file=open(local_path, "rb"),
203+
purpose="user_data",
204+
preprocess_configs={
205+
"video": {
206+
"fps": fps,
207+
}
208+
}
209+
if fps
210+
else None,
211+
)
212+
await client.files.wait_for_processing(
213+
id=file.id, poll_interval=poll_interval, max_wait_seconds=max_wait_seconds
214+
)
215+
return file.id

0 commit comments

Comments
 (0)