Skip to content

Instantly share code, notes, and snippets.

@a10y
Last active August 2, 2023 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a10y/d926039eee63cc2bcaf6345f9a419e3b to your computer and use it in GitHub Desktop.
Save a10y/d926039eee63cc2bcaf6345f9a419e3b to your computer and use it in GitHub Desktop.
Example prompt using the new grammar-guided generation functionality from llama.cpp
SYSTEM: Transcript of conversation between HUMAN and ASSISTANT. ASSISTANT can respond to USER with structured JSON messages.
USER: Extract information from an email as a JSON object matching the following TypeScript interface
```typescript
interface DeliveryInformation {
/* Tracking number for the delivery */
tracking_number: string;
/* Status of the delivery, one of "preparing", "out-for-delivery", or "delivered" */
status: string;
/* Weight of the package, e.g. "2oz" or "3lb" */
weight: string;
/* submission date time representation */
submitted_ts: string;
}
```
The text of the email enclosed in markdown backticks is
```
Hello, we'd like to inform you that your package has shipped. Below is the tracking information:
Tracking: 1Z9933457822LKL
Ship To: Omaha, NE
Net Wt: 1lb 3oz
Submitted at: August 1st, 2023 8:08PM EST
Status: Out for Delivery
We thank you for using USPS for all of your shipping needs. If you have any questions about your delivery, please contact your nearest USPS Post Office at
2109 31 ST NW
Washington, DC 20007
Hours:
M: 9am-4:30pm
T: 9am-4:30pm
W: 9am-4:30pm
Th: 9am-4:30pm
F: 9am-4:30pm
Sat: 10am-4pm
Sun: Closed
Phone (800) USMAIL-999
```
ASSISTANT:
root ::= DeliveryInformation
DeliveryInformation ::= "{" ws "\"tracking_number\":" ws string "," ws "\"status\":" ws string "," ws "\"weight\":" ws string "," ws "\"weight_oz\":" ws number "," ws "\"submitted_ts\":" ws string "}"
string ::= "\"" ([^"]*) "\""
ws ::= [ \t\n]*
number ::= [0-9]+ "."? [0-9]*
stringlist ::= "[" ws "]" | "[" ws string ("," ws string)* ws "]"
numberlist ::= "[" ws "]" | "[" ws string ("," ws number)* ws "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment