ไธไธช็ฑ AI ๅคงๅ่ฏญ่จๆจกๅ๏ผLLM๏ผ้ฉฑๅจ็ๅฝไปค่ก็ไบงๅๅทฅๅ ทใ่ฏฅๅฝไปค่กๅทฅๅ ทๆไพไบๅฏน shell ๅฝไปคใไปฃ็ ็ๆฎตใๆๆกฃ ็็ฎๅ็ๆ๏ผๆถ้คไบๅฏนๅค้จ่ตๆบ๏ผๅฆ Google ๆ็ดข๏ผ็้ๆฑใๆฏๆ LinuxใmacOSใWindows๏ผๅนถไธ PowerShellใCMDใBashใZsh ็ญไธป่ฆ Shell ๅ ผๅฎนใ
ShellGPT.mp4
pip install shell-gpt
้ป่ฎคๆ
ๅตไธ๏ผShellGPT ไฝฟ็จ OpenAI ็ API ๅ GPT-4 ๆจกๅใๆจ้่ฆไธไธช API ๅฏ้ฅ๏ผๆจๅฏไปฅๅจ่ฟ้ ็ๆไธไธชใๆจๅฐ่ขซ่ฆๆฑ่พๅ
ฅๆจ็ๅฏ้ฅ๏ผ็ถๅๅฎๅฐ่ขซๅญๅจๅจ~/.config/shell_gpt/.sgptrc
ไธญใOpenAI API ๅนถ้ๅ
่ดน๏ผๆๅ
ณๆดๅคไฟกๆฏ๏ผ่ฏทๅ้
OpenAI ๅฎไปทใ
Tip
ๆ่ ๏ผๆจๅฏไปฅไฝฟ็จๆฌๅฐๆ็ฎก็ๅผๆบๆจกๅ๏ผ่ฟไบๆจกๅๅฏๅ ่ดนไฝฟ็จใ่ฆไฝฟ็จๆฌๅฐๆจกๅ๏ผๆจ้่ฆ่ฟ่ก่ชๅทฑ็ LLM ๅ็ซฏๆๅกๅจ๏ผไพๅฆOllamaใ่ฆไฝฟ็จ Ollama ่ฎพ็ฝฎ ShellGPT๏ผ่ฏทๆ็ ง่ฟไธช่ฏฆ็ป็ๆๅ ่ฟ่กๆไฝใ
โ๏ธ่ฏทๆณจๆ๏ผShellGPT ๅนถๆช้ๅฏนๆฌๅฐๆจกๅ่ฟ่กไผๅ๏ผๅฏ่ฝๆ ๆณๆ้ขๆๅทฅไฝใ
ShellGPT ๆจๅจๅฟซ้ๅๆๅๆฃ็ดขไฟกๆฏใๅฎๅฏนไบไปๆๆฏ้ ็ฝฎๅฐไธ่ฌ็ฅ่ฏ็็ฎๅ่ฏทๆฑ้ๅธธๆ็จใ
sgpt "ไปไนๆฏๆๆณข้ฃๅฅๆฐๅ"
# -> ๆๆณข้ฃๅฅๆฐๅๆฏไธ็ณปๅๆฐๅญ๏ผๅ
ถไธญๆฏไธชๆฐๅญ ...
ShellGPT ๅฏไปฅๆฅๅๆฅ่ชๆ ๅ่พๅ
ฅๅๅฝไปค่กๅๆฐ็ๆ็คบใๆ ่ฎบๆจๆฏๅๆฌข้่ฟ็ป็ซฏ่ฟ่ก่พๅ
ฅ็ฎก้๏ผ่ฟๆฏ็ดๆฅๆๅฎๅๆฐ๏ผsgpt
้ฝๅฏไปฅๆปก่ถณๆจ็้ๆฑใไพๅฆ๏ผๆจๅฏไปฅๆ นๆฎๅทฎๅผ่ฝปๆพ็ๆไธไธช git ๆไบคๆถๆฏ๏ผ
git diff | sgpt "ไธบๆ็ๆดๆน็ๆ git ๆไบคๆถๆฏ"
# -> ๅฐไธป่ฆๅ่ฝ่ฏฆ็ปไฟกๆฏๆทปๅ ๅฐ README.md ไธญ
ๆจๅฏไปฅ้่ฟไฝฟ็จ tdin ไผ ้ๆฅ่ชๅ็งๆฅๆบ็ๆฅๅฟ๏ผไปฅๅไธไธชๆ็คบๆฅๅๆๆฅๅฟใไพๅฆ๏ผๆไปฌๅฏไปฅไฝฟ็จๅฎๅฟซ้ๅๆๆฅๅฟ๏ผ่ฏๅซ้่ฏฏๅนถ่ทๅพๅฏ่ฝ็่งฃๅณๆนๆกๅปบ่ฎฎ๏ผ
docker logs -n 20 my_app | sgpt "ๆฃๆฅๆฅๅฟ๏ผๆฅๆพ้่ฏฏ๏ผๆไพๅฏ่ฝ็่งฃๅณๆนๆก"
ๆฃๆตๅฐ้่ฏฏ๏ผ็ฌฌ 7 ่ก่ฟๆฅ่ถ
ๆถใ
ๅฏ่ฝ็่งฃๅณๆนๆก๏ผๆฃๆฅ็ฝ็ป่ฟๆฅๅ้ฒ็ซๅข่ฎพ็ฝฎใ
ๆฃๆตๅฐ้่ฏฏ๏ผ็ฌฌ 12 ่กๅ
ๅญๅ้
ๅคฑ่ดฅใ
ๅฏ่ฝ็่งฃๅณๆนๆก๏ผ่่ๅขๅ ๅ
ๅญๅ้
ๆไผๅๅบ็จ็จๅบๅ
ๅญไฝฟ็จใ
ๆจ่ฟๅฏไปฅไฝฟ็จๅ็ง้ๅฎๅ่ฟ็ฎ็ฌฆไผ ้่พๅ ฅ๏ผ
sgpt "ๆป็ป" < document.txt
# -> ่ฏฅๆๆกฃ่ฎจ่ฎบไบๅฝฑๅ...
sgpt << EOF
ไปไนๆฏๅญฆไน Golang ็ๆไฝณๆนๆณ๏ผ
ๆไพไธไธช็ฎๅ็ hello world ็คบไพใ
EOF
# -> ๅญฆไน Golang ็ๆไฝณๆนๆณๆฏ...
sgpt <<< "ไปไนๆฏๅญฆไน shell ้ๅฎๅ็ๆไฝณๆนๅผ๏ผ"
# -> ๅญฆไน shell ้ๅฎๅ็ๆไฝณๆนๅผๆฏ้่ฟ...
ๅฝ็ถ๏ผไฝฟ็จ Shell GPT๏ผๆจๅฏไปฅๅฟซ้็ๆๅธธ่ง็ shell ๅฝไปคใๅช้ไฝฟ็จ--shell
ๆ-s
้้กน๏ผๅณๅฏๅจ็ป็ซฏไธญ็ๆๅๆง่กๆ้็ๅฝไปคใ
sgpt --shell "ๅจๅฝๅๆไปถๅคนไธญๆฅๆพๆๆ json ๆไปถ"
# -> find . -type f -name "*.json"
# -> [E]xecute, [D]escribe, [A]bort: e
Shell GPT ไผๆ นๆฎๆจไฝฟ็จ็ๆไฝ็ณป็ปๅ$SHELL
็ฏๅขๅ้ๆไพ็นๅฎ็ณป็ป็ shell ๅฝไปคใไพๅฆ๏ผๅฆๆๆจ่ฆๆฑsgpt
ๆดๆฐๆจ็็ณป็ป๏ผๅฎๅฐ่ฟๅๅบไบๆจ็ๆไฝ็ณป็ป็ๅฝไปคใไธ้ขๆฏๅจ macOS ไธ็็คบไพ๏ผ
sgpt -s "ๆดๆฐๆ็็ณป็ป"
# -> sudo softwareupdate -i -a
# -> [E]xecute, [D]escribe, [A]bort: e
ๅๆ ท็ๆ็คบ๏ผๅจ Ubuntu ไธไฝฟ็จๆถ๏ผๅฐ็ๆไธๅ็ๅปบ่ฎฎ๏ผ
sgpt -s "ๆดๆฐๆ็็ณป็ป"
# -> sudo apt update && sudo apt upgrade -y
# -> [E]xecute, [D]escribe, [A]bort: e
่ฎฉๆไปฌๅฐ่ฏไธไธ Docker๏ผ
sgpt -s "ๅฏๅจ nginx ๅฎนๅจ๏ผๆ่ฝฝ./index.html"
# -> docker run -d -p 80:80 -v $(pwd)/index.html:/usr/share/nginx/html/index.html nginx
# -> [E]xecute, [D]escribe, [A]bort: e
ๆไปฌไป็ถๅฏไปฅไฝฟ็จ็ฎก้ๅฐ่พๅ
ฅไผ ้็ปsgpt
ๅนถ็ๆ shell ๅฝไปค๏ผ
sgpt -s "ไฝฟ็จไปฅไธๆฐๆฎๅจ localhost ไธ่ฟ่ก POST ่ฏทๆฑ" < data.json
# -> curl -X POST -H "Content-Type: application/json" -d '{"a": 1, "b": 2}' https://localhost
# -> [E]xecute, [D]escribe, [A]bort: e
ๅจๆ็คบไธญๅบ็จ้ขๅค็ shell ๆๅทง๏ผไพๅฆๅฐๆไปถๅไผ ้็ปffmpeg
๏ผ
ls
# -> 1.mp4 2.mp4 3.mp4
sgpt -s "ไฝฟ็จ $(ls -m) ๅฐๅคไธช่ง้ขๆไปถๅๅนถไธบไธไธชๆฒกๆ้ณ้ข็่ง้ขๆไปถใ"
# -> ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -filter_complex "[0:v] [1:v] [2:v] concat=n=3:v=1 [v]" -map "[v]" out.mp4
# -> [E]xecute, [D]escribe, [A]bort: e
ๅฆๆๆจๆณไฝฟ็จ็ฎก้ไผ ้็ๆ็ shell ๅฝไปค๏ผๅฏไปฅไฝฟ็จ--no-interaction
้้กนใ่ฟๅฐ็ฆ็จไบคไบๆจกๅผ๏ผๅนถๅฐ็ๆ็ๅฝไปคๆๅฐๅฐ tdoutใๅจๆญค็คบไพไธญ๏ผๆไปฌไฝฟ็จpbcopy
ๅฐ็ๆ็ๅฝไปคๅคๅถๅฐๅช่ดดๆฟ๏ผ
sgpt -s "ๅจๅฝๅๆไปถๅคนไธญๆฅๆพๆๆ json ๆไปถ" --no-interaction | pbcopy
่ฟๆฏไธไธช้ๅธธๆนไพฟ็ๅ่ฝ๏ผๅฎๅ
่ฎธๆจๅจ็ป็ซฏไธญ็ดๆฅไฝฟ็จ sgpt
็ๅฝไปค่กฅๅ
จ๏ผๆ ้่พๅ
ฅ sgpt
็ๆ็คบ็ฌฆๅๅๆฐใShell ้ๆๅ่ฝๆฏๆไฝฟ็จ็ญ้ฎๅจ็ป็ซฏไธญไฝฟ็จ ShellGPT๏ผๆฏๆ Bash ๅ ZSH ไธค็ง shellใ่ฏฅๅ่ฝๅฐ sgpt
็ๅฝไปค่กฅๅ
จ็ดๆฅๆพๅ
ฅ็ป็ซฏ็ผๅฒๅบ๏ผ่พๅ
ฅ่ก๏ผ๏ผๅฏไปฅ็ซๅณ็ผ่พๅปบ่ฎฎ็ๅฝไปคใ
Shell_GPT_Integration.mp4
่ฆๅฎ่ฃ
Shell ้ๆ๏ผ่ฟ่ก sgpt --install-integration
ๅนถ้ๆฐๅฏๅจ็ป็ซฏไปฅๅบ็จๆดๆนใ่ฟๅฐๅจๆจ็ .bashrc
ๆ .zshrc
ๆไปถไธญๆทปๅ ๅ ่กไปฃ็ ใไนๅ๏ผๆจๅฏไปฅไฝฟ็จ Ctrl+l
๏ผ้ป่ฎคๆ
ๅตไธ๏ผๆฅ่ฐ็จ ShellGPTใๆไธ Ctrl+l
ๅ๏ผๅฎๅฐ็จๅปบ่ฎฎ็ๅฝไปคๆฟๆขๅฝๅ็่พๅ
ฅ่ก๏ผ็ผๅฒๅบ๏ผใๆจๅฏไปฅ็ผ่พๅฎ๏ผ็ถๅๆไธ Enter
ๆฅๆง่กๅฝไปคใ
้่ฟไฝฟ็จ --code
ๆ -c
ๅๆฐ๏ผๆจๅฏไปฅๆ็กฎ่ฏทๆฑ็บฏไปฃ็ ่พๅบ๏ผไพๅฆ๏ผ
sgpt --code "ไฝฟ็จ Python ่งฃๅณ Fizz Buzz ้ฎ้ข"
for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
็ฑไบ่ฟๆฏๆๆ็ Python ไปฃ็ ๏ผๆไปฌๅฏไปฅๅฐๅ ถ้ๅฎๅๅฐไธไธชๆไปถไธญ๏ผ
sgpt --code "ไฝฟ็จ Python ่งฃๅณ็ปๅ
ธ Fizz Buzz ้ฎ้ข" > fizz_buzz.py
python fizz_buzz.py
# 1
# 2
# Fizz
# 4
# Buzz
# ...
ๆไปฌ่ฟๅฏไปฅไฝฟ็จ็ฎก้ไผ ้่พๅ ฅ๏ผ
cat fizz_buzz.py | sgpt --code "ไธบๆ็ไปฃ็ ็ๆฏไธ่ก็ๆๆณจ้"
# ๅพช็ฏ้ๅไป 1 ๅฐ 100 ็ๆฐๅญ
for i in range(1, 101):
# ๆฃๆฅๆฐๅญๆฏๅฆๆข่ฝ่ขซ 3 ๆด้คๅ่ฝ่ขซ 5 ๆด้ค
if i % 3 == 0 and i % 5 == 0:
# ๅฆๆๆฐๅญ่ฝ่ขซ 3 ๅ 5 ๅๆถๆด้ค๏ผๆๅฐ"FizzBuzz"
print("FizzBuzz")
# ๆฃๆฅๆฐๅญๆฏๅฆ่ฝ่ขซ 3 ๆด้ค
elif i % 3 == 0:
# ๅฆๆๆฐๅญ่ฝ่ขซ 3 ๆด้ค๏ผๆๅฐ"Fizz"
print("Fizz")
# ๆฃๆฅๆฐๅญๆฏๅฆ่ฝ่ขซ 5 ๆด้ค
elif i % 5 == 0:
# ๅฆๆๆฐๅญ่ฝ่ขซ 5 ๆด้ค๏ผๆๅฐ"Buzz"
print("Buzz")
# ๅฆๆๆฐๅญๆขไธ่ฝ่ขซ 3 ๆด้คไนไธ่ฝ่ขซ 5 ๆด้ค๏ผๆๅฐๆฐๅญๆฌ่บซ
else:
print(i)
็ปๅธธ้่ฆไฟ็ๅๅ้กพๅฏน่ฏใsgpt
ไผๅจๆฏๆฌก่ฏทๆฑ LLM ๅฎๆๆถๅๅปบๅฏน่ฏๅผๅฏน่ฏใๅฏน่ฏๅฏไปฅ้ๆญฅๅๅฑ๏ผ่ๅคฉๆจกๅผ๏ผๆไปฅ REPL ๅพช็ฏ็ๆนๅผ่ฟ่กไบคไบ๏ผREPL ๆจกๅผ๏ผใไธค็งๆนๅผ้ฝไพ่ตไบๅไธไธช็งฐไธบๅฏน่ฏไผ่ฏ็ๅบ็กๅฏน่ฑก๏ผ่ฏฅไผ่ฏไฝไบๅฏ้
็ฝฎ ็CHAT_CACHE_PATH
ไฝ็ฝฎใ
่ฆๅผๅงๅฏน่ฏ๏ผ่ฏทไฝฟ็จ--chat
้้กน๏ผๅ้ข่ท็ไธไธชๅฏไธ็ไผ่ฏๅ็งฐๅไธไธชๆ็คบใ
sgpt --chat conversation_1 "่ฏท่ฎฐไฝๆ็ๆๅๆฌข็ๆฐๅญ๏ผ4"
# -> ๆๅฐ่ฎฐไฝไฝ ๆๅๆฌข็ๆฐๅญๆฏ 4ใ
sgpt --chat conversation_1 "ๆ็ๆๅๆฌข็ๆฐๅญๅ ไธ 4 ไผๆฏๅคๅฐ๏ผ"
# -> ไฝ ๆๅๆฌข็ๆฐๅญๆฏ 4๏ผๆไปฅๅฆๆๆไปฌๅ ไธ 4๏ผ็ปๆๅฐๆฏ 8ใ
ๆจๅฏไปฅไฝฟ็จ่ๅคฉไผ่ฏ้ๆญฅๆน่ฟ GPT ็ๅปบ่ฎฎ๏ผๆไพ้ขๅค็็ป่ใๅฏไปฅไฝฟ็จ--code
ๆ--shell
้้กนๆฅๅฏๅจ--chat
๏ผ
sgpt --chat conversation_2 --code "ไฝฟ็จ Python ๅ localhost ๅ้่ฏทๆฑ"
import requests
response = requests.get('https://localhost')
print(response.text)
่ฎฉๆไปฌ่ฏทๆฑ LLM ไธบๆไปฌ็่ฏทๆฑๆทปๅ ็ผๅญ๏ผ
sgpt --chat conversation_2 --code "ๆทปๅ ็ผๅญ"
import requests
from cachecontrol import CacheControl
sess = requests.session()
cached_sess = CacheControl(sess)
response = cached_sess.get('https://localhost')
print(response.text)
ๅฏนไบ shell ๅฝไปคไน้็จ๏ผ
sgpt --chat conversation_3 --shell "ๅฝๅๆไปถๅคนไธญ็ๅ
ๅฎนๆฏไปไน"
# -> ls
sgpt --chat conversation_3 "ๆๅ็งฐๆๅบ"
# -> ls | sort
sgpt --chat conversation_3 "ไฝฟ็จ FFMPEG ๅฐๅฎไปฌ่ฟๆฅ่ตทๆฅ"
# -> ffmpeg -i "concat:$(ls | sort | tr '\n' '|')" -codec copy output.mp4
sgpt --chat conversation_3 "ๅฐ็ๆ็ๆไปถ่ฝฌๆขไธบ MP3 ๆ ผๅผ"
# -> ffmpeg -i output.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 final_output.mp3
่ฆๅๅบไปปไธๅฏน่ฏๆจกๅผไธญ็ๆๆไผ่ฏ๏ผ่ฏทไฝฟ็จ--list-chats
ๆ-lc
้้กน๏ผ
sgpt --list-chats
# .../shell_gpt/chat_cache/conversation_1
# .../shell_gpt/chat_cache/conversation_2
่ฆๆพ็คบไธ็นๅฎๅฏน่ฏ็ธๅ
ณ็ๆๆๆถๆฏ๏ผ่ฏทไฝฟ็จ--show-chat
้้กน๏ผๅ้ข่ท็ไผ่ฏๅ็งฐ๏ผ
sgpt --show-chat conversation_1
# user: ่ฏท่ฎฐไฝๆ็ๆๅๆฌข็ๆฐๅญ๏ผ4
# assistant: ๆๅฐ่ฎฐไฝไฝ ๆๅๆฌข็ๆฐๅญๆฏ 4ใ
# user: ๆ็ๆๅๆฌข็ๆฐๅญๅ ไธ 4 ไผๆฏๅคๅฐ๏ผ
# assistant: ไฝ ๆๅๆฌข็ๆฐๅญๆฏ 4๏ผๆไปฅๅฆๆๆไปฌๅ ไธ 4๏ผ็ปๆๅฐๆฏ 8ใ
ๆไธไธช้ๅธธๆนไพฟ็ REPL๏ผ่ฏปๅ - ๆฑๅผ - ๆๅฐๅพช็ฏ๏ผๆจกๅผ๏ผๅฎๅ
่ฎธๆจไธ GPT ๆจกๅ่ฟ่กไบคไบๅผ่ๅคฉใ่ฆๅจ REPL ๆจกๅผไธๅผๅงไธไธช่ๅคฉไผ่ฏ๏ผ่ฏทไฝฟ็จ --repl
้้กนๅ้ข่ทไธไธชๅฏไธ็ไผ่ฏๅ็งฐใๆจ่ฟๅฏไปฅไฝฟ็จ "temp" ไฝไธบไผ่ฏๅ็งฐๆฅๅฏๅจไธดๆถ REPL ไผ่ฏใ่ฏทๆณจๆ๏ผ--chat
ๅ --repl
ไฝฟ็จ็ธๅ็ๅบๅฑๅฏน่ฑก๏ผๅ ๆญคๆจๅฏไปฅไฝฟ็จ --chat
ๆฅๅฏๅจไธไธช่ๅคฉไผ่ฏ๏ผ็ถๅไฝฟ็จ --repl
ๆฅ็ปง็ปญๅจ REPL ๆจกๅผไธ่ฟ่กๅฏน่ฏใ
sgpt --repl temp
่ฟๅ
ฅ REPL ๆจกๅผ๏ผๆ Ctrl+C ้ๅบใ
>>> ไปไนๆฏ REPL๏ผ
REPL ไปฃ่กจ่ฏปๅ - ๆฑๅผ - ๆๅฐๅพช็ฏใๅฎๆฏไธไธช็ผ็จ็ฏๅข...
>>> ๅฆไฝๅจ REPL ไธญไฝฟ็จ Python๏ผ
่ฆๅจ REPL ไธญไฝฟ็จ Python๏ผๆจๅฏไปฅ็ฎๅๅฐๆๅผ็ป็ซฏๆๅฝไปคๆ็คบ็ฌฆ...
REPL ๆจกๅผๅฏไปฅไธ --shell
ๅ --code
้้กนไธ่ตทไฝฟ็จ๏ผ้ๅธธๆนไพฟ่ฟ่กไบคไบๅผ็ shell ๅฝไปคๅไปฃ็ ็ๆ๏ผ
sgpt --repl temp --shell
่ฟๅ
ฅ shell REPL ๆจกๅผ๏ผ่พๅ
ฅ [e] ๆง่กๅฝไปค๏ผๆๆ Ctrl+C ้ๅบใ
>>> ๅฝๅๆไปถๅคนไธญๆไปไน๏ผ
ls
>>> ๆพ็คบๆไปถๅคงๅฐ
ls -lh
>>> ๆๆไปถๅคงๅฐๆๅบๅฎไปฌ
ls -lhS
>>> e๏ผไป
่พๅ
ฅ e ๆง่กๅฝไปค๏ผๆ่พๅ
ฅ d ่ฟ่กๆ่ฟฐ๏ผ
่ฆๆไพๅค่กๆ็คบ๏ผ่ฏทไฝฟ็จไธไธชๅผๅท """
๏ผ
sgpt --repl temp
่ฟๅ
ฅ REPL ๆจกๅผ๏ผๆ Ctrl+C ้ๅบใ
>>> """
... ่งฃ้ไปฅไธไปฃ็ ๏ผ
... import random
... print(random.randint(1, 10))
... """
่ฟๆฏไธไธชไฝฟ็จ random ๆจกๅ็ๆๅๆๅฐ้ๆบๆดๆฐ็ Python ่ๆฌใ
ๆจ่ฟๅฏไปฅ้่ฟๅฐๅ ถไฝไธบๅๆฐๆๆ ๅ่พๅ ฅ็่ณไธค่ ๅๆถไผ ้ๆฅไฝฟ็จๅๅงๆ็คบ่ฟๅ ฅ REPL ๆจกๅผ๏ผ
sgpt --repl temp < my_app.py
่ฟๅ
ฅ REPL ๆจกๅผ๏ผๆ Ctrl+C ้ๅบใ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ่พๅ
ฅ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
name = input("What is your name?")
print(f"Hello {name}")
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
>>> ่ฟๆฎตไปฃ็ ๆฏๅ
ณไบไปไน็๏ผ
ๆจๆไพ็ไปฃ็ ็ๆฎตๆฏ็จ Python ็ผๅ็ใๅฎๆ็คบ็จๆท...
>>> ๅ็ปญ้ฎ้ข...
ๅฝๆฐ่ฐ็จ ๆฏ OpenAI ๆไพ็ไธไธชๅผบๅคงๅ่ฝใๅฎๅ ่ฎธ LLM ๅจๆจ็็ณป็ปไธญๆง่กๅฝๆฐ๏ผ็จไบๅฎๆๅ็งไปปๅกใ่ฆๅฎ่ฃ ้ป่ฎคๅฝๆฐ๏ผ่ฏท่ฟ่ก:
sgpt --install-functions
ShellGPT ๆไพไบไธ็งๆนไพฟ็ๆนๆณๆฅๅฎไนๅไฝฟ็จๅฝๆฐใไธบไบๅๅปบๆจ็่ชๅฎไนๅฝๆฐ๏ผ่ฏท่ฝฌๅฐ~/.config/shell_gpt/functions
ๅนถๅๅปบไธไธชๆฐ็.py ๆไปถ๏ผๆไปถๅไธบๅฝๆฐๅใๅจ่ฟไธชๆไปถไธญ๏ผๆจๅฏไปฅไฝฟ็จไปฅไธ่ฏญๆณๆฅๅฎไนๆจ็ๅฝๆฐ:
# execute_shell_command.py
import subprocess
from pydantic import Field
from instructor import OpenAISchema
class Function(OpenAISchema):
"""
ๆง่กไธไธช shell ๅฝไปคๅนถ่ฟๅ่พๅบ๏ผ็ปๆ๏ผใ
"""
shell_command: str = Field(..., example="ls -la", descriptions="่ฆๆง่ก็ shell ๅฝไปคใ")
class Config:
title = "execute_shell_command"
@classmethod
def execute(cls, shell_command: str) -> str:
result = subprocess.run(shell_command.split(), capture_output=True, text=True)
return f"้ๅบ็ : {result.returncode}, ่พๅบ:\n{result.stdout}"
็ฑปๅ
็ๆๆกฃๅญ็ฌฆไธฒๆณจ้ๅฐไฝไธบๅฝๆฐ็ๆ่ฟฐไผ ้็ป OpenAI API๏ผ่ฟๆtitle
ๅฑๆงๅๅๆฐๆ่ฟฐใๅฆๆ LLM ๅณๅฎไฝฟ็จๆจ็ๅฝๆฐ๏ผๅฐ่ฐ็จexecute
ๅฝๆฐใๅจ่ฟ็งๆ
ๅตไธ๏ผๆไปฌๅ
่ฎธ LLM ๅจๆไปฌ็็ณป็ปไธญๆง่กไปปไฝ Shell ๅฝไปคใ็ฑไบๆไปฌ่ฟๅไบๅฝไปค็่พๅบ๏ผLLM ๅฐ่ฝๅคๅๆๅฎๅนถๅณๅฎๆฏๅฆ้ๅๆ็คบใไปฅไธๆฏ LLM ๅฏ่ฝๆง่ก่ฏฅๅฝๆฐ็็คบไพ:
sgpt "ๆฅ็ /tmp ๆไปถๅคนไธญ็ๆไปถๆๅชไบ?"
# -> @FunctionCall execute_shell_command(shell_command="ls /tmp")
# -> /tmp ๆไปถๅคนๅ
ๅซไปฅไธๆไปถๅ็ฎๅฝ:
# -> test.txt
# -> test.json
่ฏทๆณจๆ๏ผๅฆๆ็ฑไบๆ็งๅๅ ๅฝๆฐ๏ผexecute_shell_command๏ผ่ฟๅ้่ฏฏ๏ผLLM ๅฏ่ฝไผๆ นๆฎ่พๅบๅฐ่ฏๅฎๆไปปๅกใๅ่ฎพๆไปฌ็็ณป็ปไธญๆฒกๆๅฎ่ฃ
jq
๏ผๆไปฌ่ฆๆฑ LLM ่งฃๆ JSON ๆไปถ:
sgpt "ไฝฟ็จ jq ่งฃๆ /tmp/test.json ๆไปถๅนถไป
่ฟๅ email ๅผ"
# -> @FunctionCall execute_shell_command(shell_command="jq -r '.email' /tmp/test.json")
# -> ็่ตทๆฅ็ณป็ปไธญๆฒกๆๅฎ่ฃ
jqใ่ฎฉๆ่ฏ็ไฝฟ็จ brew ๅฎ่ฃ
ๅฎใ
# -> @FunctionCall execute_shell_command(shell_command="brew install jq")
# -> jq ๅทฒๆๅๅฎ่ฃ
ใ่ฎฉๆๅๆฌกๅฐ่ฏ่งฃๆๆไปถใ
# -> @FunctionCall execute_shell_command(shell_command="jq -r '.email' /tmp/test.json")
# -> /tmp/test.json ไธญ็ email ๅผๆฏ johndoe@exampleใ
่ฟๅฏไปฅๅจๆ็คบไธญ้พๆฅๅคไธชๅฝๆฐ่ฐ็จ:
sgpt "ๆญๆพ้ณไนๅนถๆๅผ้ปๅฎขๆฐ้ป"
# -> @FunctionCall play_music()
# -> @FunctionCall open_url(url="https://news.ycombinator.com")
# -> ้ณไนๆญฃๅจๆญๆพ๏ผๅนถไธ้ปๅฎขๆฐ้ปๅทฒๅจๆจ็ๆต่งๅจไธญๆๅผใไบซๅๅง๏ผ
่ฟๅชๆฏไธไธช็ฎๅ็็คบไพ๏ผไป็ปไบๅฆไฝไฝฟ็จๅฝๆฐ่ฐ็จใๅฎๆฏไธไธช็ๆญฃๅผบๅคง็ๅ่ฝ๏ผๅฏ็จไบๅฎๆๅ็งๅคๆ็ไปปๅกใๆไปฌๅจ GitHub ่ฎจ่ฎบไธญไธ้จ่ฎพๆไธไธช็ฑปๅซ ็จไบๅ ฑไบซๅ่ฎจ่ฎบๅฝๆฐใ LLM ๅฏ่ฝๆง่ก็ ดๅๆงๅฝไปค๏ผ่ฏท่ช่กๆฟๆ ้ฃ้ฉโ๏ธ
ShellGPT ๅ
่ฎธไฝ ๅๅปบ่ชๅฎไน่ง่ฒ๏ผ็จไบ็ๆไปฃ็ ใshell ๅฝไปคๆๆปก่ถณไฝ ็็นๅฎ้ๆฑใ่ฆๅๅปบๆฐ่ง่ฒ๏ผไฝฟ็จ--create-role
้้กนๅ่ท่ง่ฒๅ็งฐใไฝ ๅฐ่ขซ่ฆๆฑๆไพ่ง่ฒ็ๆ่ฟฐไปฅๅๅ
ถไป็ป่ใ่ฟๅฐๅจ~/.config/shell_gpt/roles
็ฎๅฝไธๅๅปบไธไธชไปฅ่ง่ฒๅ็งฐๅฝๅ็ JSON ๆไปถใๅจ่ฟไธช็ฎๅฝไธญ๏ผไฝ ่ฟๅฏไปฅ็ผ่พ้ป่ฎค็sgpt
่ง่ฒ๏ผๅฆ shellใcode ๅ defaultใไฝฟ็จ--list-roles
้้กนๅๅบๆๆๅฏ็จ่ง่ฒ๏ผไฝฟ็จ--show-role
้้กนๆพ็คบ็นๅฎ่ง่ฒ็่ฏฆ็ปไฟกๆฏใไธ้ขๆฏไธไธช่ชๅฎไน่ง่ฒ็็คบไพ๏ผ
sgpt --create-role json_generator
# ่พๅ
ฅ่ง่ฒๆ่ฟฐ๏ผๅชๆไพๆๆ็ JSON ไฝไธบๅๅบใ
sgpt --role json_generator "random: user, password, email, address"
{
"user": "JohnDoe",
"password": "p@ssw0rd",
"email": "[email protected]",
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
}
ๅฆๆ่ง่ฒ็ๆ่ฟฐไธญๅ ๅซ"APPLY MARKDOWN"๏ผๅบๅๅคงๅฐๅ๏ผไธ่ฏ๏ผๅ่ๅคฉๅฐไปฅ Markdown ๆ ผๅผๆพ็คบใ
ไฝฟ็จ--cache
๏ผ้ป่ฎค๏ผๅ--no-cache
้้กนๆฅๆงๅถ็ผๅญใ่ฟไธช็ผๅญ้็จไบๆๆๅฏน OpenAI API ็sgpt
่ฏทๆฑ๏ผ
sgpt "what are the colors of a rainbow"
# -> The colors of a rainbow are red, orange, yellow, green, blue, indigo, and violet.
ไธๆฌก๏ผ็ธๅ็ๆฅ่ฏขๅฐไปๆฌๅฐ็ผๅญไธญ็ซๅณ่ทๅ็ปๆใๆณจๆ๏ผsgpt "what are the colors of a rainbow" --temperature 0.5
ๅฐๅ่ตทไธไธชๆฐ็่ฏทๆฑ๏ผๅ ไธบๆไปฌๆฒกๆๅจไธๆฌก่ฏทๆฑไธญๆไพ--temperature
๏ผ--top-probability
ไนๆฏๅฆๆญค๏ผใ
่ฟๅชๆฏไธไบไฝฟ็จ OpenAI GPT ๆจกๅ็็คบไพ๏ผๆ็ธไฟกไฝ ไผๅ็ฐๅจไฝ ็็นๅฎ็จไพไธญๅฎ้ๅธธๆ็จใ
ไฝ ๅฏไปฅๅจ่ฟ่กๆถ้
็ฝฎๆไปถ~/.config/shell_gpt/.sgptrc
ไธญ่ฎพ็ฝฎไธไบๅๆฐ๏ผ
# API ๅฏ้ฅ๏ผไนๅฏไปฅไฝฟ็จ OPENAI_API_KEY ็ฏๅขๅ้ๅฎไนใ
OPENAI_API_KEY=your_api_key
# ๅ็ซฏๆๅกๅจ็ๅบๆฌ URLใๅฆๆไธบ"default"๏ผๅฐๆ นๆฎ --model ่งฃๆ URLใ
API_BASE_URL=default
# ๆฏไธช่ๅคฉไผ่ฏไธญ็ผๅญ็ๆๅคงๆถๆฏๆฐ้ใ
CHAT_CACHE_LENGTH=100
# ่ๅคฉ็ผๅญๆไปถๅคนใ
CHAT_CACHE_PATH=/tmp/shell_gpt/chat_cache
# ่ฏทๆฑ็ผๅญ้ฟๅบฆ๏ผๆฐ้๏ผใ
CACHE_LENGTH=100
# ่ฏทๆฑ็ผๅญๆไปถๅคนใ
CACHE_PATH=/tmp/shell_gpt/cache
# ่ฏทๆฑ่ถ
ๆถๆถ้ด๏ผ็ง๏ผใ
REQUEST_TIMEOUT=60
# ้ป่ฎคไฝฟ็จ็ OpenAI ๆจกๅใ
DEFAULT_MODEL=gpt-3.5-turbo
# shell ๅ code ๅฎๆ็้ป่ฎค้ข่ฒใ
DEFAULT_COLOR=magenta
# ๅฝๅคไบ --shell ๆจกๅผๆถ๏ผ้ป่ฎคไธบไธ่พๅ
ฅใ
DEFAULT_EXECUTE_SHELL_CMD=false
# ็ฆ็จๅๅบ็ๆตๅผไผ ่พ
DISABLE_STREAMING=false
# ็จไบๆฅ็ Markdown ็ pygment ไธป้ข๏ผ้ป่ฎค / ๆ่ฟฐ่ง่ฒ๏ผใ
CODE_THEME=default
# ๅ
ๅซๅฝๆฐ็็ฎๅฝ่ทฏๅพใ
OPENAI_FUNCTIONS_PATH=/Users/user/.config/shell_gpt/functions
# ไฝฟ็จๅฝๆฐๆถๆๅฐๅฝๆฐ็่พๅบใ
SHOW_FUNCTIONS_OUTPUT=false
# ๅ
่ฎธ LLM ไฝฟ็จๅฝๆฐใ
OPENAI_USE_FUNCTIONS=true
# ๅผบๅถไฝฟ็จ LiteLLM๏ผ็จไบๆฌๅฐ LLM๏ผใ
USE_LITELLM=false
DEFAULT_COLOR
็ๅฏ่ฝ้้กน๏ผblackใredใgreenใyellowใblueใmagentaใcyanใwhiteใbright_blackใbright_redใbright_greenใbright_yellowใbright_blueใbright_magentaใbright_cyanใbright_whiteใ
CODE_THEME
็ๅฏ่ฝ้้กน๏ผhttps://pygments.org/styles/
โญโ Arguments โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ prompt [PROMPT] The prompt to generate completions for. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --model TEXT Large language model to use. [default: gpt-4-1106-preview] โ
โ --temperature FLOAT RANGE [0.0<=x<=2.0] Randomness of generated output. [default: 0.0] โ
โ --top-p FLOAT RANGE [0.0<=x<=1.0] Limits highest probable tokens (words). [default: 1.0] โ
โ --md --no-md Prettify markdown output. [default: md] โ
โ --editor Open $EDITOR to provide a prompt. [default: no-editor] โ
โ --cache Cache completion results. [default: cache] โ
โ --version Show version. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Assistance Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --shell -s Generate and execute shell commands. โ
โ --interaction --no-interaction Interactive mode for --shell option. [default: interaction] โ
โ --describe-shell -d Describe a shell command. โ
โ --code -c Generate only code. โ
โ --functions --no-functions Allow function calls. [default: functions] โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Chat Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --chat TEXT Follow conversation with id, use "temp" for quick session. [default: None] โ
โ --repl TEXT Start a REPL (Readโevalโprint loop) session. [default: None] โ
โ --show-chat TEXT Show all messages from provided chat id. [default: None] โ
โ --list-chats -lc List all existing chat ids. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Role Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --role TEXT System role for GPT model. [default: None] โ
โ --create-role TEXT Create role. [default: None] โ
โ --show-role TEXT Show role. [default: None] โ
โ --list-roles -lr List roles. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
ไฝฟ็จ OPENAI_API_KEY
็ฏๅขๅ้ไปฅๅๅฎนๅจๅทๆฅ่ฟ่กๅฎนๅจไปฅๅญๅจ็ผๅญ:
docker run --rm \
--env OPENAI_API_KEY="ไฝ ็ OPENAI API ๅฏ้ฅ" \
--volume gpt-cache:/tmp/shell_gpt \
ghcr.io/ther1d/shell_gpt --chat rainbow "what are the colors of a rainbow"
ไฝฟ็จๅซๅๅ OPENAI_API_KEY
็ฏๅขๅ้็ๅฏน่ฏ็คบไพ:
alias sgpt="docker run --rm --env OPENAI_API_KEY --volume gpt-cache:/tmp/shell_gpt ghcr.io/ther1d/shell_gpt"
export OPENAI_API_KEY="ไฝ ็ OPENAI API ๅฏ้ฅ"
sgpt --chat rainbow "what are the colors of a rainbow"
sgpt --chat rainbow "inverse the list of your last answer"
sgpt --chat rainbow "translate your last answer in french"
ไฝ ่ฟๅฏไปฅไฝฟ็จๆไพ็ Dockerfile
ๆฅๆๅปบ่ชๅทฑ็้ๅ:
docker build -t sgpt .
้ๅ ๆๆกฃ: Azure ้ๆ, Ollama ้ๆ.