From e20831ed07eb96281f554a1f92fa08ff0e75c864 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Fri, 17 Apr 2026 17:05:31 +0530 Subject: [PATCH 1/2] feat: make text gen. async --- videodb/_constants.py | 2 ++ videodb/_utils/_http_client.py | 10 +++++++--- videodb/client.py | 9 +++++++++ videodb/collection.py | 9 ++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/videodb/_constants.py b/videodb/_constants.py index 99db326..9e35a39 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -123,11 +123,13 @@ class ApiPath: identities = "identities" merge = "merge" split = "split" + async_response = "async-response" class Status: processing = "processing" in_progress = "in progress" + complete = "complete" class MeetingStatus: diff --git a/videodb/_utils/_http_client.py b/videodb/_utils/_http_client.py index ecab5de..32fbba8 100644 --- a/videodb/_utils/_http_client.py +++ b/videodb/_utils/_http_client.py @@ -95,7 +95,10 @@ def _make_request( response = method(url, headers=request_headers, timeout=timeout, **kwargs) response.raise_for_status() if not wait: - return response.json().get("data") + data = response.json().get("data") + if data is not None: + return data + return response.json() return self._parse_response(response) except requests.exceptions.RequestException as e: @@ -185,6 +188,7 @@ def _parse_response(self, response: requests.Response): response_json.get("status") == Status.processing and response_json.get("request_type", "sync") == "sync" ): + print("inside loop") if self.show_progress: self.progress_bar = tqdm( total=100, @@ -233,12 +237,12 @@ def _apply_poll_overrides(self, kwargs): ) def get( - self, path: str, show_progress: Optional[bool] = False, **kwargs + self, path: str, show_progress: Optional[bool] = False, wait: bool = True, **kwargs ) -> requests.Response: """Make a get request""" self.show_progress = show_progress self._apply_poll_overrides(kwargs) - return self._make_request(method=self.session.get, path=path, **kwargs) + return self._make_request(method=self.session.get, path=path, wait=wait, **kwargs) def post( self, path: str, data=None, show_progress: Optional[bool] = False, diff --git a/videodb/client.py b/videodb/client.py index 7eac7bb..81bfa96 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -494,3 +494,12 @@ def generate_client_token(self, expires_in: int = 86400) -> str: data={"expires_in": expires_in}, ) return response.get("token") + + def get_async_response(self, id: str) -> dict: + """Get the details of an async response. + + :param str id: ID of the async response + :return: Details of the async response + :rtype: dict + """ + return self.get(path=f"{ApiPath.async_response}/{id}", wait=False) diff --git a/videodb/collection.py b/videodb/collection.py index 73e06e9..07f94ba 100644 --- a/videodb/collection.py +++ b/videodb/collection.py @@ -425,6 +425,8 @@ def generate_text( prompt: str, model_name: Literal["basic", "pro", "ultra"] = "basic", response_type: Literal["text", "json"] = "text", + wait: bool = True, + callback_url: Optional[str] = None, ) -> Union[str, dict]: """Generate text from a prompt using genai offering. @@ -436,13 +438,16 @@ def generate_text( :param str prompt: Prompt for the text generation :param str model_name: Model name to use ("basic", "pro" or "ultra") :param str response_type: Desired response type ("text" or "json") - :return: Generated text response + :param bool wait: Wait for the text generation to complete (default: True) + :param str callback_url: URL to receive the callback (optional) + :return: Generated text response if wait is False, otherwise job id of the text generation :rtype: Union[str, dict] """ payload = { "prompt": prompt, "model_name": model_name, "response_type": response_type, + "callback_url": callback_url, } payload_size = len(json.dumps(payload).encode("utf-8")) @@ -457,11 +462,13 @@ def generate_text( ), "model_name": model_name, "response_type": response_type, + "callback_url": callback_url, } return self._connection.post( path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.text}", data=payload, + wait=wait, ) def dub_video( From a1967b97cc60013fd324ab145a884e3a8972cf7c Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Fri, 17 Apr 2026 18:10:28 +0530 Subject: [PATCH 2/2] fix: remove print --- videodb/_utils/_http_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/videodb/_utils/_http_client.py b/videodb/_utils/_http_client.py index 32fbba8..6507e38 100644 --- a/videodb/_utils/_http_client.py +++ b/videodb/_utils/_http_client.py @@ -188,7 +188,6 @@ def _parse_response(self, response: requests.Response): response_json.get("status") == Status.processing and response_json.get("request_type", "sync") == "sync" ): - print("inside loop") if self.show_progress: self.progress_bar = tqdm( total=100,