mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-23 21:00:30 +08:00
fixed internet research
This commit is contained in:
parent
57a53bd6af
commit
a5fc71f34e
@ -5,6 +5,7 @@ Example of Search Graph
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from scrapegraphai.graphs import SearchGraph
|
||||
from scrapegraphai.utils import convert_to_csv, convert_to_json
|
||||
|
||||
load_dotenv()
|
||||
openai_key = os.getenv("OPENAI_APIKEY")
|
||||
@ -25,4 +26,8 @@ smart_scraper_graph = SearchGraph(
|
||||
)
|
||||
|
||||
result = smart_scraper_graph.run()
|
||||
print(result)
|
||||
print(result)
|
||||
|
||||
# Save to json and csv
|
||||
convert_to_csv(result, "result")
|
||||
convert_to_json(result, "result")
|
||||
|
||||
@ -80,7 +80,8 @@ class SearchInternetNode(BaseNode):
|
||||
|
||||
output_parser = CommaSeparatedListOutputParser()
|
||||
|
||||
search_template = """Given the following user prompt, return a query that can be used to search the internet for relevant information. \n
|
||||
search_template = """Given the following user prompt, return a query that can be
|
||||
used to search the internet for relevant information. \n
|
||||
You should return only the query string. \n
|
||||
User Prompt: {user_prompt}"""
|
||||
|
||||
@ -95,7 +96,7 @@ class SearchInternetNode(BaseNode):
|
||||
|
||||
print(f"Search Query: {search_query}")
|
||||
# TODO: handle multiple URLs
|
||||
answer = search_on_web(query=search_query, search_engine="DuckDuckGo", max_results=1)[0]
|
||||
answer = search_on_web(query=search_query, max_results=1)[0]
|
||||
|
||||
# Update the state with the generated answer
|
||||
state.update({self.output[0]: answer})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user