first testcase

This commit is contained in:
Grey_D
2023-02-28 00:36:43 +08:00
parent c09f6bf016
commit 01930a9fdb
6 changed files with 249 additions and 2 deletions

View File

@@ -1,5 +1,35 @@
from chatgpt_wrapper import ChatGPT
from llm_handle.parser import extract_cmd
import os
bot = ChatGPT()
response = bot.ask("Hello, world!")
print(response) # prints the response from chatGPT
response = bot.ask("Can you give me a sample command in Mac terminal for checking the user names? Please give me the code directly.")
sample_response = """
Certainly! To list all user names on a Mac using the terminal, you can use the `dscl` command with the `list` option for the `/Users` node. Here's the command:
```
dscl . list /Users | grep -v '^_'
```
This will output a list of all user accounts on the system, excluding any system accounts that start with an underscore.
"""
# print("The response is:", response)
command = extract_cmd(str(response))
print("The command is:", command)
# execute the command in the mac terminal.
# Alert!! The execution should be really careful, because it can be dangerous.
# It is recommended to use this in a sandbox environment.
output = os.popen(command).read()
print("The output is:\n", output)
# Ideally, the output should be:
"""
daemon
uname
nobody
root"""
# delete the session in the end
bot.delete_conversation()