In today’s era of AI and machine learning, extracting valuable data from language models (LLMs) can be quite an investment. However, with the right approach, it’s entirely possible to efficiently and affordably extract JSON outputs from LLMs. In this guide, we will discuss how to achieve this using the relatively budget-friendly gpt-4o-mini
model, which offers robust functionality at a lower cost. Additionally, we’ll explore the utilization of function calling designed to retrieve JSON outputs seamlessly.
To extract JSON output effectively, you need a language model that supports function calling. In our guide, we will use the gpt-4o-mini
model due to its cost-efficiency and adequate performance. Let’s break down the steps required:
First, we need to configure our model. Here’s the setup:
{
"model": "gpt-4o-mini",
"temperature": 0,
"messages": [
{
"role": "user",
"content": "Send a mail to [email protected] with subject: I want a demo"
}
],
"tool_choice": {
"type": "function",
"function": {
"name": "json"
}
},
"tools": [
{
"type": "function",
"function": {
"name": "json",
"description": "Respond with a JSON object.",
"parameters": {
"type": "object",
"properties": {
"ticker": {
"type": "string",
"description": "Email of whom to send to"
},
"subject": {
"type": "string",
"description": "Subject of the email"
}
},
"required": [
"email",
"subject"
],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#"
}
}
}
]
}
The tool_choice
field is crucial as it defines the function to be used. In this case, we use a JSON function to handle the email and subject extraction. Here’s an example API call response:
{
"id": "chatcmpl-9pAj2ulHR52ti2mBEJmjgNFKVHjjH",
"object": "chat.completion",
"created": 1721982984,
"model": "gpt-4o-mini-2024-07-18",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_tDRmy7uCVveKgfCKi6TVAmS0",
"type": "function",
"function": {
"name": "json",
"arguments": "{\"ticker\":\"[email protected]\",\"subject\":\"I want a demo\"}"
}
}
]
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 83,
"completion_tokens": 16,
"total_tokens": 99
},
"system_fingerprint": "fp_661538dc1f"
}
gpt-4o-mini
gpt-4o-mini
model is budget-friendly, making it an excellent choice for projects requiring frequent model interactions without breaking the bank.To implement JSON extraction using the gpt-4o-mini
model, follow these steps:
Extracting JSON output from language models doesn’t have to be expensive. By leveraging the gpt-4o-mini
model, you can achieve cost-effective, efficient data extraction. This guide provides a step-by-step strategy to optimize your processes and maintain a tight budget.
By understanding the setup and function calling as described, you can effortlessly handle complex tasks without incurring high costs. Happy extracting!
Come talk to us at Franz. We can help you unlock the full potential of your data, transforming your processes and boosting efficiency. Let’s revolutionize your document processing together! Reach out to us at [email protected] to get started on your journey to a more efficient and innovative future.