Step 1: Prompt-only JSON extraction (baseline)
The naive approach
The easiest way to get structured data out of an LLM is to ask for JSON in the prompt. It mostly works — but mostly isn't good enough for production, and you'll quantify why in step 4.
The task
Extract structured contact info from a free-text message. Given an email like:
"Hi, this is Jane Chen from Acme Corp. My email is [email protected] and my phone is +1-415-555-2036. Thanks!"
Return:
{"name": "Jane Chen", "company": "Acme Corp", "email": "[email protected]", "phone": "+1-415-555-2036"}
Your task
Add to main.py:
- Create a NIM client.
- Define
extract_via_prompt(text: str) -> dictthat asksmeta/llama-3.3-70b-instructfor a JSON object with keysname,company,email,phone. - Parse the response with regex +
json.loads. Return{}if parsing fails. - Call it on a sample message and print the result.
main.py, the file you edit13 lines
from openai import OpenAI
import json, re
client = OpenAI(base_url="http://nim-proxy.labs.svc:8080/v1", api_key="nvapi-inject")
MODEL = "meta/llama-3.3-70b-instruct"
SAMPLE = "Hi, this is Jane Chen from Acme Corp. My email is [email protected] and my phone is +1-415-555-2036. Thanks!"
# TODO: extract_via_prompt(text) -> dict with keys name, company, email, phone
def extract_via_prompt(text: str) -> dict:
______
print(extract_via_prompt(SAMPLE))