ragas icon indicating copy to clipboard operation
ragas copied to clipboard

Issues with await for language adapt

Open shawn-maxiao opened this issue 10 months ago • 2 comments

[ 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

shawn-maxiao avatar Feb 14 '25 13:02 shawn-maxiao

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)

sahusiddharth avatar Feb 15 '25 08:02 sahusiddharth

The code needs to be in inside aasync def function. See this pull request for an example https://github.com/explodinggradients/ragas/pull/1983

yesidc avatar Mar 27 '25 15:03 yesidc