Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Llama Index
Commits
23f1491d
Unverified
Commit
23f1491d
authored
1 year ago
by
Huu Le (Lee)
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix null value in default file document metadata (#11501)
parent
b66f94c5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llama-index-core/llama_index/core/readers/file/base.py
+26
-14
26 additions, 14 deletions
llama-index-core/llama_index/core/readers/file/base.py
with
26 additions
and
14 deletions
llama-index-core/llama_index/core/readers/file/base.py
+
26
−
14
View file @
23f1491d
...
@@ -56,6 +56,21 @@ def _try_loading_included_file_formats() -> Dict[str, Type[BaseReader]]:
...
@@ -56,6 +56,21 @@ def _try_loading_included_file_formats() -> Dict[str, Type[BaseReader]]:
return
default_file_reader_cls
return
default_file_reader_cls
def
_format_file_timestamp
(
timestamp
:
float
)
->
Optional
[
str
]:
"""
Format file timestamp to a %Y-%m-%d string.
Args:
timestamp (float): timestamp in float
Returns:
str: formatted timestamp
"""
try
:
return
datetime
.
fromtimestamp
(
timestamp
).
strftime
(
"
%Y-%m-%d
"
)
except
Exception
:
return
None
def
default_file_metadata_func
(
def
default_file_metadata_func
(
file_path
:
str
,
fs
:
Optional
[
fsspec
.
AbstractFileSystem
]
=
None
file_path
:
str
,
fs
:
Optional
[
fsspec
.
AbstractFileSystem
]
=
None
)
->
Dict
:
)
->
Dict
:
...
@@ -66,20 +81,10 @@ def default_file_metadata_func(
...
@@ -66,20 +81,10 @@ def default_file_metadata_func(
"""
"""
fs
=
fs
or
get_default_fs
()
fs
=
fs
or
get_default_fs
()
stat_result
=
fs
.
stat
(
file_path
)
stat_result
=
fs
.
stat
(
file_path
)
creation_date
=
stat_result
.
get
(
"
created
"
)
creation_date
=
_format_file_timestamp
(
stat_result
.
get
(
"
created
"
))
last_modified_date
=
stat_result
.
get
(
"
mtime
"
)
last_modified_date
=
_format_file_timestamp
(
stat_result
.
get
(
"
mtime
"
))
last_accessed_date
=
stat_result
.
get
(
"
atime
"
)
last_accessed_date
=
_format_file_timestamp
(
stat_result
.
get
(
"
atime
"
))
try
:
default_meta
=
{
creation_date
=
datetime
.
fromtimestamp
(
creation_date
).
strftime
(
"
%Y-%m-%d
"
)
last_modified_date
=
datetime
.
fromtimestamp
(
last_modified_date
).
strftime
(
"
%Y-%m-%d
"
)
last_accessed_date
=
datetime
.
fromtimestamp
(
last_accessed_date
).
strftime
(
"
%Y-%m-%d
"
)
except
Exception
:
pass
return
{
"
file_path
"
:
file_path
,
"
file_path
"
:
file_path
,
"
file_name
"
:
stat_result
[
"
name
"
],
"
file_name
"
:
stat_result
[
"
name
"
],
"
file_type
"
:
mimetypes
.
guess_type
(
file_path
)[
0
],
"
file_type
"
:
mimetypes
.
guess_type
(
file_path
)[
0
],
...
@@ -89,6 +94,13 @@ def default_file_metadata_func(
...
@@ -89,6 +94,13 @@ def default_file_metadata_func(
"
last_accessed_date
"
:
last_accessed_date
,
"
last_accessed_date
"
:
last_accessed_date
,
}
}
# Return not null value
return
{
meta_key
:
meta_value
for
meta_key
,
meta_value
in
default_meta
.
items
()
if
meta_value
is
not
None
}
class
_DefaultFileMetadataFunc
:
class
_DefaultFileMetadataFunc
:
"""
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment