Christine Straub 0eb461acc2
refactor: restructure PDF/Image example document organization (#3410)
This PR aims to improve the organization and readability of our example
documents used in unit tests, specifically focusing on PDF and image
files.

### Summary
- Created two new subdirectories in the `example-docs` folder:
  - `pdf/`: for all PDF example files
  - `img/`: for all image example files
- Moved relevant PDF files from `example-docs/` to `example-docs/pdf/`
- Moved relevant image files from `example-docs/` to `example-docs/img/`
- Updated file paths in affected unit & ingest tests to reflect the new
directory structure

### Testing
All unit & ingest tests should be updated and verified to work with the
new file structure.

## Notes
Other file types (e.g., office documents, HTML files) remain in the root
of `example-docs/` for now.

## Next Steps
Consider similar reorganization for other file types if this structure
proves to be beneficial.

---------

Co-authored-by: ryannikolaidis <1208590+ryannikolaidis@users.noreply.github.com>
Co-authored-by: christinestraub <christinestraub@users.noreply.github.com>
2024-07-18 22:21:32 +00:00

67 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
DEST_PATH=$(dirname "$(realpath "$0")")
SCRIPT_DIR=$(dirname "$DEST_PATH")
cd "$SCRIPT_DIR"/.. || exit 1
OUTPUT_FOLDER_NAME=local-kafka-dest
OUTPUT_DIR=$SCRIPT_DIR/structured-output/$OUTPUT_FOLDER_NAME
WORK_DIR=$SCRIPT_DIR/workdir/$OUTPUT_FOLDER_NAME
max_processes=${MAX_PROCESSES:=$(python3 -c "import os; print(os.cpu_count())")}
RANDOM_SUFFIX=$((RANDOM % 100000 + 1))
LC_ALL=C
# Set the variables with default values if they're not set in the environment
KAFKA_TOPIC=${KAFKA_TOPIC:-"ingest-test-$RANDOM_SUFFIX"}
# shellcheck disable=SC1091
source "$SCRIPT_DIR"/cleanup.sh
function cleanup {
# Local file cleanup
cleanup_dir "$WORK_DIR"
cleanup_dir "$OUTPUT_DIR"
echo "Stopping local Kafka instance"
docker-compose -f scripts/kafka-test-helpers/docker-compose.yml down --remove-orphans -v
}
trap cleanup EXIT
echo "Creating local Kafka instance"
# shellcheck source=/dev/null
scripts/kafka-test-helpers/create-kafka-instance.sh
wait
PYTHONPATH=. ./unstructured/ingest/main.py \
local \
--num-processes "$max_processes" \
--output-dir "$OUTPUT_DIR" \
--strategy fast \
--verbose \
--reprocess \
--input-path example-docs/pdf/layout-parser-paper.pdf \
--work-dir "$WORK_DIR" \
--chunking-strategy basic \
--chunk-combine-text-under-n-chars 200 \
--chunk-new-after-n-chars 2500 \
--chunk-max-characters 38000 \
--chunk-multipage-sections \
--embedding-provider "langchain-huggingface" \
kafka \
--topic "$KAFKA_TOPIC" \
--bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
--port 29092 \
--confluent false
echo "Checking for matching messages in Kafka"
#Check the number of messages in destination topic
python "$SCRIPT_DIR"/python/test-kafka-output.py check \
--bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
--topic "$KAFKA_TOPIC" \
--confluent false \
--port 29092