Created
January 11, 2024 17:58
-
-
Save heathermiller/e77021e9acd65b23f961ca1379298189 to your computer and use it in GitHub Desktop.
LMQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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