-
Notifications
You must be signed in to change notification settings - Fork 841
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
Showing
8 changed files
with
324 additions
and
23 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
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
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,48 @@ | ||
import pytest | ||
|
||
from ragas.testset.synthesizers import AbstractQuerySynthesizer | ||
|
||
|
||
def test_prompt_save_load(tmp_path, fake_llm): | ||
synth = AbstractQuerySynthesizer(llm=fake_llm) | ||
synth_prompts = synth.get_prompts() | ||
synth.save_prompts(tmp_path) | ||
loaded_prompts = synth.load_prompts(tmp_path) | ||
assert len(synth_prompts) == len(loaded_prompts) | ||
for name, prompt in synth_prompts.items(): | ||
assert name in loaded_prompts | ||
assert prompt == loaded_prompts[name] | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_prompt_save_adapt_load(tmp_path, fake_llm): | ||
synth = AbstractQuerySynthesizer(llm=fake_llm) | ||
|
||
# patch adapt_prompts | ||
async def adapt_prompts_patched(self, language, llm): | ||
for prompt in self.get_prompts().values(): | ||
prompt.instruction = "test" | ||
prompt.language = language | ||
return self.get_prompts() | ||
|
||
synth.adapt_prompts = adapt_prompts_patched.__get__(synth) | ||
|
||
# adapt prompts | ||
original_prompts = synth.get_prompts() | ||
adapted_prompts = await synth.adapt_prompts("spanish", fake_llm) | ||
synth.set_prompts(**adapted_prompts) | ||
|
||
# save n load | ||
synth.save_prompts(tmp_path) | ||
loaded_prompts = synth.load_prompts(tmp_path, language="spanish") | ||
|
||
# check conditions | ||
assert len(adapted_prompts) == len(loaded_prompts) | ||
for name, adapted_prompt in adapted_prompts.items(): | ||
assert name in loaded_prompts | ||
assert name in original_prompts | ||
|
||
loaded_prompt = loaded_prompts[name] | ||
assert adapted_prompt.instruction == loaded_prompt.instruction | ||
assert adapted_prompt.language == loaded_prompt.language | ||
assert adapted_prompt == loaded_prompt |
Oops, something went wrong.