Skip to content

Commit

Permalink
Remove total quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
thoqbk committed Jan 29, 2023
1 parent f99c256 commit 58886ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,25 @@ Once the PDF has been converted to text, the next step is to call the OpenAI API
The query is as simple as follows with %s replaced by PO text content:
```java
private static final String QUERY = """
Want to extract fields: "PO Number", "Total Amount", "Total Quantity" and "Delivery Address".
Want to extract fields: "PO Number", "Total Amount" and "Delivery Address".
Return result in JSON format without any explanation.
The PO content is as follows:
%s
""";
```

Sample results from OpenAI:
The query consists of two components:
- specifying the desired fields
- formatting the field values as JSON data for easy retrieval from API response.

And here is the example response from OpenAI:
```js
{
"object": "text_completion",
"model": "text-davinci-003",
"choices": [
{
"text": "\\n{\\n \\"PO Number\\": \\"PO-003847945\\",\\n \\"Total Amount\\": \\"1,485.00\\",\\n \\"Total Quantity\\": \\"100.00\\",\\n \\"Delivery Address\\": \\"Peera Consumer Good Co.(QSC), P.O.Box 3371, Dohe, QAT\\"\\n}",
"text": "\\n{\\n \\"PO Number\\": \\"PO-003847945\\",\\n \\"Total Amount\\": \\"1,485.00\\",\\n \\"Delivery Address\\": \\"Peera Consumer Good Co.(QSC), P.O.Box 3371, Dohe, QAT\\"\\n}",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
Expand All @@ -87,6 +91,15 @@ Sample results from OpenAI:
}
```

Decoding the `text` field's JSON string yields the following desired fields:
```js
{
"PO Number": "PO-003847945",
"Total Amount": "1,485.00",
"Delivery Address": "Peera Consumer Good Co.(QSC), P.O.Box 3371, Dohe, QAT"
}
```

## Run sample code
Prerequisites:
- Java 16+
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/thoqbk/openaipdf/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class Main {
private static final String SAMPLE_PDF_FILE = "io/thoqbk/openaipdf/sample-invoice.pdf";
private static final String OPENAI_API_URL = "https://api.openai.com/v1/completions";
private static final String QUERY = """
Want to extract fields: "PO Number", "Total Amount", "Total Quantity" and "Delivery Address".
Return result in JSON format without any explanation.
Want to extract fields: "PO Number", "Total Amount" and "Delivery Address".
Return result in JSON format without any explanation.
The PO content is as follows:
%s
""";
Expand Down

0 comments on commit 58886ed

Please sign in to comment.