Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update examples #136

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ From string
from genai.prompt_pattern import PromptPattern

_string = """
The capital of {{country}} is {{capital}}. The capital of Taiwan is
The capital of {{country}} is {{capital}}. The capital of United Kingdom is
"""

prompt = PromptPattern.from_str(_string)
prompt.sub("country", "Spain").sub("capital", "Madrid")

# The capital of Spain is Madrid. The capital of Taiwan is
# The capital of Spain is Madrid. The capital of United Kingdom is


From file
Expand Down
2 changes: 1 addition & 1 deletion examples/user/prompt-raw-string.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
model = Model("google/flan-ul2", params=params, credentials=creds)

# can live locally or at an url endpoint
pt = PromptPattern.from_str("The capital of {{country}} is {{capital}}. The capital of Taiwan is")
pt = PromptPattern.from_str("The capital of {{country}} is {{capital}}. The capital of United Kingdom is")
pt.sub("capital", "Madrid").sub("country", "Spain")

print(pt)
Expand Down
2 changes: 1 addition & 1 deletion tests/assets/capital-qa-sub.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Country: Germany
Capital: Berlin
Country: USA
Capital: Washington
Country: Taiwan
Country: United Kingdom
Capital:
5 changes: 3 additions & 2 deletions tests/test_prompt_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ def test_sub(self):

def test_sub_string_template(self):
pt = PromptPattern.from_file(self.asset_path + "capital-qa.yaml")
pt.sub("country", "Taiwan")
pt.sub("country", "United Kingdom")

expected = self.asset(name="capital-qa-sub.txt")
assert str(pt) == expected

def test_cache_reset(self):
pt = PromptPattern.from_file(self.asset_path + "capital-qa.yaml")
pt.sub("country", "Taiwan")
pt.sub("country", "United Kingdom")

expected = self.asset(name="capital-qa-sub.txt")
assert str(pt) == expected
assert str(pt) == expected

pt.reset()

Expand Down