休斯頓是一種簡單的基於GPT的命令行工具,可通過提供簡單的自然語言指令來生成外殼命令或腳本。
在Linux,Mac和Windows上工作。您可以將其用於Bash,Powershell,ZSH,Python或任何其他外殼或腳本語言。
cargo install --git https://github.com/npgrosser/Houston.git
與休斯頓互動的默認命令是hu (休斯頓的縮寫)。您可以為休斯頓提供自然語言的指導。
例如:
hu run ubuntu container with interactive bashhu find all pdf files in my home directoryhu delete unused docker images and networkshu tell me a dad joke要使用休斯頓,必須將OpenAI_API_KEY環境變量設置為OpenAI API密鑰。您可以在https://platform.openai.com上獲得一個。如果願意,還可以在配置文件中指定密鑰,請參閱“配置”部分以獲取更多信息。
休斯頓對您的系統一無所知。因此,為了給休斯頓完成任務的最佳機會,您可以提供上下文信息。這可能包括有關文件樹的詳細信息,特定文件的內容,已安裝的軟件包,您的bash歷史記錄等。
為此,有一些功能可以幫助您完成此操作。
上下文文件是一個具有“ .ctxt”擴展名的文件,其中包含自然語言的信息列表。
您還可以使用命令變量添加動態生成的信息。
您在〜/Houston/default.ctxt文件中定義的信息始終提供給休斯敦。這是您將使用的上下文文件讓休斯頓了解您的個人偏好和要求。例如,您喜歡哪個軟件包經理,您最喜歡的語言是什麼,您喜歡他打電話給您,等等。
上下文文件的內容應寫入項目符號列表。
例子:
- If I want you to install something, use brew if the package is avaiable there
- If the script gets more complex, use comments to explain what you are doing
- When printing to the console, use capital letters. I like it when you shout at me
命名的上下文文件是您可以按照指示啟用的上下文文件。它們對於提供特定特定任務的上下文信息很有用。像默認的上下文文件一樣,它們位於〜/Houston目錄中。您可以使用-c標誌啟用它們。
hu <instruction> -c <context-file-name>
例子:
〜/houston/pretty-ofput.ctxt
- when printing to the terminal, use colored output and fancy ASCII art
用法:
hu print hello world -c pretty-output
根據指令,您可以啟用多個上下文文件。
hu <instruction> -c <context-file-name-1> -c <context-file-name-2>
例子:
hu tell me a joke -c pretty-output -c dark-humor
上下文文件可以是純文本文件,但它們也可以包含命令變量。您可以使用${cmd}語法來利用它們。這些命令變量在每個說明上評估,並替換為命令的輸出。
這是使用命令變量的上下文文件的示例:
- The current working directory is ${pwd}.
- The current user is ${whoami}.
- The current time is ${date}.
處理此模板時,結果輸出看起來與此相似:
- The current working directory is /home/user/my-name/houston.
- The current user is my-name.
- The current time is 2020-10-10 12:00:00.
編寫自己的上下文文件時,請記住所有數據將發送到OpenAI。因此,您應僅使用未透露敏感信息的命令。
通過-c標誌使用命名上下文時,您也可以通過參數。例如:
hu tell me a joke -c lang:german
參數傳遞給模板,您可以像使用任何普通的Shell腳本一樣訪問它。例子:
〜/休斯頓/lang.ctxt:
- When printing to the terminal, always use the ${echo $1} language.
請記住,我們需要在此處使用echo命令,因為命令變量被命令的輸出替換
如果要通過多個參數,則只需要確保圍繞上下文規範添加引號即可。
hu tell me a joke -c "langs:german english french"
請注意,上面的示例假定Bash用作評估命令變量的外殼。
使用其他外殼時,您可能需要使用其他語法來訪問參數。
例如,在PowerShell中,您將使用$ args變量。另外,您無需使用Echo命令。
- When printing to the terminal, always use the ${$args[0]} language.
這裡還有一些命名上下文文件的示例,可以讓您了解如何使用它們。
將當前GIT狀態作為上下文信息添加的上下文文件。
- The current git status is:
```
${git status}
```
上下文文件,將當前的Docker狀態添加為上下文信息。
- The current docker status is:
```
${docker ps -a}
```
- The current docker images are:
```
${docker images}
```
上下文文件,將bash歷史記錄中的最後一個n(默認10)命令作為上下文信息。
- The last ${1:-10} commands I ran were:
```
${tail -n ${1:-10} ~/.bash_history | cut -d ';' -f 2-}
```
上下文文件,將當前環境變量作為上下文信息。
- The current environment variables are:
```
${env}
```
上下文文件,將當前文件樹添加為上下文信息。
- The current file tree is:
```
${tree -L ${1:-3}}
```
如果您想查看實際傳遞給API的內容,則可以使用-v (冗長)標誌。
hu <instruction> -v
如果您想查看如何評估上下文文件,這將特別有用。
有關可用的配置選項,請參見示例config.yml 。首次運行hu時,將自動創建配置。它要么在$XDG_CONFIG_HOME/houston/config.yml或~/.config/houston/config.yml中。