Skip to content

Commit

Permalink
docs(media): add update upload status to cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
hassiebp committed Nov 24, 2024
1 parent 70739b9 commit d220b99
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cookbook/example_multi_modal_traces.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@
"## Custom via API"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Link to API docs](https://api.reference.langfuse.com/#tag--Media)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -499,6 +506,36 @@
" print(\"File uploaded\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Update upload status"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime, timezone\n",
"\n",
"if upload_response is not None:\n",
" requests.patch(\n",
" f\"{base_URL}/api/public/media/{upload_url_response['mediaId']}\",\n",
" auth=(public_key or \"\", secret_key or \"\"),\n",
" headers={\"Content-Type\": \"application/json\"},\n",
" json={\n",
" \"uploadedAt\": datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%fZ'), # ISO 8601\n",
" \"uploadHttpStatus\": upload_response.status_code,\n",
" \"uploadHttpError\": upload_response.text if upload_response.status_code != 200 else None,\n",
" },\n",
" )\n",
"\n",
" print(\"Upload status updated\")"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down
23 changes: 23 additions & 0 deletions pages/guides/cookbook/example_multi_modal_traces.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ handler.flush()

## Custom via API

[Link to API docs](https://api.reference.langfuse.com/#tag--Media)

### Setup


Expand Down Expand Up @@ -298,6 +300,27 @@ if (
print("File uploaded")
```

### Update upload status


```python
from datetime import datetime, timezone

if upload_response is not None:
requests.patch(
f"{base_URL}/api/public/media/{upload_url_response['mediaId']}",
auth=(public_key or "", secret_key or ""),
headers={"Content-Type": "application/json"},
json={
"uploadedAt": datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%fZ'), # ISO 8601
"uploadHttpStatus": upload_response.status_code,
"uploadHttpError": upload_response.text if upload_response.status_code != 200 else None,
},
)

print("Upload status updated")
```

### Fetch media link


Expand Down

0 comments on commit d220b99

Please sign in to comment.