Skip to content
The Chat Archive
gpt-4-0314· OpenAI WildChat-4.8M (AI2)

the following code create a GPT-4 agent that can execute tasks so can you write another…

  1. User

    the following code create a GPT-4 agent that can execute tasks so can you write another python program 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 text
    

    def 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_response
    

    chromep = 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() alert = driver.switch_to.alert alert.accept() except: alert = driver.switch_to.alert alert.accept() agreebox = driver.find_element("xpath","""/html/body/gradio-app/div/div/div/div/div/div[4]/div[2]/div[3]/button""") agreebox.click()

    time.sleep(4) textbox = driver.find_element("xpath","""//[@id="component-5"]/label/textarea""") 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: Make an instagram account and build any tools that will help with completing this task.") time.sleep(3) run = driver.find_element("xpath","""//[@id="component-9"]""") run.click() time.sleep(3)

    queue = driver.find_element("xpath","""//[@id="component-11"]/div/div[2]""") while True: try: queue = driver.find_element("xpath","""//[@id="component-11"]/div/div[2]""") except: break

    greenoutline = driver.find_element("xpath","""//[@id="component-11"]/div""").value_of_css_property('border') while greenoutline == "1.6px solid rgb(34, 197, 94)": greenoutline = driver.find_element("xpath","""//[@id="component-11"]/div""").value_of_css_property('border')

    response =driver.find_element("xpath","""//*[@id="chatbot"]/div[2]/div/div[2]""") print(response.text) response1 = response.text.replace("“",""").replace("”",""") responsereal = json.loads(response1)

    if responsereal["command"]["name"]: if responsereal["command"]["name"] == "google": prompt += str(google_search(responsereal["command"]["args"]["input"])) print(prompt) elif responsereal["command"]["name"] == "browse_website": prompt += str(scrape_text(responsereal["command"]["args"]["url"])) print(prompt) elif responsereal["command"]["name"] == "memory_add": memory_add(responsereal["command"]["args"]["key"],responsereal["command"]["args"]["string"]) prompt += "System: Added to memory proceed with your plan." elif responsereal["command"]["name"] == "memory_list": prompt += str(memory_list())

    count = 4 while True: textbox = driver.find_element("xpath","""//[@id="component-5"]/label/textarea""") driver.execute_script(""" arguments[0].value = arguments[1]; var input_event = new Event('input', {bubbles: true}); arguments[0].dispatchEvent(input_event); """, textbox, prompt) time.sleep(3) run = driver.find_element("xpath","""//[@id="component-9"]""") run.click() time.sleep(3)

    try:
    	queue = driver.find_element("xpath","""//*[@id="component-11"]/div/div[2]""")
    except:
    	pass
    while True:
    	try:
    		queue = driver.find_element("xpath","""//*[@id="component-11"]/div/div[2]""")
    	except:
    		break
    
    greenoutline = driver.find_element("xpath","""//*[@id="component-11"]/div""").value_of_css_property('border')
    while greenoutline == "1.6px solid rgb(34, 197, 94)":
    	greenoutline = driver.find_element("xpath","""//*[@id="component-11"]/div""").value_of_css_property('border')
    
    
    response =driver.find_element("xpath","""//*[@id="chatbot"]/div[2]/div/div["""+str(count)+"""]""")
    print(response.text)
    response1 = response.text.replace("“","\"").replace("”","\"")
    responsereal = json.loads(response1)
    prompt = ""
    time.sleep(10)
    if responsereal["command"]["name"]:
    	if responsereal["command"]["name"] == "google":
    		prompt += str(google_search(responsereal["command"]["args"]["input"]))
    		print(prompt)
    	elif responsereal["command"]["name"] == "browse_website":
    		prompt += str(scrape_text(responsereal["command"]["args"]["url"]))
    		print(prompt)
    	elif responsereal["command"]["name"] == "memory_add":
    		memory_add(responsereal["command"]["args"]["key"],responsereal["command"]["args"]["string"])
    		prompt += "System: Added to memory proceed with your plan."
    	elif responsereal["command"]["name"] == "memory_list":
    		prompt += str(memory_list())
    count += 2
    
  2. Assistant

    It's important to note that GPT-4 doesn't exist as of now, and the given code snippet uses GPT-3. However, I'll assume that GPT-4 would function similarly to GPT-3 and continue.

    To create another GPT-4 agent and allow communication between the two agents, you can simply send the response from one agent as input to the other. Here's a modified version of the given code snippet to create two GPT-4 agents and make them communicate with each other:

    def create_agent(driver, main_prompt):
        textbox = driver.find_element("xpath", """//*[@id="component-5"]/label/textarea""")
        driver.execute_script("""
            arguments[0].value = arguments[1];
            var input_event = new Event('input', {bubbles: true});
            arguments[0].dispatchEvent(input_event);
        """, textbox, main_prompt)
        time.sleep(3)
        run = driver.find_element("xpath", """//*[@id="component-9"]""")
        run.click()
        time.sleep(3)
    
        queue = driver.find_element("xpath", """//*[@id="component-11"]/div/div[2]""")
        greenoutline = driver.find_element("xpath", """//*[@id="component-11"]/div""").value_of_css_property('border')
        while greenoutline == "1.6px solid rgb(34, 197, 94)":
            greenoutline = driver.find_element("xpath", """//*[@id="component-11"]/div""").value_of_css_property('border')
    
        response = driver.find_element("xpath", """//*[@id="chatbot"]/div[2]/div/div[2]""")
        print(response.text)
        response_text = response.text.replace("“", "\"").replace("”", "\"")
        response_data = json.loads(response_text)
        return response_data
    
    
    # Initialize two GPT-4 agents with different tasks
    agent1_task = "Agent 1, your task is to create an Instagram account."
    agent2_task = "Agent 2, your task is to help Agent 1 create an Instagram account."
    
    main_prompt_agent1 = mainprompt + "\nThe Task: " + agent1_task
    main_prompt_agent2 = mainprompt + "\nThe Task: " + agent2_task
    
    response_agent1 = create_agent(driver, main_prompt_agent1)
    response_agent2 = create_agent(driver, main_prompt_agent2)
    
    # Make the two GPT-4 agents communicate with each other
    communication_rounds = 5
    for _ in range(communication_rounds):
        prompt_agent1 = "Agent 1, communicate with Agent 2: " + response_agent2["response"]
        response_agent1 = create_agent(driver, main_prompt_agent1 + '\n' + prompt_agent1)
    
        prompt_agent2 = "Agent 2, communicate with Agent 1: " + response_agent1["response"]
        response_agent2 = create_agent(driver, main_prompt_agent2 + '\n' + prompt_agent2)
    

    This script initializes two different GPT-4 agents with separate tasks and makes them communicate with each other for a specified number of communication rounds (communication_rounds). Each agent's response is sent as input to the other agent.

  3. User

    rewrite this maintining the origial piece of code that I gave you and making the agent in a function

  4. Assistant

    Here's the modified version of the original code that creates the GPT Agent as a function and includes communication between two agents:

    # ...
    # (original import statements and helper function definitions)
    # ...
    
    def create_agent(driver, prompt, count):
        textbox = driver.find_element("xpath", """//*[@id="component-5"]/label/textarea""")
        driver.execute_script("""
            arguments[0].value = arguments[1];
            var input_event = new Event('input', {bubbles: true});
            arguments[0].dispatchEvent(input_event);
        """, textbox, prompt)
        time.sleep(3)
        run = driver.find_element("xpath", """//*[@id="component-9"]""")
        run.click()
        time.sleep(3)
    
        while True:
            try:
                queue = driver.find_element("xpath", """//*[@id="component-11"]/div/div[2]""")
            except:
                break
    
        greenoutline = driver.find_element("xpath", """//*[@id="component-11"]/div""").value_of_css_property('border')
        while greenoutline == "1.6px solid rgb(34, 197, 94)":
            greenoutline = driver.find_element("xpath", """//*[@id="component-11"]/div""").value_of_css_property('border')
    
        response = driver.find_element("xpath", """//*[@id="chatbot"]/div[2]/div/div[""" + str(count) + """]""")
        print(response.text)
        response_text = response.text.replace("“", "\"").replace("”", "\"")
        response_data = json.loads(response_text)
        return response_data
    
    # ...
    # (the original code that initializes the GPT Agent)
    # ...
    
    # Initialize two GPT-4 agents with different tasks
    agent1_task = "Agent 1, your task is to create an Instagram account."
    agent2_task = "Agent 2, your task is to help Agent 1 create an Instagram account."
    
    main_prompt_agent1 = mainprompt + "\nThe Task: " + agent1_task
    main_prompt_agent2 = mainprompt + "\nThe Task: " + agent2_task
    
    response_agent1 = create_agent(driver, main_prompt_agent1, 2)
    response_agent2 = create_agent(driver, main_prompt_agent2, 4)
    
    # Make the two GPT-4 agents communicate with each other
    communication_rounds = 5
    count_agent1 = 6
    count_agent2 = 8
    for _ in range(communication_rounds):
        prompt_agent1 = "Agent 1, communicate with Agent 2: " + response_agent2["response"]
        response_agent1 = create_agent(driver, main_prompt_agent1 + '\n' + prompt_agent1, count_agent1)
        count_agent1 += 2
    
        prompt_agent2 = "Agent 2, communicate with Agent 1: " + response_agent1["response"]
        response_agent2 = create_agent(driver, main_prompt_agent2 + '\n' + prompt_agent2, count_agent2)
        count_agent2 += 2
    

    This script maintains the original code you provided and incorporates the create_agent function to create two agents that communicate with each other. We now have separate counts (count_agent1 and count_agent2) for each agent's response elements in the DOM.