Hi there,
trying to get SmartScraperGraph running on Fast-API.
@app.post("/crawl")
async def crawl(request: Request):
data = await request.json()
url = data.get('url')
try:
smart_scraper_graph = SmartScraperGraph(
prompt="List me all the articles",
# also accepts a string with the already downloaded HTML code
source=url,
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
# Access the URL field
return result
except Exception as e:
print(f"Error in crawl: {e}")
return None
Config
`graph_config = {
"llm": {
"model": "ollama/llama3",
"temperature": 0,
"format": "json", # Ollama needs the format to be specified explicitly
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
},
"embeddings": {
"model": "ollama/nomic-embed-text",
"base_url": "http://localhost:11434", # set ollama URL arbitrarilyURL
}
}`
Error:
Error in crawl: asyncio.run() cannot be called from a running event loop
/Users/konrad/Documents/Projects/product-spider/apps/service/main.py:171: RuntimeWarning: coroutine 'AsyncChromiumLoader.ascrape_playwright' was never awaited
Any idea? Thanks
Hi there,
trying to get SmartScraperGraph running on Fast-API.
Config
Error:
Any idea? Thanks