Scrapegraph-ai icon indicating copy to clipboard operation
Scrapegraph-ai copied to clipboard

RuntimeError: asyncio.run() cannot be called from a running event loop

Open madeepakkumar1 opened this issue 1 year ago • 2 comments

Describe the bug Extract same code copied from example of Azure (below), trying to execute it on Jupyter notebook. python3.11

To Reproduce Steps to reproduce the behavior:

from langchain_openai import AzureOpenAIEmbeddings

lm_model_instance = AzureChatOpenAI(
    openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],
    azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]
)

embedder_model_instance = AzureOpenAIEmbeddings(
    azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],
    openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],
)
graph_config = {
    "llm": {"model_instance": llm_model_instance},
    "embeddings": {"model_instance": embedder_model_instance}
}

smart_scraper_graph = SmartScraperGraph(
    prompt="""List me all the events, with the following fields: company_name, event_name, event_start_date, event_start_time, 
    event_end_date, event_end_time, location, event_mode, event_category, 
    third_party_redirect, no_of_days, 
    time_in_hours, hosted_or_attending, refreshments_type, 
    registration_available, registration_link""",
    source="https://www.hmhco.com/event",
    config=graph_config
)

Additional context Error traceback log 1 result = smart_scraper_graph.run() 2 print(result)

File d:\conda\envs\python311\Lib\site-packages\scrapegraphai\graphs\smart_scraper_graph.py:116, in SmartScraperGraph.run(self) 108 """ 109 Executes the scraping process and returns the answer to the prompt. 110 111 Returns: 112 str: The answer to the prompt. 113 """ 115 inputs = {"user_prompt": self.prompt, self.input_key: self.source} --> 116 self.final_state, self.execution_info = self.graph.execute(inputs) 118 return self.final_state.get("answer", "No answer found.")

File d:\conda\envs\python311\Lib\site-packages\scrapegraphai\graphs\base_graph.py:107, in BaseGraph.execute(self, initial_state) 104 current_node = index 106 with get_openai_callback() as cb: --> 107 result = current_node.execute(state) 108 node_exec_time = time.time() - curr_time 109 total_exec_time += node_exec_time

File d:\conda\envs\python311\Lib\site-packages\scrapegraphai\nodes\fetch_node.py:88, in FetchNode.execute(self, state) ... 187 "asyncio.run() cannot be called from a running event loop") 189 with Runner(debug=debug) as runner: 190 return runner.run(main

madeepakkumar1 avatar May 09 '24 05:05 madeepakkumar1

https://github.com/VinciGit00/Scrapegraph-ai/issues/179

kkarkos avatar May 09 '24 08:05 kkarkos

you should the libraries inside here https://colab.research.google.com/drive/1sEZBonBMGP44CtO6GQTwAlL0BGJXjtfd?usp=sharing

VinciGit00 avatar May 09 '24 08:05 VinciGit00

let us know

VinciGit00 avatar May 09 '24 10:05 VinciGit00

Duplicate of https://github.com/VinciGit00/Scrapegraph-ai/issues/179

PeriniM avatar May 09 '24 12:05 PeriniM