Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Using GPT4 to give a point score from PDF document
Post Flair (click to view more posts with a particular flair)
Post Body

Xpost from r/chatgpt

I am a GPT4 user and I am trying to build out a GPT that will extract specific information from a large PDF file (25 pages) and then use that information to calculate a score.

For example, I want GPT4 to search for total hours worked, which is a clearly designated field, and assign 0 points for no hours worked and up to 10 points for 2,000 hours worked at any job.

There are multiple fields I want to score like this, and they are almost all uniquely and discretely defined units. The problem is after providing a very specific rubric to use, half the time the GPT model doesn’t even access it for use, and the other half of the time it just totally misses items. It is also terrible about assigning points when there is a range of values (e.g., it gave 4 points for 495 hours worked when the rubric clearly says give 3 points for hours worked between 250 and 500 hours).

Any thoughts on how to make this better? I’ve tried messing with Python code, but it doesn’t seem to use it when placed in the “knowledge” of the GPT model.

Thanks!

Comments
[not loaded or deleted]

Good to hear you are open to trying Python for this! Sometimes you need the right tool for the job. ChatGPT is very capable, but it is just not robust enough for more complex tasks like this.

While you can technically run a restricted version of Python from within ChatGPT, it cannot make API requests, install new packages, etc. For this reason I would highly recommend installing Python on your computer and running it yourself.

I made an example PDF that looks like this one, here is the Python script you can use:

# extract the content from the PDF into a prompt
from thepipe_api import thepipe
prompt = thepipe.extract("doc.pdf")

# Add your instructions to the prompt
prompt  = [{"role": "user", "content": "Using the given document, output the total number of hours worked by the employee. Return your response in valid JSON format with the key 'hours_worked'."}]

# send the prompt to GPT-4 
from openai import OpenAI
openai_client = OpenAI()
response = openai_client.chat.completions.create(
    model = "gpt-4-turbo",
    messages = prompt,
    response_format = {"type": "json_object"}
)

# GPT-4 will return JSON formatted text, since we asked it to. 
# Now, let's extract the hours worked.
import json
response = response.choices[0].message.content
hours_worked = json.loads(response)['hours_worked']

# Define a Function to calculate score based on hours worked
def calculate_score(hours):
    if hours == 0:
        return 0
    elif hours <= 2000:
        return (hours / 2000) * 10
    else:
        return 10

# Run the function on the hours worked we extracted earlier
score = calculate_score(hours_worked)
print(score)

For that PDF, the code outputs

Total score: 7.0

To get it working, you'll need the OpenAI API for GPT4 and The Pipe API for PDF extraction. I should mention that both APIs, like ChatGPT Pro, are paid.

Good luck!

Why not use Python to do this step by step with the GPT4 API?

Author
Account Strength
100%
Account Age
14 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,958
Link Karma
602
Comment Karma
9,239
Profile updated: 5 days ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 months ago