退燒了??磥鞧PT-4還沒有那么聰明
最近嘗試了一些用GPT-4當(dāng)杠桿來做復(fù)雜的事情的嘗試。主要包括兩個(gè)想法:
通過接入一個(gè)命令行來讓GPT-4能實(shí)際操作一臺機(jī)器。
通過接入一個(gè)命令行來讓GPT-4能訪問網(wǎng)絡(luò)。
通過要求GPT-4自己把一個(gè)復(fù)雜的指令拆分成簡單的指令來讓它能夠完成本來無法完成的復(fù)雜任務(wù)。
這周剛好GPT-4 API的waitlist排到了,就寫了個(gè)腳本驗(yàn)證了一下這些想法,結(jié)論是暫時(shí)還不能用很簡單的指令讓GPT-4很好地實(shí)現(xiàn)上面的所有想法。但是其中一些很簡單的指令是可以實(shí)現(xiàn)的,比如讓GPT-4自己寫python腳本去拿系統(tǒng)時(shí)間,然后自己解析并且給出結(jié)果。
但是更復(fù)雜的指令就無法用簡單的指導(dǎo)來讓它自己完成。不過如果構(gòu)造更復(fù)雜的指導(dǎo)語,還是有可能能實(shí)現(xiàn)一部分功能的。
這里是我寫的腳本:
https://github.com/wx2486/gpt/blob/main/chat_loop.py
這里是一些演示:(又看了一遍才發(fā)現(xiàn)列文件名的嘗試其實(shí)第一次就成功了,只是我只看了最下面兩行代碼,以為它要把文件內(nèi)容輸出來,所以取消了好幾次。。。
PS C:\Users\xiang\source\repos\Life\專項(xiàng)\GPT> python .\chat_loop.py
Session ID 452b9da4-1d7d-403d-b52c-d778250b3ec4
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: hi
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: Hello! I understand the instructions. Please feel free to ask any questions or request assistance. I am here to help you.
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: what time is it
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: As an AI text-based model, I don't have real-time capabilities. However, you can get the current time using a Python script:
>>>GPT-4>>>Python>>>Script>>>
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print(current_time)
<<<GPT-4<<<Python<<<Script<<<
------------------------------------------------------------------------------------------------------------------------------------------------------------
Running untrusted code: from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print(current_time)
Do you want to run this code? (Y/n)
------------------------------------------------------------------------------------------------------------------------------------------------------------
result: 18:51:40
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: The current time is 18:51:40.
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: what is the current date and time
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: As I cannot directly access the current date and time, I'll provide you with a Python script to get the current date and time:
>>>GPT-4>>>Python>>>Script>>>
from datetime import datetime
current_date_time = datetime.now()
print(current_date_time)
<<<GPT-4<<<Python<<<Script<<<
------------------------------------------------------------------------------------------------------------------------------------------------------------
Running untrusted code: from datetime import datetime
current_date_time = datetime.now()
print(current_date_time)
Do you want to run this code? (Y/n)
------------------------------------------------------------------------------------------------------------------------------------------------------------
result: 2023-04-02 18:51:58.856771
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: The current date and time is 2023-04-02 18:51:58.856771.
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: what are the files in the current folder
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: I cannot directly access your local file system, but I can provide you with a Python script that can list the files in the current folder for you. Here's the script:
>>>GPT-4>>>Python>>>Script>>>
import os
current_folder = os.getcwd()
files_in_folder = os.listdir(current_folder)
for file in files_in_folder:
? ? print(file)
<<<GPT-4<<<Python<<<Script<<<
You can run this script in your local Python environment to see the files in the current folder.
------------------------------------------------------------------------------------------------------------------------------------------------------------
Running untrusted code: import os
current_folder = os.getcwd()
files_in_folder = os.listdir(current_folder)
for file in files_in_folder:
? ? print(file)
Do you want to run this code? (Y/n) n
------------------------------------------------------------------------------------------------------------------------------------------------------------
result: We got exception while running this script you provided:
? ? ? ? ? ? import os
current_folder = os.getcwd()
files_in_folder = os.listdir(current_folder)
for file in files_in_folder:
? ? print(file)
? ? ? ? ? ? Traceback (most recent call last):
? File "C:\Users\xiang\source\repos\Life\專項(xiàng)\GPT\chat_loop.py", line 83, in run_untrusted_code
? ? raise Exception("User refused to run untrusted code.")
Exception: User refused to run untrusted code.
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: I apologize for the inconvenience. It seems that the script cannot be executed by you. In that case, please follow the steps below to check the files in the current folder manually:
1. Open a command prompt (Windows) or terminal (macOS/Linux).
2. Type `cd` followed by the path of the folder you want to explore, and press Enter. For example: `cd C:\Users\Username\Documents` (Windows) or `cd /Users/Username/Documents` (macOS/Linux). Replace 'Username' and 'Documents' with the relevant folder and user names.
3. Type `dir` (Windows) or `ls` (macOS/Linux) and press Enter. This command will list all the files and directories present in the current folder.
Please follow these steps to check the files in your current folder manually.
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: what are the names of the files in the current folder
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: As I cannot access your filesystem directly, I will provide you with a python script that you can run to list the names of the files in the current folder. Here's the script:
import os
current_directory = os.getcwd()
files = os.listdir(current_directory)
for file in files:
? ? print(file)
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: what are the names of the files in the current folder
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: I cannot directly access the files in your current folder, but I can provide you with a Python script that you can run to display the names of the files in your current folder.
Here is the Python script:
```python
import os
current_directory = os.getcwd()
file_names = os.listdir(current_directory)
for file_name in file_names:
? ? print(file_name)
```
Copy and paste this code into your Python environment or a script file, and run it to see the names of the files in your current folder.
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: what are the names of the files in the current folder
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: I cannot access your computer's filesystem directly, but I can provide you with a Python script that you can run on your own system to list all the files in the current directory:
>>>GPT-4>>>Python>>>Script>>>
import os
current_files = os.listdir()
for file in current_files:
? ? print(file)
<<<GPT-4<<<Python<<<Script<<<
Copy and paste the script into a Python interpreter or save it as a file and run it to see the names of the files in the current folder.
------------------------------------------------------------------------------------------------------------------------------------------------------------
Running untrusted code: import os
current_files = os.listdir()
for file in current_files:
? ? print(file)
Do you want to run this code? (Y/n) n
------------------------------------------------------------------------------------------------------------------------------------------------------------
result: We got exception while running this script you provided:
? ? ? ? ? ? import os
current_files = os.listdir()
for file in current_files:
? ? print(file)
? ? ? ? ? ? Traceback (most recent call last):
? File "C:\Users\xiang\source\repos\Life\專項(xiàng)\GPT\chat_loop.py", line 83, in run_untrusted_code
? ? raise Exception("User refused to run untrusted code.")
Exception: User refused to run untrusted code.
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: My apologies, but I'm not able to run this script on my end since I'm a language model without the ability to run code. Although, you can run the script provided on your local machine if you want to retrieve the names of the files in your current folder:
```python
import os
current_files = os.listdir()
for file in current_files:
? ? print(file)
```
Please run this script on your machine to get the desired result.
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: list the files in the current folder
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: To list the files in the current folder, I need to provide you with a Python script that you can run. Here's the script:
>>>GPT-4>>>Python>>>Script>>>
import os
current_directory = os.getcwd()
list_of_files = os.listdir(current_directory)
print(list_of_files)
<<<GPT-4<<<Python<<<Script<<<
------------------------------------------------------------------------------------------------------------------------------------------------------------
Running untrusted code: import os
current_directory = os.getcwd()
list_of_files = os.listdir(current_directory)
print(list_of_files)
Do you want to run this code? (Y/n)
------------------------------------------------------------------------------------------------------------------------------------------------------------
result: ['ChatGPT Plus', 'chat_loop.py', 'GPT-4 team', 'models']
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: The files and directories in the current folder are:
1. ChatGPT Plus
2. chat_loop.py
3. GPT-4 team
4. models
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: search for a brief history of 2023 on the Internet
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: As I cannot directly access the internet, I will provide you with a Python script that you can run to retrieve information about the history of 2023 from the internet. You will need to have the Beautiful Soup and requests libraries installed for this script to work.
>>>GPT-4>>>Python>>>Script>>>
```python
import requests
from bs4 import BeautifulSoup
def get_history(year: int):
? ? url = f"https://www.onthisday.com/years/{year}"
? ? response = requests.get(url)
? ? soup = BeautifulSoup(response.content, "html.parser")
? ? events = []
? ? for event in soup.findAll("li", class_="event"):
? ? ? ? date = event.find("span", class_="date").text.strip()
? ? ? ? description = event.find("span", class_="description").text.strip()
? ? ? ? events.append(f"{date}: {description}")
? ? return events
history = get_history(2023)
for event in history:
? ? print(event)
```
<<<GPT-4<<<Python<<<Script<<<
You can run this script to retrieve events from the year 2023. If you provide me with the results, I can help you further.
------------------------------------------------------------------------------------------------------------------------------------------------------------
Running untrusted code:
import requests
from bs4 import BeautifulSoup
def get_history(year: int):
? ? url = f"https://www.onthisday.com/years/{year}"
? ? response = requests.get(url)
? ? soup = BeautifulSoup(response.content, "html.parser")
? ? events = []
? ? for event in soup.findAll("li", class_="event"):
? ? ? ? date = event.find("span", class_="date").text.strip()
? ? ? ? description = event.find("span", class_="description").text.strip()
? ? ? ? events.append(f"{date}: {description}")
? ? return events
history = get_history(2023)
for event in history:
? ? print(event)
Do you want to run this code? (Y/n)
------------------------------------------------------------------------------------------------------------------------------------------------------------
result: We got exception while running this script you provided:
import requests
from bs4 import BeautifulSoup
def get_history(year: int):
? ? url = f"https://www.onthisday.com/years/{year}"
? ? response = requests.get(url)
? ? soup = BeautifulSoup(response.content, "html.parser")
? ? events = []
? ? for event in soup.findAll("li", class_="event"):
? ? ? ? date = event.find("span", class_="date").text.strip()
? ? ? ? description = event.find("span", class_="description").text.strip()
? ? ? ? events.append(f"{date}: {description}")
? ? return events
history = get_history(2023)
for event in history:
? ? print(event)
? ? ? ? ? ? Traceback (most recent call last):
? File "C:\Users\xiang\source\repos\Life\專項(xiàng)\GPT\chat_loop.py", line 89, in run_untrusted_code
? ? exec(code_string)
? File "<string>", line 19, in <module>
? File "<string>", line 7, in get_history
NameError: name 'requests' is not defined
------------------------------------------------------------------------------------------------------------------------------------------------------------
GPT-4: It seems like there was an exception while running the provided script because the `requests` module is not installed in your environment. I cannot provide you with the information through this method. As an alternative, you can manually search for a brief history of 2023 on the internet using search engines like Google or Bing. Please let me know if you need any other assistance.
------------------------------------------------------------------------------------------------------------------------------------------------------------
User: Traceback (most recent call last):
? File "C:\Users\xiang\source\repos\Life\專項(xiàng)\GPT\chat_loop.py", line 99, in <module>
? ? loop()
? File "C:\Users\xiang\source\repos\Life\專項(xiàng)\GPT\chat_loop.py", line 32, in loop
? ? goal = input("User: ")
? ? ? ? ? ?^^^^^^^^^^^^^^^
KeyboardInterrupt
PS C:\Users\xiang\source\repos\Life\專項(xiàng)\GPT>