Skip to content
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
33 changes: 21 additions & 12 deletions transform/sample-code/extract-quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,43 @@
from unstructured_client.models.operations import CreateJobRequest, DownloadJobOutputRequest
from unstructured_client.models.shared import BodyCreateJob, InputFiles

# ----------------------------------------------------------------------------------
# SET THE VARIABLES BELOW as they apply to you.
# ----------------------------------------------------------------------------------
# API_KEY is included here as a local variable for ease of use in this quickstart.
# This isn't best practice outside of local testing on your own machine. Once
# you've added your real key, don't share this file or check it into any
# repositories.
API_KEY = "YOUR_API_KEY_HERE"
# The local directory containing the file (or files) you want to process.
# This folder should contain only the file(s) you want to process, since the
# script processes every file it finds here.
INPUT_DIR = "/full/path/to/your/input/directory"
# The local directory where you want the results saved.
# Use a different folder than INPUT_DIR, or on a second run the script will
# also try to process the JSON files already saved here.
OUTPUT_DIR = "/full/path/to/your/output/directory"
# ----------------------------------------------------------------------------------

# Set the variables below this validation function before running this script.
# Validate the variable settings
def validate_inputs(api_key, input_dir, output_dir):
# Checks that the settings below have been changed from their placeholder values.
if api_key in ("YOUR_API_KEY_HERE", ""):
raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
if input_dir in ("/full/path/to/your/input/directory", ""):
raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.")
if output_dir in ("/full/path/to/your/output/directory", ""):
raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.")
Comment on lines 30 to 35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The validation comparisons no longer identify their literals as non-editable, so readers can mistake these guard values for the settings they should change. Restore # <-- DO NOT UPDATE on each validation check to preserve the promised placeholder-editing guidance.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At transform/sample-code/extract-quickstart.py, line 30:

<comment>The validation comparisons no longer identify their literals as non-editable, so readers can mistake these guard values for the settings they should change. Restore `# <-- DO NOT UPDATE` on each validation check to preserve the promised placeholder-editing guidance.</comment>

<file context>
@@ -39,13 +23,26 @@ def validate_inputs(api_key, input_dir, output_dir):
+
+# Validate the variable settings
+def validate_inputs(api_key, input_dir, output_dir):
+    if api_key in ("YOUR_API_KEY_HERE", ""):
+        raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
+    if input_dir in ("/full/path/to/your/input/directory", ""):
</file context>
Suggested change
if api_key in ("YOUR_API_KEY_HERE", ""):
raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
if input_dir in ("/full/path/to/your/input/directory", ""):
raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.")
if output_dir in ("/full/path/to/your/output/directory", ""):
raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.")
if api_key in ("YOUR_API_KEY_HERE", ""): # <-- DO NOT UPDATE
raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
if input_dir in ("/full/path/to/your/input/directory", ""): # <-- DO NOT UPDATE
raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.")
if output_dir in ("/full/path/to/your/output/directory", ""): # <-- DO NOT UPDATE
raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.")



# API_KEY is included here as a local variable for ease of use in this quickstart.
# This isn't best practice outside of local testing on your own machine. Once
# you've added your real key, don't share this file or check it into any
# repositories.
API_KEY = "YOUR_API_KEY_HERE"
# API_URL is already preset for you. Do not change the value.
API_URL = "https://platform-api.transform.unstructured.io/api/v1"
# The local directory containing the file (or files) you want to process.
INPUT_DIR = "/full/path/to/your/input/directory"
# The local directory where you want the results saved.
OUTPUT_DIR = "/full/path/to/your/output/directory"

# EXTRACTION_PROMPT is already preset for you.
# EXTRACTION_PROMPT tells the LLM how to format, normalize, or present the values your
# schema already defines. It doesn't describe which fields to extract. The schema
# further down in this script does that.
EXTRACTION_PROMPT = "Dates are in MM/DD/YYYY format on the form. Represent them as YYYY-MM-DD. Combine the home address, city, state, and ZIP code fields into a single address string."


validate_inputs(API_KEY, INPUT_DIR, OUTPUT_DIR)

client = UnstructuredClient(
Expand Down
31 changes: 19 additions & 12 deletions transform/sample-code/partition-quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@
from unstructured_client.models.operations import CreateJobRequest, DownloadJobOutputRequest
from unstructured_client.models.shared import BodyCreateJob, InputFiles

# ----------------------------------------------------------------------------------
# SET THE VARIABLES BELOW as they apply to you.
# ----------------------------------------------------------------------------------
# API_KEY is included here as a local variable for ease of use in this quickstart.
# This isn't best practice outside of local testing on your own machine. Once
# you've added your real key, don't share this file or check it into any
# repositories.
API_KEY = "YOUR_API_KEY_HERE"
# The local directory containing the file (or files) you want to process.
# This folder should contain only the file(s) you want to process, since the
# script processes every file it finds here.
INPUT_DIR = "/full/path/to/your/input/directory"
# The local directory where you want the results saved.
# Use a different folder than INPUT_DIR, or on a second run the script will
# also try to process the JSON files already saved here.
OUTPUT_DIR = "/full/path/to/your/output/directory"
# ----------------------------------------------------------------------------------

# Set the variables below this validation function before running this script.
# Validate the variable settings
def validate_inputs(api_key, input_dir, output_dir):
# Checks that the settings below have been changed from their placeholder values.
if api_key in ("YOUR_API_KEY_HERE", ""):
raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
if input_dir in ("/full/path/to/your/input/directory", ""):
raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.")
if output_dir in ("/full/path/to/your/output/directory", ""):
raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.")
Comment on lines 30 to 35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The validation checks still contain the same placeholder strings as the editable settings, but removing their DO NOT UPDATE markers reintroduces the ambiguity this change is meant to resolve. Keep the marker on each validation check.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At transform/sample-code/partition-quickstart.py, line 30:

<comment>The validation checks still contain the same placeholder strings as the editable settings, but removing their `DO NOT UPDATE` markers reintroduces the ambiguity this change is meant to resolve. Keep the marker on each validation check.</comment>

<file context>
@@ -41,6 +25,18 @@ def validate_inputs(api_key, input_dir, output_dir):
 
+# Validate the variable settings
+def validate_inputs(api_key, input_dir, output_dir):
+    if api_key in ("YOUR_API_KEY_HERE", ""):
+        raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
+    if input_dir in ("/full/path/to/your/input/directory", ""):
</file context>
Suggested change
if api_key in ("YOUR_API_KEY_HERE", ""):
raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
if input_dir in ("/full/path/to/your/input/directory", ""):
raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.")
if output_dir in ("/full/path/to/your/output/directory", ""):
raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.")
if api_key in ("YOUR_API_KEY_HERE", ""): # <-- DO NOT UPDATE
raise SystemExit("Set API_KEY to your Unstructured API key before running this script.")
if input_dir in ("/full/path/to/your/input/directory", ""): # <-- DO NOT UPDATE
raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.")
if output_dir in ("/full/path/to/your/output/directory", ""): # <-- DO NOT UPDATE
raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.")



# API_KEY is included here as a local variable for ease of use in this quickstart.
# This isn't best practice outside of local testing on your own machine. Once
# you've added your real key, don't share this file or check it into any
# repositories.
API_KEY = "YOUR_API_KEY_HERE"
# API_URL is already preset for you. Do not change the value.
API_URL = "https://platform-api.transform.unstructured.io/api/v1"
# The local directory containing the file (or files) you want to process.
INPUT_DIR = "/full/path/to/your/input/directory"
# The local directory where you want the results saved.
OUTPUT_DIR = "/full/path/to/your/output/directory"

validate_inputs(API_KEY, INPUT_DIR, OUTPUT_DIR)

Expand Down
Loading