mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-20 23:44:19 +01:00
removed un necessary changes
This commit is contained in:
@@ -5,17 +5,21 @@ from llm_utils import create_chat_completion
|
|||||||
|
|
||||||
cfg = Config()
|
cfg = Config()
|
||||||
|
|
||||||
def get_website_content(url):
|
def scrape_text(url):
|
||||||
response = requests.get(url, headers=cfg.user_agent_header)
|
# Most basic check if the URL is valid:
|
||||||
|
if not url.startswith('http'):
|
||||||
|
return "Error: Invalid URL"
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(url, headers=cfg.user_agent_header)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
return "Error: " + str(e)
|
||||||
|
|
||||||
# Check if the response contains an HTTP error
|
# Check if the response contains an HTTP error
|
||||||
if response.status_code >= 400:
|
if response.status_code >= 400:
|
||||||
return "Error: HTTP " + str(response.status_code) + " error"
|
return "Error: HTTP " + str(response.status_code) + " error"
|
||||||
return response
|
|
||||||
|
|
||||||
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|
||||||
def scrape_text(website_content):
|
|
||||||
soup = BeautifulSoup(website_content.text, "html.parser")
|
|
||||||
|
|
||||||
for script in soup(["script", "style"]):
|
for script in soup(["script", "style"]):
|
||||||
script.extract()
|
script.extract()
|
||||||
@@ -42,8 +46,14 @@ def format_hyperlinks(hyperlinks):
|
|||||||
return formatted_links
|
return formatted_links
|
||||||
|
|
||||||
|
|
||||||
def scrape_links(website_content):
|
def scrape_links(url):
|
||||||
soup = BeautifulSoup(website_content.text, "html.parser")
|
response = requests.get(url, headers=cfg.user_agent_header)
|
||||||
|
|
||||||
|
# Check if the response contains an HTTP error
|
||||||
|
if response.status_code >= 400:
|
||||||
|
return "error"
|
||||||
|
|
||||||
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|
||||||
for script in soup(["script", "style"]):
|
for script in soup(["script", "style"]):
|
||||||
script.extract()
|
script.extract()
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ def execute_command(command_name, arguments):
|
|||||||
return execute_python_file(arguments["file"])
|
return execute_python_file(arguments["file"])
|
||||||
elif command_name == "generate_image":
|
elif command_name == "generate_image":
|
||||||
return generate_image(arguments["prompt"])
|
return generate_image(arguments["prompt"])
|
||||||
|
elif command_name == "do_nothing":
|
||||||
|
return "No action performed."
|
||||||
elif command_name == "task_complete":
|
elif command_name == "task_complete":
|
||||||
shutdown()
|
shutdown()
|
||||||
else:
|
else:
|
||||||
@@ -163,9 +165,8 @@ def google_official_search(query, num_results=8):
|
|||||||
return search_results_links
|
return search_results_links
|
||||||
|
|
||||||
def browse_website(url, question):
|
def browse_website(url, question):
|
||||||
website_content = browse.get_website_content(url)
|
summary = get_text_summary(url, question)
|
||||||
summary = get_text_summary(website_content, question)
|
links = get_hyperlinks(url)
|
||||||
links = get_hyperlinks(website_content)
|
|
||||||
|
|
||||||
# Limit links to 5
|
# Limit links to 5
|
||||||
if len(links) > 5:
|
if len(links) > 5:
|
||||||
@@ -176,14 +177,14 @@ def browse_website(url, question):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_text_summary(website_content, question):
|
def get_text_summary(url, question):
|
||||||
text = browse.scrape_text(website_content)
|
text = browse.scrape_text(url)
|
||||||
summary = browse.summarize_text(text, question)
|
summary = browse.summarize_text(text, question)
|
||||||
return """ "Result" : """ + summary
|
return """ "Result" : """ + summary
|
||||||
|
|
||||||
|
|
||||||
def get_hyperlinks(website_content):
|
def get_hyperlinks(url):
|
||||||
link_list = browse.scrape_links(website_content)
|
link_list = browse.scrape_links(url)
|
||||||
return link_list
|
return link_list
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user