-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22a431f
commit 5e9b2fa
Showing
3 changed files
with
141 additions
and
9 deletions.
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
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,127 @@ | ||
import uuid | ||
|
||
from opik import Prompt | ||
|
||
|
||
def test_prompt__create__happyflow(opik_client): | ||
unique_identifier = str(uuid.uuid4())[-6:] | ||
|
||
prompt_name = f"some-prompt-name-{unique_identifier}" | ||
prompt_template = f"some-prompt-text-{unique_identifier}" | ||
prompt_description = f"some-prompt-description-{unique_identifier}" | ||
|
||
prompt = opik_client.create_prompt( | ||
name=prompt_name, | ||
template=prompt_template, | ||
description=prompt_description, | ||
) | ||
|
||
assert prompt.name == prompt_name | ||
assert prompt.template == prompt_template | ||
assert prompt.description == prompt_description | ||
assert prompt.id is not None | ||
assert prompt.commit is not None | ||
|
||
|
||
def test_prompt__create_new_version__happyflow(opik_client): | ||
unique_identifier = str(uuid.uuid4())[-6:] | ||
|
||
prompt_name = f"some-prompt-name-{unique_identifier}" | ||
prompt_template = f"some-prompt-text-{unique_identifier}" | ||
prompt_description = f"some-prompt-description-{unique_identifier}" | ||
|
||
prompt = opik_client.create_prompt( | ||
name=prompt_name, | ||
template=prompt_template, | ||
description=prompt_description, | ||
) | ||
|
||
unique_identifier_new = str(uuid.uuid4())[-6:] | ||
prompt_template_new = f"some-prompt-text-{unique_identifier_new}" | ||
|
||
# must create new version | ||
new_prompt = opik_client.create_prompt( | ||
name=prompt_name, | ||
template=prompt_template_new, | ||
) | ||
|
||
assert new_prompt.name == prompt.name | ||
assert new_prompt.template == prompt_template_new | ||
assert new_prompt.description == prompt.description | ||
assert new_prompt.id == prompt.id | ||
assert new_prompt.commit != prompt.commit | ||
|
||
|
||
def test_prompt__get__happyflow(opik_client): | ||
unique_identifier = str(uuid.uuid4())[-6:] | ||
|
||
prompt_name = f"some-prompt-name-{unique_identifier}" | ||
prompt_template = f"some-prompt-text-{unique_identifier}" | ||
prompt_description = f"some-prompt-description-{unique_identifier}" | ||
|
||
prompt = opik_client.create_prompt( | ||
name=prompt_name, | ||
template=prompt_template, | ||
description=prompt_description, | ||
) | ||
|
||
unique_identifier_new = str(uuid.uuid4())[-6:] | ||
prompt_template_new = f"some-prompt-text-{unique_identifier_new}" | ||
|
||
# must create new version | ||
new_prompt = opik_client.create_prompt( | ||
name=prompt_name, | ||
template=prompt_template_new, | ||
) | ||
|
||
# ASSERTIONS | ||
p1 = opik_client.get_prompt(name=prompt.name) | ||
|
||
assert p1.name == new_prompt.name | ||
assert p1.template == new_prompt.template | ||
assert p1.description == new_prompt.description | ||
assert p1.id == new_prompt.id | ||
assert p1.commit == new_prompt.commit | ||
|
||
p2 = opik_client.get_prompt(name=prompt.name, commit=prompt.commit) | ||
|
||
assert p2.name == prompt.name | ||
assert p2.template == prompt.template | ||
assert p2.description == prompt.description | ||
assert p2.id == prompt.id | ||
assert p2.commit == prompt.commit | ||
|
||
|
||
def test_prompt__initialize_class_instance(opik_client): | ||
unique_identifier = str(uuid.uuid4())[-6:] | ||
template = "Hello, {name} from {place}! Nice to meet you, {name}." | ||
|
||
prompt = Prompt(name=f"test-{unique_identifier}", template=template) | ||
prompt_from_api = opik_client.get_prompt(name=prompt.name) | ||
|
||
assert prompt.name == prompt_from_api.name | ||
assert prompt.template == prompt_from_api.template | ||
assert prompt.description == prompt_from_api.description | ||
assert prompt.id == prompt_from_api.id | ||
assert prompt.commit == prompt_from_api.commit | ||
|
||
|
||
def test_prompt__format(opik_client): | ||
unique_identifier = str(uuid.uuid4())[-6:] | ||
template = "Hello, {name} from {place}! Nice to meet you, {name}." | ||
|
||
prompt = Prompt(name=f"test-{unique_identifier}", template=template) | ||
|
||
result = prompt.format() | ||
assert result == "Hello, {name} from {place}! Nice to meet you, {name}." | ||
|
||
result = prompt.format(name="John") | ||
assert result == "Hello, John from {place}! Nice to meet you, John." | ||
|
||
result = prompt.format(name="John", place="The Earth") | ||
assert result == "Hello, John from The Earth! Nice to meet you, John." | ||
|
||
result = prompt.format(name="John", place="The Earth", unexisting_key="value") | ||
assert result == "Hello, John from The Earth! Nice to meet you, John." | ||
|
||
assert prompt.template == template |