ragas
ragas copied to clipboard
Issues with await for language adapt
[ y] I have checked the documentation and related resources and couldn't resolve my bug.
Describe the bug
I run the code flow with the help documents bellow,but one error happened. https://docs.ragas.io/en/latest/howtos/customizations/testgenerator/_language_adaptation/
from ragas.testset.synthesizers.single_hop.specific import (
SingleHopSpecificQuerySynthesizer,
)
distribution = [
(SingleHopSpecificQuerySynthesizer(llm=generator_llm), 1.0),
]
for query, _ in distribution:
prompts = await query.adapt_prompts("spanish", llm=generator_llm)
query.set_prompts(**prompts)
Output
==========================
results:
prompts = await query.adapt_prompts("spanish", llm=generator_llm)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside function
Ragas version: 0.2.13
Python version: 3.10.12
**Code to Reproduce**
from ragas.testset.synthesizers.single_hop.specific import (
SingleHopSpecificQuerySynthesizer,
)
distribution = [
(SingleHopSpecificQuerySynthesizer(llm=generator_llm), 1.0),
]
for query, _ in distribution:
prompts = await query.adapt_prompts("spanish", llm=generator_llm)
query.set_prompts(**prompts)
**Error trace**
prompts = await query.adapt_prompts("spanish", llm=generator_llm)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside function
Hi @shawn-maxiao,
I couldn't reproduce the error on my end. I'm using Python 3.10.14 and Ragas 0.2.13. Could you try reinstalling the Ragas package and see if that helps?
from ragas.testset.synthesizers.single_hop.specific import (
SingleHopSpecificQuerySynthesizer,
)
distribution = [
(SingleHopSpecificQuerySynthesizer(llm=generator_llm), 1.0),
]
for query, _ in distribution:
prompts = await query.adapt_prompts("spanish", llm=generator_llm)
query.set_prompts(**prompts)
The code needs to be in inside aasync def function. See this pull request for an example https://github.com/explodinggradients/ragas/pull/1983