Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Create Llama
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
Create Llama
Commits
a221cfc1
Unverified
Commit
a221cfc1
authored
9 months ago
by
Huu Le
Committed by
GitHub
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: use LlamaParse for all the supported types (#154)
parent
d3f92f8a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.changeset/olive-knives-cheat.md
+5
-0
5 additions, 0 deletions
.changeset/olive-knives-cheat.md
templates/components/loaders/python/file.py
+17
-5
17 additions, 5 deletions
templates/components/loaders/python/file.py
with
22 additions
and
5 deletions
.changeset/olive-knives-cheat.md
0 → 100644
+
5
−
0
View file @
a221cfc1
---
"
create-llama"
:
patch
---
Use LlamaParse for all the file types that it supports (if activated)
This diff is collapsed.
Click to expand it.
templates/components/loaders/python/file.py
+
17
−
5
View file @
a221cfc1
import
os
import
logging
from
typing
import
Dict
from
llama_parse
import
LlamaParse
from
pydantic
import
BaseModel
,
validator
...
...
@@ -32,13 +33,18 @@ def llama_parse_parser():
return
parser
def
llama_parse_extractor
()
->
Dict
[
str
,
LlamaParse
]:
from
llama_parse.utils
import
SUPPORTED_FILE_TYPES
parser
=
llama_parse_parser
()
return
{
file_type
:
parser
for
file_type
in
SUPPORTED_FILE_TYPES
}
def
get_file_documents
(
config
:
FileLoaderConfig
):
from
llama_index.core.readers
import
SimpleDirectoryReader
try
:
reader
=
SimpleDirectoryReader
(
config
.
data_dir
,
recursive
=
True
,
filename_as_id
=
True
,
raise_on_error
=
True
)
file_extractor
=
None
if
config
.
use_llama_parse
:
# LlamaParse is async first,
# so we need to use nest_asyncio to run it in sync mode
...
...
@@ -46,8 +52,14 @@ def get_file_documents(config: FileLoaderConfig):
nest_asyncio
.
apply
()
parser
=
llama_parse_parser
()
reader
.
file_extractor
=
{
"
.pdf
"
:
parser
}
file_extractor
=
llama_parse_extractor
()
reader
=
SimpleDirectoryReader
(
config
.
data_dir
,
recursive
=
True
,
filename_as_id
=
True
,
raise_on_error
=
True
,
file_extractor
=
file_extractor
,
)
return
reader
.
load_data
()
except
Exception
as
e
:
import
sys
,
traceback
...
...
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