Closed muhammad-ammar12 closed 1 month ago
Hey @muhammad-ammar12! 👋 I'm here to help you with your coding troubles!
The "ExceptionInRunner" error you're encountering is due to the event loop already running when the evaluate
function tries to execute asynchronous operations. This is a common issue when running asynchronous code in environments like Jupyter notebooks.
To fix this, you can use the nest_asyncio
library to allow nested use of asyncio.run()
. Here's how you can modify your code:
Install the nest_asyncio
library:
pip install nest_asyncio
Modify your code to include nest_asyncio
:
from datasets import Dataset
import os
import nest_asyncio
from ragas import evaluate
from ragas.metrics import faithfulness, answer_correctness
# Apply nest_asyncio to allow nested event loops
nest_asyncio.apply()
os.environ["OPENAI_API_KEY"] = "your-openai-key"
data_samples = {
'question': ['When was the first super bowl?', 'Who won the most super bowls?'],
'answer': ['The first superbowl was held on Jan 15, 1967', 'The most super bowls have been won by The New England Patriots'],
'contexts' : [['The First AFL–NFL World Championship Game was an American football game played on January 15, 1967, at the Los Angeles Memorial Coliseum in Los Angeles,'],
['The Green Bay Packers...Green Bay, Wisconsin.','The Packers compete...Football Conference']],
'ground_truth': ['The first superbowl was held on January 15, 1967', 'The New England Patriots have won the Super Bowl a record six times']
}
dataset = Dataset.from_dict(data_samples)
score = evaluate(dataset, metrics=[faithfulness, answer_correctness])
score.to_pandas()
This should resolve the "This event loop is already running" error and allow your code to run correctly [1].
To continue talking to Dosu, mention @dosu.
thanks for reaching out, tried your provided solution but still getting the same error.
On Wed, Jul 3, 2024 at 4:16 PM dosubot[bot] @.***> wrote:
Hey @muhammad-ammar12 https://github.com/muhammad-ammar12! 👋 I'm here to help you with your coding troubles!
The "ExceptionInRunner" error you're encountering is due to the event loop already running when the evaluate function tries to execute asynchronous operations. This is a common issue when running asynchronous code in environments like Jupyter notebooks.
To fix this, you can use the nest_asyncio library to allow nested use of asyncio.run(). Here's how you can modify your code:
1.
Install the nest_asyncio library:
pip install nest_asyncio
2.
Modify your code to include nest_asyncio:
from datasets import Dataset import osimport nest_asynciofrom ragas import evaluatefrom ragas.metrics import faithfulness, answer_correctness
Apply nest_asyncio to allow nested event loopsnest_asyncio.apply()
os.environ["OPENAI_API_KEY"] = "your-openai-key" data_samples = { 'question': ['When was the first super bowl?', 'Who won the most super bowls?'], 'answer': ['The first superbowl was held on Jan 15, 1967', 'The most super bowls have been won by The New England Patriots'], 'contexts' : [['The First AFL–NFL World Championship Game was an American football game played on January 15, 1967, at the Los Angeles Memorial Coliseum in Los Angeles,'], ['The Green Bay Packers...Green Bay, Wisconsin.','The Packers compete...Football Conference']], 'ground_truth': ['The first superbowl was held on January 15, 1967', 'The New England Patriots have won the Super Bowl a record six times'] } dataset = Dataset.from_dict(data_samples) score = evaluate(dataset, metrics=[faithfulness, answer_correctness])score.to_pandas()
This should resolve the "This event loop is already running" error and allow your code to run correctly [1] https://github.com/explodinggradients/ragas/blob/main/src/ragas/executor.py .
To continue talking to Dosu https://dosu.dev, mention @dosu https://github.com/dosu.
— Reply to this email directly, view it on GitHub https://github.com/explodinggradients/ragas/issues/1064#issuecomment-2206505060, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7ROIEUQVCZJRQEL47XKBRDZKQIVTAVCNFSM6AAAAABKJZJRO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBWGUYDKMBWGA . You are receiving this because you were mentioned.Message ID: @.***>
My Bad! just figured out after fixing the code with your help was missing the API_key. it works now!!
thanks a lot for your help @dosu
On Wed, Jul 3, 2024 at 4:39 PM Muhammad Ammar Shahid < @.***> wrote:
thanks for reaching out, tried your provided solution but still getting the same error.
On Wed, Jul 3, 2024 at 4:16 PM dosubot[bot] @.***> wrote:
Hey @muhammad-ammar12 https://github.com/muhammad-ammar12! 👋 I'm here to help you with your coding troubles!
The "ExceptionInRunner" error you're encountering is due to the event loop already running when the evaluate function tries to execute asynchronous operations. This is a common issue when running asynchronous code in environments like Jupyter notebooks.
To fix this, you can use the nest_asyncio library to allow nested use of asyncio.run(). Here's how you can modify your code:
1.
Install the nest_asyncio library:
pip install nest_asyncio
2.
Modify your code to include nest_asyncio:
from datasets import Dataset import osimport nest_asynciofrom ragas import evaluatefrom ragas.metrics import faithfulness, answer_correctness
Apply nest_asyncio to allow nested event loopsnest_asyncio.apply()
os.environ["OPENAI_API_KEY"] = "your-openai-key" data_samples = { 'question': ['When was the first super bowl?', 'Who won the most super bowls?'], 'answer': ['The first superbowl was held on Jan 15, 1967', 'The most super bowls have been won by The New England Patriots'], 'contexts' : [['The First AFL–NFL World Championship Game was an American football game played on January 15, 1967, at the Los Angeles Memorial Coliseum in Los Angeles,'], ['The Green Bay Packers...Green Bay, Wisconsin.','The Packers compete...Football Conference']], 'ground_truth': ['The first superbowl was held on January 15, 1967', 'The New England Patriots have won the Super Bowl a record six times'] } dataset = Dataset.from_dict(data_samples) score = evaluate(dataset, metrics=[faithfulness, answer_correctness])score.to_pandas()
This should resolve the "This event loop is already running" error and allow your code to run correctly [1] https://github.com/explodinggradients/ragas/blob/main/src/ragas/executor.py .
To continue talking to Dosu https://dosu.dev, mention @dosu https://github.com/dosu.
— Reply to this email directly, view it on GitHub https://github.com/explodinggradients/ragas/issues/1064#issuecomment-2206505060, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7ROIEUQVCZJRQEL47XKBRDZKQIVTAVCNFSM6AAAAABKJZJRO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBWGUYDKMBWGA . You are receiving this because you were mentioned.Message ID: @.***>
You're welcome! I'm glad to hear it's working now. If you have any more questions or run into any other issues, feel free to ask. Happy coding! 🚀
To continue talking to Dosu, mention @dosu.
I can not figure out what is wrong with the provided code read the documentation provided as well.
Bug ExceptionInRunner: The runner thread which was running the jobs raised an exeception. Read the traceback above to debug it. You can also pass
raise_exceptions=False
incase you want to show only a warning message instead.Ragas version: Python version:
Code to Reproduce pip install ragas
Error trace
Additional context Tried to run as it is code provided in the repo but it is raising an error. tried it on 03-JUL-2024