Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions videodb/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions videodb/_utils/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -233,12 +236,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,
Expand Down
9 changes: 9 additions & 0 deletions videodb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 8 additions & 1 deletion videodb/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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"))
Expand All @@ -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(
Expand Down
Loading