Skip to content

Instantly share code, notes, and snippets.

@heathermiller
Created January 11, 2024 17:58
Show Gist options
  • Save heathermiller/e77021e9acd65b23f961ca1379298189 to your computer and use it in GitHub Desktop.
Save heathermiller/e77021e9acd65b23f961ca1379298189 to your computer and use it in GitHub Desktop.
LMQL
@lmql.query
def meaning_of_life():
'''lmql
# top-level strings are prompts
"Q: What is the answer to life, the \
universe and everything?"
# generation via (constrained) variables
"A: [ANSWER]" where \
len(ANSWER) < 120 and STOPS_AT(ANSWER, ".")
# results are directly accessible
print("LLM returned", ANSWER)
# use typed variables for guaranteed
# output format
"The answer is [NUM: int]"
# query programs are just functions
return NUM
'''
# so from Python, you can just do this
meaning_of_life() # 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment