Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/change default split page behavior to true #118

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

awalker4
Copy link
Collaborator

@awalker4 awalker4 commented Jun 17, 2024

  • Set the split_pdf_page default to true and run make client-generate locally.
  • Update the readme, add another reference back to our docs
  • Change some warning logs to info. The user should not be warned about default behavior for non pdf files

Testing

Use the client locally and verify that split mode is the default, and that the client behavior is consistent with older versions.

  • Set up (or activate) your pyenv for the client: pyenv virtualenv 3.12 unstructured-client; pyenv activate unstructured-client
  • Check out this branch and install: pip install -e .
  • Run this sample script in the top level of the client repo. Try different files in _sample_docs and verify that the logging and results look acceptable.
from unstructured_client import UnstructuredClient
from unstructured_client.models import shared, operations

import json

api_key = "free-api-key"
filename = "_sample_docs/layout-parser-paper.pdf"

s = UnstructuredClient(
    api_key_auth=api_key,
)

with open(filename, "rb") as f:
    files=shared.Files(
        content=f.read(),
        file_name=filename,
    )

req = operations.PartitionRequest(
    shared.PartitionParameters(
        files=files,
        strategy=shared.Strategy.AUTO
    ),
)

try:
    resp = s.general.partition(req)
    print(json.dumps(resp.elements, indent=4))
except Exception as e:
    print(e)

* Set the split_pdf_page default to true
* Update the readme, add another reference back to our docs
* Change some warning logs to info. The user should not be warned about default behavior for non pdf files
Copy link

@Klaijan Klaijan left a comment

Choose a reason for hiding this comment

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

Tested with non-pdf files, logging shows INFO then print out output elements
e.g.

INFO: Preparing to split document for partition.
INFO: Given file doesn't have '.pdf' extension, so splitting is not enabled.
INFO: Partitioning without split.
INFO: Successfully partitioned the document.
[
    {
        "type": "Title",
        "element_id": "7366bfb62015d7f749e8c38e7284a60c",
        "text": "Lorem ipsum dolor sit amet.",
        "metadata": {
            "category_depth": 0,
            "filename": "fake.doc",
            "languages": [
                "por",
                "cat"
            ],
            "filetype": "application/msword"
        }
    }
]

@awalker4 awalker4 merged commit eabf116 into main Jun 17, 2024
7 checks passed
@awalker4 awalker4 deleted the chore/splitting-default branch June 17, 2024 20:50
awalker4 added a commit to Unstructured-IO/unstructured-js-client that referenced this pull request Jun 17, 2024
Mirror of
Unstructured-IO/unstructured-python-client#118
* Set the split_pdf_page default to true and run `make client-generate`
locally.
* Update the readme, add another reference back to our docs, bring back
some autogenerated sections like in the python repo
* Change some warning logs to info. The user should not be warned about
default behavior for non pdf files

# Testing
Use the client locally and verify that split mode is the default, and
that the dev experience is good

* Create a new test dir and run `npm init -y; npm install typescript
tsx`
* Check out this branch and install from your test dir: `npm i
file:~/repos/unstructured-js-client`
* Run this sample script. Try some different files in and verify that
the logging and results look acceptable.

`npx tsx unstructured.ts`


```
import { UnstructuredClient } from "unstructured-client";
import { PartitionResponse } from "unstructured-client/sdk/models/operations";
import { Strategy } from "unstructured-client/sdk/models/shared";
import * as fs from "fs";

const key = "free-api-key";

const client = new UnstructuredClient({
    security: {
        apiKeyAuth: key,
    },
});

const filename = "fake-html.html";
const data = fs.readFileSync(filename);

client.general.partition({
    partitionParameters: {
        files: {
            content: data,
            fileName: filename,
        },
        strategy: Strategy.Auto,
    }
}).then((res: PartitionResponse) => {
    if (res.statusCode == 200) {
        console.log(res.elements);
    }
}).catch((e) => {
    if (e.statusCode) {
      console.log(e.statusCode);
      console.log(e.body);
    } else {
      console.log(e);
    }
});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants