You can use the get_result_type method of the Undatasio object to retrieve text information, images, tables, titles, or interline equation information from a PDF file.
This notebook will select the table in the first Financial Summary of tsla-20241023-gen.pdf as the sample content, as shown in the figure above.
Initialize the OpenAI object. You need to apply for an API key yourself.
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("API_KEY"),
base_url="https://api.deepseek.com"
)
Use deepseek-chat model and set the system and user prompts.
Question 1: What new features were included in the Summer Release of Tesla's vehicle software?
We ask a question over the parsed markdown and get back the right answer! We also ask a question over the text.
query1 = "What new features were included in the Summer Release of Tesla's vehicle software?"
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a data analysis expert. Please extract information from the data provided by the user. Note that only the information asked by the user should be returned, and nothing else should be returned. Data: %s" % (result.data, )},
{"role": "user", "content": query1},
],
stream=False
)
"The new features included in the Summer Release of Tesla's vehicle software are:\n- YouTube and Amazon Music as native apps.\n- Parental Controls via PIN to apply maximum speed limit, reduce acceleration to Chill, force-enable safety settings, and enable curfew notifications.\n- Hands-Free Frunk.\n- Revamped climate controls for Model 3 and Model Y.\n- Weather forecast and air quality improvements in-vehicle navigation."
show the result above:
The new features included in the Summer Release of Tesla's vehicle software are:
YouTube and Amazon Music as native apps.
Parental Controls via PIN to apply maximum speed limit, reduce acceleration to Chill, force-enable safety settings, and enable curfew notifications.
Hands-Free Frunk.
Revamped climate controls for Model 3 and Model Y.
Weather forecast and air quality improvements in-vehicle navigation.
Question 2: How did the Energy business perform in Q3 in terms of gross margin?
Let's also try asking a question over another piece of the text.
query2 = 'How did the Energy business perform in Q3 in terms of gross margin?'
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a data analysis expert. Please extract information from the data provided by the user. Note that only the information asked by the user should be returned, and nothing else should be returned. Data: %s" % (result.data, )},
{"role": "user", "content": query2},
],
stream=False
)
'The Energy business achieved a record gross margin of 30.5% in Q3, a sequential increase of 596 basis points.'
This is a code recipe that harnesses the power of the platform and the advanced to unlock crucial insights from the Tesla Gen report.
Pinpoint key data: This notebook zeroes in on the table within the first Financial Summary of as our prime sample content. As illustrated in the figures accompanying this recipe, this data will serve as the foundation for our in-depth exploration, holding valuable financial and operational details about Tesla's business.
An procured from the official Undatas.io platform. This key unlocks the platform's full suite of data extraction and manipulation features.
An obtained following OpenAI's official process. Ensure you've completed all necessary registration and verification steps to gain access to the deepseek model via OpenAI's infrastructure.