Skip to content

Commit 3e72731

Browse files
[Inference Providers] Fix status and response URLs when polling text-to-video results with fal-ai (#2943)
* fix fal ai urls * nit * remove type ignore
1 parent 17f562e commit 3e72731

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/huggingface_hub/inference/_providers/fal_ai.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
from abc import ABC
44
from typing import Any, Dict, Optional, Union
5+
from urllib.parse import urlparse
56

67
from huggingface_hub.inference._common import RequestParameters, _as_dict
78
from huggingface_hub.inference._providers._common import TaskProviderHelper, filter_none
@@ -122,11 +123,16 @@ def get_response(
122123
)
123124

124125
# extract the base url and query params
125-
base_url = request_params.url.split("?")[0] # or parsed.scheme + "://" + parsed.netloc + parsed.path ?
126-
query = "?_subdomain=queue" if request_params.url.endswith("_subdomain=queue") else ""
127-
128-
status_url = f"{base_url}/requests/{request_id}/status{query}"
129-
result_url = f"{base_url}/requests/{request_id}{query}"
126+
parsed_url = urlparse(request_params.url)
127+
# a bit hacky way to concatenate the provider name without parsing `parsed_url.path`
128+
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}{'/fal-ai' if parsed_url.netloc == 'router.huggingface.co' else ''}"
129+
query_param = f"?{parsed_url.query}" if parsed_url.query else ""
130+
131+
# extracting the provider model id for status and result urls
132+
# from the response as it might be different from the mapped model in `request_params.url`
133+
model_id = urlparse(response_dict.get("response_url")).path
134+
status_url = f"{base_url}{str(model_id)}/status{query_param}"
135+
result_url = f"{base_url}{str(model_id)}{query_param}"
130136

131137
status = response_dict.get("status")
132138
logger.info("Generating the video.. this can take several minutes.")

tests/test_inference_providers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,21 @@ def test_text_to_video_response(self, mocker):
310310
data=None,
311311
json=None,
312312
)
313-
response = helper.get_response(b'{"request_id": "test_request_id", "status": "PROCESSING"}', request_params)
313+
response = helper.get_response(
314+
b'{"request_id": "test_request_id", "status": "PROCESSING", "response_url": "https://queue.fal.run/username_provider/repo_name_provider/requests/test_request_id", "status_url": "https://queue.fal.run/username_provider/repo_name_provider/requests/test_request_id/status"}',
315+
request_params,
316+
)
314317

315318
# Verify the correct URLs were called
316319
assert mock_session.return_value.get.call_count == 3
317320
mock_session.return_value.get.assert_has_calls(
318321
[
319322
mocker.call(
320-
"https://router.huggingface.co/fal-ai/username/repo_name/requests/test_request_id/status?_subdomain=queue",
323+
"https://router.huggingface.co/fal-ai/username_provider/repo_name_provider/requests/test_request_id/status?_subdomain=queue",
321324
headers=request_params.headers,
322325
),
323326
mocker.call(
324-
"https://router.huggingface.co/fal-ai/username/repo_name/requests/test_request_id?_subdomain=queue",
327+
"https://router.huggingface.co/fal-ai/username_provider/repo_name_provider/requests/test_request_id?_subdomain=queue",
325328
headers=request_params.headers,
326329
),
327330
mocker.call("video_url"),

0 commit comments

Comments
 (0)