เครื่องมือการผลิตบรรทัดคำสั่งที่ขับเคลื่อนโดย AI Models Language Language (LLM) เครื่องมือบรรทัดคำสั่งนี้นำเสนอการสร้าง คำสั่งเชลล์ที่มีความคล่องตัว, ตัวอย่างโค้ด, เอกสาร , ไม่จำเป็นต้องใช้ทรัพยากรภายนอก (เช่นการค้นหาของ Google) รองรับ Linux, MacOS, Windows และเข้ากันได้กับเปลือกหอยที่สำคัญทั้งหมดเช่น PowerShell, CMD, Bash, ZSH ฯลฯ
pip install shell-gpt โดยค่าเริ่มต้น ShellGPT ใช้โมเดล API และ GPT-4 ของ OpenAI คุณจะต้องมีคีย์ API คุณสามารถสร้างได้ที่นี่ คุณจะได้รับแจ้งสำหรับคีย์ของคุณซึ่งจะถูกเก็บไว้ใน ~/.config/shell_gpt/.sgptrc OpenAI API ไม่เสียค่าใช้จ่ายโปรดดูราคา OpenAI สำหรับข้อมูลเพิ่มเติม
เคล็ดลับ
หรือคุณสามารถใช้โมเดลโอเพนซอร์ซโฮสต์ที่โฮสต์ซึ่งมีให้บริการฟรี ในการใช้โมเดลท้องถิ่นคุณจะต้องเรียกใช้เซิร์ฟเวอร์แบ็กเอนด์ LLM ของคุณเองเช่น Ollama หากต้องการตั้งค่า Shellgpt กับ Ollama โปรดทำตามคำแนะนำที่ครอบคลุมนี้
❗หมายเหตุว่า ShellGPT ไม่ได้รับการปรับให้เหมาะสมสำหรับรุ่นท้องถิ่นและอาจไม่ทำงานตามที่คาดไว้
Shellgpt ได้รับการออกแบบมาเพื่อวิเคราะห์และดึงข้อมูลได้อย่างรวดเร็ว มันมีประโยชน์สำหรับการร้องขอที่ตรงไปตรงมาตั้งแต่การกำหนดค่าทางเทคนิคไปจนถึงความรู้ทั่วไป
sgpt " What is the fibonacci sequence "
# -> The Fibonacci sequence is a series of numbers where each number ... Shellgpt ยอมรับพรอมต์จากทั้ง stdin และอาร์กิวเมนต์บรรทัดคำสั่ง ไม่ว่าคุณจะชอบอินพุตท่อผ่านเทอร์มินัลหรือระบุโดยตรงเป็นอาร์กิวเมนต์ sgpt ให้คุณครอบคลุม ตัวอย่างเช่นคุณสามารถสร้างข้อความ GIT COMMIT ตามความแตกต่างได้อย่างง่ายดาย:
git diff | sgpt " Generate git commit message, for my changes "
# -> Added main feature details into README.mdคุณสามารถวิเคราะห์บันทึกจากแหล่งต่าง ๆ โดยผ่านพวกเขาโดยใช้ stdin พร้อมกับพรอมต์ ตัวอย่างเช่นเราสามารถใช้เพื่อวิเคราะห์บันทึกระบุข้อผิดพลาดและรับคำแนะนำสำหรับการแก้ปัญหาที่เป็นไปได้อย่างรวดเร็ว:
docker logs -n 20 my_app | sgpt " check logs, find errors, provide possible solutions " Error Detected: Connection timeout at line 7.
Possible Solution: Check network connectivity and firewall settings.
Error Detected: Memory allocation failed at line 12.
Possible Solution: Consider increasing memory allocation or optimizing application memory usage.
นอกจากนี้คุณยังสามารถใช้ตัวดำเนินการเปลี่ยนเส้นทางทุกชนิดเพื่อส่งผ่านอินพุต:
sgpt " summarise " < document.txt
# -> The document discusses the impact...
sgpt << EOF
What is the best way to lear Golang?
Provide simple hello world example.
EOF
# -> The best way to learn Golang...
sgpt <<< " What is the best way to learn shell redirects? "
# -> The best way to learn shell redirects is through... คุณเคยพบว่าตัวเองลืมคำสั่งเชลล์ทั่วไปเช่น find และจำเป็นต้องค้นหาไวยากรณ์ออนไลน์หรือไม่? ด้วยตัวเลือก --shell หรือ -s ลัดคุณสามารถสร้างและดำเนินการคำสั่งที่คุณต้องการได้อย่างรวดเร็วในเทอร์มินัล
sgpt --shell " find all json files in current folder "
# -> find . -type f -name "*.json"
# -> [E]xecute, [D]escribe, [A]bort: e เชลล์ GPT ตระหนักถึง OS และ $SHELL ที่คุณใช้มันจะให้คำสั่งเชลล์สำหรับระบบเฉพาะที่คุณมี ตัวอย่างเช่นหากคุณขอให้ sgpt อัปเดตระบบของคุณมันจะส่งคืนคำสั่งตามระบบปฏิบัติการของคุณ นี่คือตัวอย่างการใช้ MacOS:
sgpt -s " update my system "
# -> sudo softwareupdate -i -a
# -> [E]xecute, [D]escribe, [A]bort: eพรอมต์เดียวกันเมื่อใช้กับ Ubuntu จะสร้างคำแนะนำที่แตกต่างกัน:
sgpt -s " update my system "
# -> sudo apt update && sudo apt upgrade -y
# -> [E]xecute, [D]escribe, [A]bort: eลองกับ Docker:
sgpt -s " start nginx container, mount ./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 และสร้างคำสั่งเชลล์:
sgpt -s " POST localhost with " < data.json
# -> curl -X POST -H "Content-Type: application/json" -d '{"a": 1, "b": 2}' http://localhost
# -> [E]xecute, [D]escribe, [A]bort: e ใช้เวทมนตร์เชลล์เพิ่มเติมในพรอมต์ของเราในตัวอย่างนี้ส่งชื่อไฟล์ไปยัง ffmpeg :
ls
# -> 1.mp4 2.mp4 3.mp4
sgpt -s " ffmpeg combine $( ls -m ) into one video file without audio. "
# -> 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 หากคุณต้องการผ่านคำสั่งเชลล์ที่สร้างขึ้นโดยใช้ท่อคุณสามารถใช้ --no-interaction สิ่งนี้จะปิดการใช้งานโหมดอินเทอร์แอคทีฟและจะพิมพ์คำสั่งที่สร้างขึ้นเป็น stdout ในตัวอย่างนี้เราใช้ pbcopy เพื่อคัดลอกคำสั่งที่สร้างไปยังคลิปบอร์ด:
sgpt -s " find all json files in current folder " --no-interaction | pbcopy นี่เป็น คุณสมบัติที่มีประโยชน์มาก ซึ่งช่วยให้คุณสามารถใช้ sgpt Shell Completions โดยตรงในเทอร์มินัลของคุณโดยไม่จำเป็นต้องพิมพ์ sgpt ด้วยพรอมต์และอาร์กิวเมนต์ การรวมเชลล์ช่วยให้สามารถใช้งาน ShellGPT กับปุ่มลัดในเทอร์มินัลของคุณได้รับการสนับสนุนโดย Shell ทั้ง Bash และ ZSH คุณลักษณะนี้ทำให้ sgpt เสร็จสมบูรณ์โดยตรงในบัฟเฟอร์เทอร์มินัล (อินพุตบรรทัด) ช่วยให้สามารถแก้ไขคำสั่งที่แนะนำได้ทันที
ในการติดตั้งการรวมเชลล์ให้เรียกใช้ sgpt --install-integration และรีสตาร์ทเทอร์มินัลของคุณเพื่อใช้การเปลี่ยนแปลง สิ่งนี้จะเพิ่มไม่กี่บรรทัดในไฟล์ .bashrc หรือ .zshrc ของคุณ หลังจากนั้นคุณสามารถใช้ Ctrl+l (โดยค่าเริ่มต้น) เพื่อเรียกใช้ shellgpt เมื่อคุณกด Ctrl+l มันจะแทนที่บรรทัดอินพุตปัจจุบันของคุณ (บัฟเฟอร์) ด้วยคำสั่งที่แนะนำ จากนั้นคุณสามารถแก้ไขและเพียงกด Enter เพื่อดำเนินการ
โดยใช้พารามิเตอร์ --code หรือ -c คุณสามารถร้องขอเอาต์พุตรหัสบริสุทธิ์เป็นพิเศษได้เช่น:
sgpt --code " solve fizz buzz problem using python " 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 " solve classic fizz buzz problem using Python " > fizz_buzz.py
python fizz_buzz.py
# 1
# 2
# Fizz
# 4
# Buzz
# ...นอกจากนี้เรายังสามารถใช้ท่อเพื่อส่งผ่านอินพุต:
cat fizz_buzz.py | sgpt --code " Generate comments for each line of my code " # Loop through numbers 1 to 100
for i in range ( 1 , 101 ):
# Check if number is divisible by both 3 and 5
if i % 3 == 0 and i % 5 == 0 :
# Print "FizzBuzz" if number is divisible by both 3 and 5
print ( "FizzBuzz" )
# Check if number is divisible by 3
elif i % 3 == 0 :
# Print "Fizz" if number is divisible by 3
print ( "Fizz" )
# Check if number is divisible by 5
elif i % 5 == 0 :
# Print "Buzz" if number is divisible by 5
print ( "Buzz" )
# If number is not divisible by 3 or 5, print the number itself
else :
print ( i ) บ่อยครั้งที่มันเป็นสิ่งสำคัญที่จะต้องรักษาและเรียกคืนการสนทนา sgpt สร้างบทสนทนาการสนทนาด้วยการร้องเรียน LLM แต่ละครั้ง บทสนทนาสามารถพัฒนาหนึ่งต่อหนึ่ง (โหมดแชท) หรือโต้ตอบในการแก้ไขลูป (โหมดแทนที่) ทั้งสองวิธีขึ้นอยู่กับวัตถุพื้นฐานเดียวกันเรียกว่าเซสชั่นแชท เซสชันตั้งอยู่ที่ CHAT_CACHE_PATH ที่กำหนดค่าได้
ในการเริ่มต้นการสนทนาให้ใช้ตัวเลือก --chat ตามด้วยชื่อเซสชันที่ไม่ซ้ำกันและพรอมต์
sgpt --chat conversation_1 " please remember my favorite number: 4 "
# -> I will remember that your favorite number is 4.
sgpt --chat conversation_1 " what would be my favorite number + 4? "
# -> Your favorite number is 4, so if we add 4 to it, the result would be 8. คุณสามารถใช้เซสชันแชทเพื่อปรับปรุงคำแนะนำ GPT ซ้ำ ๆ โดยให้รายละเอียดเพิ่มเติม เป็นไปได้ที่จะใช้ตัวเลือก --code หรือ --shell เพื่อเริ่ม --chat :
sgpt --chat conversation_2 --code " make a request to localhost using python " import requests
response = requests . get ( 'http://localhost' )
print ( response . text )ขอให้ LLM เพิ่มแคชให้กับคำขอของเรา:
sgpt --chat conversation_2 --code " add caching " import requests
from cachecontrol import CacheControl
sess = requests . session ()
cached_sess = CacheControl ( sess )
response = cached_sess . get ( 'http://localhost' )
print ( response . text )เช่นเดียวกับคำสั่งเชลล์:
sgpt --chat conversation_3 --shell " what is in current folder "
# -> ls
sgpt --chat conversation_3 " Sort by name "
# -> ls | sort
sgpt --chat conversation_3 " Concatenate them using FFMPEG "
# -> ffmpeg -i "concat:$(ls | sort | tr 'n' '|')" -codec copy output.mp4
sgpt --chat conversation_3 " Convert the resulting file into an 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: please remember my favorite number: 4
# assistant: I will remember that your favorite number is 4.
# user: what would be my favorite number + 4?
# assistant: Your favorite number is 4, so if we add 4 to it, the result would be 8. มีโหมด REPL ที่มีประโยชน์มาก (Read - Eval - Print Loop) ซึ่งช่วยให้คุณสามารถแชทกับรุ่น GPT ได้ ในการเริ่มต้นเซสชันการแชทในโหมด REPL ให้ใช้ตัวเลือก --repl ตามด้วยชื่อเซสชันที่ไม่ซ้ำกัน นอกจากนี้คุณยังสามารถใช้ "อุณหภูมิ" เป็นชื่อเซสชันเพื่อเริ่มเซสชัน Repl ชั่วคราว โปรดทราบว่า --chat และ --repl ใช้วัตถุพื้นฐานเดียวกันดังนั้นคุณสามารถใช้ --chat เพื่อเริ่มเซสชันการแชทแล้วหยิบมันขึ้นมาด้วย --repl เพื่อดำเนินการสนทนาในโหมด REPL ต่อ
sgpt --repl temp
Entering REPL mode, press Ctrl+C to exit.
>>> What is REPL?
REPL stands for Read-Eval-Print Loop. It is a programming environment ...
>>> How can I use Python with REPL?
To use Python with REPL, you can simply open a terminal or command prompt ...
โหมด RELP สามารถใช้งานได้กับ -ตัวเลือก --shell และ --code ซึ่งทำให้มีประโยชน์มากสำหรับคำสั่งเชลล์แบบโต้ตอบและการสร้างรหัส:
sgpt --repl temp --shell
Entering shell REPL mode, type [e] to execute commands or press Ctrl+C to exit.
>>> What is in current folder?
ls
>>> Show file sizes
ls -lh
>>> Sort them by file sizes
ls -lhS
>>> e (enter just e to execute commands, or d to describe them)
เพื่อให้การใช้คำพูดหลาย ๆ ครั้งที่มีคำสั่งสามเท่า """ ::
sgpt --repl temp
Entering REPL mode, press Ctrl+C to exit.
>>> """
... Explain following code:
... import random
... print(random.randint(1, 10))
... """
It is a Python script that uses the random module to generate and print a random integer.
นอกจากนี้คุณยังสามารถเข้าสู่โหมด REPL ด้วยพรอมต์เริ่มต้นโดยส่งเป็นอาร์กิวเมนต์หรือ stdin หรือแม้แต่ทั้งสองอย่าง::
sgpt --repl temp < my_app.py Entering REPL mode, press Ctrl+C to exit.
──────────────────────────────────── Input ────────────────────────────────────
name = input("What is your name?")
print(f"Hello {name}")
───────────────────────────────────────────────────────────────────────────────
>>> What is this code about?
The snippet of code you've provided is written in Python. It prompts the user...
>>> Follow up questions...
การเรียกใช้ฟังก์ชั่นเป็นคุณสมบัติที่ทรงพลังที่ 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 ):
"""
Executes a shell command and returns the output (result).
"""
shell_command : str = Field (..., example = "ls -la" , descriptions = "Shell command to execute." )
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"Exit code: { result . returncode } , Output: n { result . stdout } " ความคิดเห็นเอกสารภายในชั้นเรียนจะถูกส่งผ่านไปยัง OpenAI API เป็นคำอธิบายสำหรับฟังก์ชั่นพร้อมกับแอตทริบิวต์ title และคำอธิบายพารามิเตอร์ ฟังก์ชั่น execute จะถูกเรียกถ้า LLM ตัดสินใจใช้ฟังก์ชั่นของคุณ ในกรณีนี้เราอนุญาตให้ LLM ดำเนินการคำสั่งเชลล์ใด ๆ ในระบบของเรา เนื่องจากเรากำลังส่งคืนผลลัพธ์ของคำสั่ง LLM จะสามารถวิเคราะห์ได้และตัดสินใจว่ามันเหมาะสมกับพรอมต์หรือไม่ นี่คือตัวอย่างที่ฟังก์ชันอาจดำเนินการโดย LLM:
sgpt " What are the files in /tmp folder? "
# -> @FunctionCall execute_shell_command(shell_command="ls /tmp")
# -> The /tmp folder contains the following files and directories:
# -> test.txt
# -> test.json โปรดทราบว่าหากด้วยเหตุผลบางอย่างฟังก์ชั่น (Execute_Shell_Command) จะส่งคืนข้อผิดพลาด LLM อาจพยายามทำภารกิจให้สำเร็จตามผลลัพธ์ สมมติว่าเราไม่ได้ติดตั้ง jq ในระบบของเราและเราขอให้ LLM Parse JSON ไฟล์:
sgpt " parse /tmp/test.json file using jq and return only email value "
# -> @FunctionCall execute_shell_command(shell_command="jq -r '.email' /tmp/test.json")
# -> It appears that jq is not installed on the system. Let me try to install it using brew.
# -> @FunctionCall execute_shell_command(shell_command="brew install jq")
# -> jq has been successfully installed. Let me try to parse the file again.
# -> @FunctionCall execute_shell_command(shell_command="jq -r '.email' /tmp/test.json")
# -> The email value in /tmp/test.json is johndoe@example.นอกจากนี้ยังเป็นไปได้ที่จะห่วงโซ่การเรียกใช้ฟังก์ชันหลายรายการในพรอมต์:
sgpt " Play music and open hacker news "
# -> @FunctionCall play_music()
# -> @FunctionCall open_url(url="https://news.ycombinator.com")
# -> Music is now playing, and Hacker News has been opened in your browser. Enjoy!นี่เป็นเพียงตัวอย่างง่ายๆของวิธีที่คุณสามารถใช้การโทรฟังก์ชั่น มันเป็นคุณสมบัติที่ทรงพลังอย่างแท้จริงที่สามารถใช้ในการทำงานที่ซับซ้อนได้หลากหลาย เรามีหมวดหมู่โดยเฉพาะในการอภิปราย GitHub สำหรับการแบ่งปันและการอภิปรายฟังก์ชั่น LLM อาจเรียกใช้คำสั่งทำลายล้างดังนั้นโปรดใช้ตามความเสี่ยงของคุณเอง
ShellGPT ช่วยให้คุณสร้างบทบาทที่กำหนดเองซึ่งสามารถใช้เพื่อสร้างรหัสคำสั่งเชลล์หรือเพื่อตอบสนองความต้องการเฉพาะของคุณ ในการสร้างบทบาทใหม่ให้ใช้ตัวเลือก --create-role ตามด้วยชื่อบทบาท คุณจะได้รับแจ้งให้ให้คำอธิบายสำหรับบทบาทพร้อมกับรายละเอียดอื่น ๆ สิ่งนี้จะสร้างไฟล์ JSON ใน ~/.config/shell_gpt/roles ด้วยชื่อบทบาท ภายในไดเรกทอรีนี้คุณยังสามารถแก้ไขบทบาท sgpt เริ่มต้นเช่น เชลล์ รหัส และ ค่าเริ่มต้น ใช้ตัวเลือก --list-roles เพื่อแสดงรายการบทบาทที่มีอยู่ทั้งหมดและตัวเลือก --show-role เพื่อแสดงรายละเอียดของบทบาทที่เฉพาะเจาะจง นี่คือตัวอย่างของบทบาทที่กำหนดเอง:
sgpt --create-role json_generator
# Enter role description: Provide only valid json as response.
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 "
}
}หากคำอธิบายของบทบาทมีคำว่า "ใช้ markdown" (ตัวพิมพ์เล็ก) การแชทจะปรากฏขึ้นโดยใช้การจัดรูปแบบ markdown
ควบคุมแคชโดยใช้ --cache (ค่าเริ่มต้น) และ --no-cache การแคชนี้ใช้สำหรับคำขอ sgpt ทั้งหมดไปยัง OpenAI API:
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 key, also it is possible to define OPENAI_API_KEY env.
OPENAI_API_KEY=your_api_key
# Base URL of the backend server. If "default" URL will be resolved based on --model.
API_BASE_URL=default
# Max amount of cached message per chat session.
CHAT_CACHE_LENGTH=100
# Chat cache folder.
CHAT_CACHE_PATH=/tmp/shell_gpt/chat_cache
# Request cache length (amount).
CACHE_LENGTH=100
# Request cache folder.
CACHE_PATH=/tmp/shell_gpt/cache
# Request timeout in seconds.
REQUEST_TIMEOUT=60
# Default OpenAI model to use.
DEFAULT_MODEL=gpt-4o
# Default color for shell and code completions.
DEFAULT_COLOR=magenta
# When in --shell mode, default to "Y" for no input.
DEFAULT_EXECUTE_SHELL_CMD=false
# Disable streaming of responses
DISABLE_STREAMING=false
# The pygment theme to view markdown (default/describe role).
CODE_THEME=default
# Path to a directory with functions.
OPENAI_FUNCTIONS_PATH=/Users/user/.config/shell_gpt/functions
# Print output of functions when LLM uses them.
SHOW_FUNCTIONS_OUTPUT=false
# Allows LLM to use functions.
OPENAI_USE_FUNCTIONS=true
# Enforce LiteLLM usage (for local LLMs).
USE_LITELLM=false
ตัวเลือกที่เป็นไปได้สำหรับ DEFAULT_COLOR : สีดำ, สีแดง, สีเขียว, สีเหลือง, สีน้ำเงิน, สีม่วงแดง, สีฟ้า, สีขาว, 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-4o] │
│ --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 เพื่อเก็บแคช พิจารณาที่จะตั้งค่าตัวแปรสภาพแวดล้อม OS_NAME และ SHELL_NAME ตามการตั้งค่าของคุณ
docker run --rm
--env OPENAI_API_KEY=api_key
--env OS_NAME= $( uname -s )
--env SHELL_NAME= $( echo $SHELL )
--volume gpt-cache:/tmp/shell_gpt
ghcr.io/ther1d/shell_gpt -s " update my system " ตัวอย่างการสนทนาโดยใช้นามแฝงและตัวแปรสภาพแวดล้อม OPENAI_API_KEY :
alias sgpt= " docker run --rm --volume gpt-cache:/tmp/shell_gpt --env OPENAI_API_KEY --env OS_NAME= $( uname -s ) --env SHELL_NAME= $( echo $SHELL ) ghcr.io/ther1d/shell_gpt "
export OPENAI_API_KEY= " your OPENAI API key "
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 .หากคุณต้องการส่งคำขอของคุณไปยังอินสแตนซ์ของ Ollama และเรียกใช้ Shellgpt ภายในคอนเทนเนอร์ Docker คุณต้องปรับ DockerFile และสร้างคอนเทนเนอร์ด้วยตัวคุณเอง: จำเป็นต้องมีแพ็คเกจ Litellm และต้องตั้งค่าตัวแปร Env ให้ถูกต้อง
ตัวอย่าง DockerFile:
FROM python:3-slim
ENV DEFAULT_MODEL=ollama/mistral:7b-instruct-v0.2-q4_K_M
ENV API_BASE_URL=http://10.10.10.10:11434
ENV USE_LITELLM=true
ENV OPENAI_API_KEY=bad_key
ENV SHELL_INTERACTION=false
ENV PRETTIFY_MARKDOWN=false
ENV OS_NAME="Arch Linux"
ENV SHELL_NAME=auto
WORKDIR /app
COPY . /app
RUN apt-get update && apt-get install -y gcc
RUN pip install --no-cache /app[litellm] && mkdir -p /tmp/shell_gpt
VOLUME /tmp/shell_gpt
ENTRYPOINT ["sgpt"]