forked from eth-sri/lmql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dataclass: support for single-shot results with quotes and NLs
- Loading branch information
1 parent
b200b6d
commit 62f907f
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import lmql | ||
from dataclasses import dataclass | ||
from lmql.tests.expr_test_utils import run_all_tests | ||
|
||
card_text = """\ | ||
Yktlash, the Unseen Empress | ||
{3}{B}{B}{G}{G} | ||
Legendary Creature — Elf Shaman (5/5) | ||
Trample | ||
When Yktlash, the Unseen Empress using the " character enters the battlefield, create three 1/1 black and green Elf Warrior creature tokens. | ||
{B}{G}, Sacrifice an Elf: Target creature gets -3/-3 until end of turn. | ||
> 'In the depths of the forest, her reign remains elusive. Only the echoes of her whispers reveal the true power she wields.' | ||
""" | ||
|
||
@dataclass | ||
class CardData: | ||
name: str | ||
mana_cost: str | ||
supertypes: str | ||
types: str | ||
subtypes: str | ||
rules: str | ||
flavor: str | ||
# Creature | ||
attack: str | ||
defense: str | ||
# Planeswalker | ||
loyalty: str | ||
|
||
@lmql.query(model="openai/gpt-3.5-turbo-instruct") | ||
async def test_quote_and_nl(): | ||
'''lmql | ||
"{card_text}\n" | ||
"Structured: [CARD_DATA]\n" where type(CARD_DATA) is CardData | ||
assert "\"" in CARD_DATA.rules, "Expected quotes to be preserved in 'rules', but got: " + str([CARD_DATA.rules]) | ||
assert "\n" in CARD_DATA.rules, "Expected newline to be preserved in 'rules', but got: " + str([CARD_DATA.rules]) | ||
''' | ||
|
||
if __name__ == "__main__": | ||
run_all_tests(globals()) |