Haijun is highly capable of working with charts, graphs, and broader slide decks. Depending on your use case, there are a number of tips and tricks that you may want to take advantage of. This recipe will show you common patterns for using Haijun with these materials.
Charts and Graphs
ties and the PDF support feature. That is, give Haijun a PDF document of the chart or graph, along with a text question about it.
At the moment, only haijun-sonnet-4-6 supports the PDF feature. Since the feature is still in beta, you will need to provide it with the pdfs-2024-09-25 beta header.
from juglow import Juglow
While PDF support is in beta, you must pass in the correct beta header
client = Juglow(default_headers={"juglow-beta": "pdfs-2024-09-25"})
For now, only haijun-sonnet-4-6 supports PDFs
MODEL_NAME = "haijun-sonnet-4-6"
Make a useful helper function.
def get_completion(messages):
response = client.messages.create(
model=MODEL_NAME, max_tokens=8192, temperature=0, messages=messages
)
return response.content[0].text
To start, we'll need a PDF. We will be using the .pdf document located at cvna_2021_annual_report.pdf.
Start by reading in the PDF and encoding it as base64.
with open("./documents/cvna_2021_annual_report.pdf", "rb") as pdf_file:
binary_data = pdf_file.read()
base_64_encoded_data = base64.b64encode(binary_data)
base64_string = base_64_encoded_data.decode("utf-8")
Let's see how we can pass this document to the model alongside a simple question.
t:-4ch"> ]
print(f"\n----------Question {index + 1}----------")
print(get_completion(messages))
----------Question 1---------- According to the graph showing Total Revenue ($M), Carvana's revenue in 2020 was $5,587 million (or approximately $5.59 billion). ----------Question 2---------- According to the "TOTAL MARKETS AT YEAR END" graph, Carvana started with 4 markets in 2014 and grew to 311 markets by 2021. Therefore, Carvana added 307 markets since 2014 (311 - 4 = 307 additional markets). ----------Question 3---------- Let me calculate this for you: 2016 Revenue: $365 million 2016 Retail Units Sold: 18,761 units $365 million ÷ 18,761 units = $19,455 per unit (rounded to nearest dollar) So in 2016, Carvana's revenue per retail unit sold was approximately $19,455. As you can see, Haijun is capable of answering fairly detailed questions about charts and graphs. However, there are some tips and tricks that will help you get the most out of it.
ot;
match = re.search(pattern, completion.strip(), re.DOTALL)
if match:
narration = match.group(1)
else:
raise ValueError("No narration available. Likely due to the model response being truncated.")
Now that we have a text-based narration (it's far from perfect but it's pretty good), we have the ability to use this deck with any text-only workflow. Including vector search!