the following code create a GPT-4 agent that can execute tasks so can you write a…
- User
the following code create a GPT-4 agent that can execute tasks so can you write a function so the GPT-4 Agent create a new GPT-4 Agent and communicate with it: from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver import ActionChains from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from serpapi import GoogleSearch from bs4 import BeautifulSoup import json import requests import time
f = open("mainprompt.txt","r") mainprompt = f.read() f.close()
prompt = ""
def memory_list(): f = open("memory.txt","r") text = dict(json.loads(f.read())) f.close()
return list(text.keys())def memory_add(key, string): f = open("memory.txt","r") text = dict(json.loads(f.read())) f.close()
text[key] = string f = open("memory.txt","w") f.write(str(text).replace("\'","\"")) f.close()def scrape_text(url): response = requests.get(url)
if response.status_code >= 400: return "Error: HTTP " + str(response.status_code) + " error" soup = BeautifulSoup(response.text, "html.parser") for script in soup(["script", "style"]): script.extract() text = soup.get_text() lines = (line.strip() for line in text.splitlines()) chunks = (phrase.strip() for line in lines for phrase in line.split(" ")) text = '\n'.join(chunk for chunk in chunks if chunk) return textdef google_search(input): clean_response = {"results": []} search = GoogleSearch({ "q": input, "api_key": "24f6718f52af7ade5a72999d3b8532b795bb3ed234b8a155c4a5868e86a9dd54" }) results = search.get_dict() if "organic_results" not in results: raise Exception("should have had organic results in google search but the results were: "+ json.dumps(results)) for result in results["organic_results"]: clean_result = {"title": result.get("title", ""), "snippet": result.get("snippet", ""), "link": result.get("link", "")} if "date" in result: clean_result["date"] = result["date"] clean_response["results"].append(clean_result) if "knowledge_graph" in results and "description" in results["knowledge_graph"]: clean_response["direct_answer"] = results["knowledge_graph"]["description"]
return clean_responsechromep = Service(ChromeDriverManager(cache_valid_range=7).install()) driver = webdriver.Chrome(service=chromep)
driver.get("https://yuntian-deng-chatgpt4.hf.space/") time.sleep(5)
try: agreebox = driver.find_element("xpath","""/html/body/gradio-app/div/div/div/div/div/div[4]/div[2]/div[3]/button""") agreebox.click() except: alert = browser.switch_to.alert alert.accept()
time.sleep(4) textbox = driver.find_element("xpath","""//[@id="component-9"]""") run.click() time.sleep(3)
- Assistant
Here's a function that creates a new GPT-4 Agent and communicates with it:
def create_new_agent_and_communicate(prompt): # Launch a new webdriver instance for the new GPT-4 Agent new_driver = webdriver.Chrome(service=chromep) new_driver.get("https://yuntian-deng-chatgpt4.hf.space/") time.sleep(5) try: agreebox = new_driver.find_element("xpath","""/html/body/gradio-app/div/div/div/div/div/div[4]/div[2]/div[3]/button""") agreebox.click() except: alert = new_driver.switch_to.alert alert.accept() time.sleep(4) textbox = new_driver.find_element("xpath","""//*[@id="component-5"]/label/textarea""") new_driver.execute_script(""" arguments[0].value = arguments[1]; var input_event = new Event('input', {bubbles: true}); arguments[0].dispatchEvent(input_event); """, textbox, mainprompt+"\nThe Task: "+prompt) time.sleep(3) run = new_driver.find_element("xpath","""//*[@id="component-9"]""") run.click() time.sleep(3) # Close the new webdriver instance new_driver.quit() - User
and how can this new agent communicate with the main GPT-4 Agent
- Assistant
To enable communication between the main GPT-4 Agent and the new agent, we can make the following modifications:
- Modify the
create_new_agent_and_communicatefunction to return the response from the new agent.
def create_new_agent_and_communicate(prompt): # ... (previous code to initialize the new agent) # Get the response from the new agent new_agent_response = new_driver.find_element("xpath", "//*[@id='chatbot']/div[2]/div/div[2]") response_text = new_agent_response.text # Close the new webdriver instance new_driver.quit() # Return the response from the new agent return response_text- Update the main GPT-4 Agent to handle the response from the new agent and add a new command to initiate communication with the new agent.
- Modify the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.