Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support releative path #32

Merged
merged 2 commits into from
Nov 22, 2024
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
5 changes: 5 additions & 0 deletions .changeset/afraid-seals-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@llamaindex/chat-ui': patch
---

fix: support releative URLs in document viewer
10 changes: 2 additions & 8 deletions packages/chat-ui/src/widgets/document-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function DocumentInfo({
onRemove?: () => void
}) {
const { url, sources } = document
const fileName = urlToFileName(url)
const urlParts = url.split('/')
const fileName = urlParts.length > 0 ? urlParts[urlParts.length - 1] : url
const fileExt = fileName?.split('.').pop() as DocumentFileType | undefined

const previewFile = {
Expand Down Expand Up @@ -191,10 +192,3 @@ function DocumentPreviewCard(props: {
function inKB(size: number) {
return Math.round((size / 1024) * 10) / 10
}

function urlToFileName(url: string) {
const urlObj = new URL(url)
const urlParts = urlObj.pathname.split('/')
const fileName = urlParts.length > 0 ? urlParts[urlParts.length - 1] : url
return fileName
}
Loading