0
0
Prompt Engineering / GenAIml~10 mins

Document loaders in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a text document using a document loader.

Prompt Engineering / GenAI
loader = TextLoader('[1]')
documents = loader.load()
Drag options to blanks, or click blank then click option'
Aexample.txt
Bload_text
Cread_file
Ddocument
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name instead of a file path.
Forgetting to put the file name in quotes.
2fill in blank
medium

Complete the code to load a PDF document using the PDFLoader.

Prompt Engineering / GenAI
loader = PDFLoader('[1]')
docs = loader.load()
Drag options to blanks, or click blank then click option'
Aimage.png
Bdocument.docx
Cnotes.txt
Dfile.pdf
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-PDF file with PDFLoader.
Providing a file with the wrong extension.
3fill in blank
hard

Fix the error in the code to load a CSV file using CSVLoader.

Prompt Engineering / GenAI
loader = CSVLoader(file_path='[1]')
data = loader.load()
Drag options to blanks, or click blank then click option'
Adata.txt
Bdata.pdf
Cdata.csv
Ddata.docx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-CSV file with CSVLoader.
Incorrect file extension causing loading failure.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that loads documents only if their length is greater than 100.

Prompt Engineering / GenAI
filtered_docs = {doc.id: doc for doc in documents if len(doc.[1]) [2] 100}
Drag options to blanks, or click blank then click option'
Apage_content
Bmetadata
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'metadata' instead of 'page_content' for length.
Using '<' instead of '>' causing wrong filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps document titles to their content if the content length is less than 500.

Prompt Engineering / GenAI
doc_map = {doc.[1]: doc.[2] for doc in docs if len(doc.[3]) < 500}
Drag options to blanks, or click blank then click option'
Ametadata['title']
Bpage_content
Dmetadata['author']
Attempts:
3 left
💡 Hint
Common Mistakes
Using author instead of title for keys.
Mixing up content and metadata in length check.