Skip to content
forked from TheR1D/shell_gpt

A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.

License

Notifications You must be signed in to change notification settings

DBinK/shell_gpt

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

96 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ShellGPT

ไธ€ไธช็”ฑ 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

Shell integration

่ฟ™ๆ˜ฏไธ€ไธช้žๅธธๆ–นไพฟ็š„ๅŠŸ่ƒฝ๏ผŒๅฎƒๅ…่ฎธๆ‚จๅœจ็ปˆ็ซฏไธญ็›ดๆŽฅไฝฟ็”จ 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 ๆจกๅผ

ๆœ‰ไธ€ไธช้žๅธธๆ–นไพฟ็š„ REPL๏ผˆ่ฏปๅ– - ๆฑ‚ๅ€ผ - ๆ‰“ๅฐๅพช็Žฏ๏ผ‰ๆจกๅผ๏ผŒๅฎƒๅ…่ฎธๆ‚จไธŽ GPT ๆจกๅž‹่ฟ›่กŒไบคไบ’ๅผ่Šๅคฉใ€‚่ฆๅœจ REPL ๆจกๅผไธ‹ๅผ€ๅง‹ไธ€ไธช่Šๅคฉไผš่ฏ๏ผŒ่ฏทไฝฟ็”จ --repl ้€‰้กนๅŽ้ข่ทŸไธ€ไธชๅ”ฏไธ€็š„ไผš่ฏๅ็งฐใ€‚ๆ‚จ่ฟ˜ๅฏไปฅไฝฟ็”จ "temp" ไฝœไธบไผš่ฏๅ็งฐๆฅๅฏๅŠจไธดๆ—ถ REPL ไผš่ฏใ€‚่ฏทๆณจๆ„๏ผŒ--chat ๅ’Œ --repl ไฝฟ็”จ็›ธๅŒ็š„ๅบ•ๅฑ‚ๅฏน่ฑก๏ผŒๅ› ๆญคๆ‚จๅฏไปฅไฝฟ็”จ --chat ๆฅๅฏๅŠจไธ€ไธช่Šๅคฉไผš่ฏ๏ผŒ็„ถๅŽไฝฟ็”จ --repl ๆฅ็ปง็ปญๅœจ REPL ๆจกๅผไธ‹่ฟ›่กŒๅฏน่ฏใ€‚

gif

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.                                                                โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Docker

ไฝฟ็”จ 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 ้›†ๆˆ.

About

A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.4%
  • Other 0.6%