Skip to content

Commit

Permalink
Add download_filename for specifying a filename when downloading from…
Browse files Browse the repository at this point in the history
… url

Previously the filename from the download_url was always used. This
enables bots to set a custom filename for attachments they post via
download_url.

Updates version to 0.0.51
  • Loading branch information
agamble-quora committed Dec 16, 2024
1 parent 92c6eb5 commit d23bfc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "fastapi_poe"
version = "0.0.50"
version = "0.0.51"
authors = [
{ name="Lida Li", email="lli@quora.com" },
{ name="Jelle Zijlstra", email="jelle@quora.com" },
Expand Down
9 changes: 9 additions & 0 deletions src/fastapi_poe/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ async def post_message_attachment(
message_id: Identifier,
*,
download_url: Optional[str] = None,
download_filename: Optional[str] = None,
file_data: Optional[Union[bytes, BinaryIO]] = None,
filename: Optional[str] = None,
content_type: Optional[str] = None,
Expand All @@ -338,6 +339,7 @@ async def post_message_attachment(
*,
message_id: Identifier,
download_url: Optional[str] = None,
download_filename: Optional[str] = None,
file_data: Optional[Union[bytes, BinaryIO]] = None,
filename: Optional[str] = None,
content_type: Optional[str] = None,
Expand All @@ -350,6 +352,7 @@ async def post_message_attachment(
message_id: Optional[Identifier] = None,
*,
download_url: Optional[str] = None,
download_filename: Optional[str] = None,
file_data: Optional[Union[bytes, BinaryIO]] = None,
filename: Optional[str] = None,
content_type: Optional[str] = None,
Expand All @@ -366,6 +369,8 @@ async def post_message_attachment(
- `access_key` (`str`): The access_key corresponding to your bot. This is needed to ensure
that file upload requests are coming from an authorized source.
- `download_url` (`Optional[str] = None`): A url to the file to be attached to the message.
- `download_filename` (`Optional[str] = None`): A filename to be used when storing the
downloaded attachment. If not set, the filename from the `download_url` is used.
- `file_data` (`Optional[Union[bytes, BinaryIO]] = None`): The contents of the file to be
uploaded. This should be a bytes-like or file object.
- `filename` (`Optional[str] = None`): The name of the file to be attached.
Expand All @@ -384,6 +389,7 @@ async def post_message_attachment(
access_key=access_key,
message_id=message_id,
download_url=download_url,
download_filename=download_filename,
file_data=file_data,
filename=filename,
content_type=content_type,
Expand All @@ -406,6 +412,7 @@ async def _make_file_attachment_request(
*,
access_key: Optional[str] = None,
download_url: Optional[str] = None,
download_filename: Optional[str] = None,
file_data: Optional[Union[bytes, BinaryIO]] = None,
filename: Optional[str] = None,
content_type: Optional[str] = None,
Expand Down Expand Up @@ -443,6 +450,8 @@ async def _make_file_attachment_request(
"is_inline": is_inline,
"download_url": download_url,
}
if download_filename:
data["download_filename"] = download_filename
request = httpx.Request("POST", url, data=data, headers=headers)
elif file_data and filename:
data = {"message_id": message_id, "is_inline": is_inline}
Expand Down

0 comments on commit d23bfc2

Please sign in to comment.