SGPT ( aka shell-gpt ) เป็นเครื่องมืออินเตอร์เฟสบรรทัดคำสั่งที่ทรงพลัง (CLI) ที่ออกแบบมาสำหรับการโต้ตอบอย่างราบรื่นกับโมเดล OpenAI โดยตรงจากเทอร์มินัลของคุณ เรียกใช้แบบสอบถามอย่างง่ายดายสร้างคำสั่งเชลล์หรือรหัสสร้างภาพจากข้อความและอื่น ๆ โดยใช้คำสั่งง่ายๆ ปรับปรุงเวิร์กโฟลว์ของคุณและเพิ่มประสิทธิภาพการทำงานด้วยเครื่องมือ CLI ที่ทรงพลังและใช้งานง่ายนี้
พัฒนาขึ้นด้วยความช่วยเหลือของ SGPT
นี่คือการใช้งาน GO สำหรับการใช้งาน Python ดั้งเดิมเยี่ยมชม Shell-GPT โปรดจำไว้ว่าเมื่อมีการรายงานปัญหา
หมายเหตุ: ปัจจุบันอยู่ภายใต้การปรับโครงสร้างอย่างหนักสำหรับ V3 แต่ V2 ยังคงอยู่
ด้วยการนำเสนอคุณสมบัติที่หลากหลายเหล่านี้ SGPT ทำหน้าที่เป็นเครื่องมือที่ทรงพลังในการเพิ่มประสิทธิภาพการทำงานโดยรวมของคุณปรับปรุงเวิร์กโฟลว์ของคุณและทำให้งานที่ซับซ้อนง่ายขึ้น
SGPT ได้รับการทดสอบในการเปิดตัว Ubuntu LTS และคาดว่าจะเข้ากันได้กับการแจกแจง Linux ต่อไปนี้:
ในการติดตั้งให้ดาวน์โหลดรีลีสล่าสุดจากหน้ารีลีสและใช้แพ็คเกจจัดการเฉพาะเพื่อแจกจ่ายของคุณ
สำหรับผู้ใช้ที่มี Homebrew เป็นผู้จัดการแพ็คเกจให้เรียกใช้คำสั่งต่อไปนี้ในเทอร์มินัล:
brew install tbckr/tap/sgptสำหรับผู้ใช้ที่มี Scoop เป็นตัวจัดการแพ็คเกจให้ดำเนินการคำสั่งเหล่านี้ใน PowerShell:
scoop bucket add tbckr https://github.com/tbckr/scoop-bucket.git
scoop install tbckr/sgptในการติดตั้ง SGPT ด้วย GO ตามแท็ก GIT ให้ใช้คำสั่งนี้:
go install github.com/tbckr/sgpt/v2/cmd/sgpt@latestในการเรียกใช้ SGPT ด้วย Docker ให้ใช้คำสั่งต่อไปนี้เพื่อดึงภาพล่าสุด:
docker pull ghcr.io/tbckr/sgpt:latestตัวอย่างเกี่ยวกับวิธีการใช้ SGPT กับ Docker สามารถพบได้ที่นี่
ในการติดตั้ง SGPT ด้วย Ansible คุณสามารถใช้ playbook ansible ต่อไปนี้เป็นฐานของคุณและปรับตาม:
---
- hosts : all
tasks :
- name : Get latest sgpt release
uri :
url : " https://api.github.com/repos/tbckr/sgpt/releases/latest "
return_content : yes
register : sgpt_release
- name : Set latest version of sgpt
set_fact :
sgpt_latest_version : " {{ sgpt_release.json.tag_name }} "
- name : Install sgpt for debian based, amd64 systems
ansible.builtin.apt :
deb : https://github.com/tbckr/sgpt/releases/download/{{ sgpt_latest_version }}/sgpt_{{ sgpt_latest_version[1:] }}_amd64.deb
allow_unauthenticated : trueplaybook สามารถเรียกใช้ด้วยคำสั่งต่อไปนี้:
ansible-playbook -i < inventory > < playbook > .ymlPlaybook เวอร์ชันล่าสุดสามารถพบได้ที่นี่
สำหรับแพลตฟอร์มอื่น ๆ โปรดไปที่หน้า GitHub Release และดาวน์โหลดรุ่นล่าสุดที่เหมาะสำหรับระบบของคุณ
ดูเอกสารสำหรับคำแนะนำการใช้โดยละเอียด
ในการใช้ OpenAI API คุณต้องได้รับคีย์ API ก่อน
.bashrc หรือ .zshrc ของคุณเพื่อรวมคำสั่งส่งออกต่อไปนี้เพิ่มคีย์ API ของคุณเป็นค่า: export OPENAI_API_KEY= " sk-... "OPENAI_API_KEY ด้วยคีย์ API ของคุณเป็นค่าหลังจากทำตามขั้นตอนเหล่านี้เสร็จแล้วคุณจะมีคีย์ OpenAI API ที่สามารถใช้ในการโต้ตอบกับโมเดล OpenAI ผ่านเครื่องมือ SGPT
หมายเหตุ: คีย์ API ของคุณเป็นข้อมูลที่ละเอียดอ่อน อย่าแบ่งปันกับใคร
SGPT ช่วยให้คุณถามคำถามง่ายๆและรับคำตอบที่ให้ข้อมูล ตัวอย่างเช่น:
$ sgpt " mass of sun "
The mass of the sun is approximately 1.989 x 10^30 kilograms.นอกจากนี้คุณยังสามารถส่งพรอมต์ไปยัง SGPT โดยใช้ท่อ:
$ echo -n " mass of sun " | sgpt
The mass of the sun is approximately 1.989 x 10^30 kilograms. นอกจากนี้คุณยังสามารถเพิ่มพรอมต์อื่นลงในข้อมูล PIPED โดยการระบุตัวดัดแปลง stdin จากนั้นระบุพรอมต์:
$ echo " Say: Hello World! " | sgpt stdin ' Replace every "World" word with "ChatGPT" '
Hello ChatGPT ! หากคุณต้องการสตรีมให้เสร็จสิ้นไปยังบรรทัดคำสั่งคุณสามารถเพิ่ม --stream สตรีมธง สิ่งนี้จะสตรีมเอาต์พุตไปยังบรรทัดคำสั่งตามที่สร้างขึ้น
SGPT ยังช่วยอำนวยความสะดวกในการใช้ประโยชน์จาก GPT-4O และ GPT-4 Vision API รวมภาพอินพุตโดยใช้ค่าสถานะ -i หรือ --input อินพุตรองรับทั้ง URL และรูปภาพท้องถิ่น
$ sgpt -m " gpt-4o " -i pkg/fs/testdata/marvin.jpg " what can you see on the picture? "
The picture shows a robot with a large, round head and an expressive, downward-slanting triangular eye. The body of the robot is designed with a sleek, somewhat shiny, metallic structure and it is pointing with its right hand. The design appears to be humanoid with distinct arms, legs, and a segmented torso.
$ sgpt -m " gpt-4-vision-preview " -i " https://upload.wikimedia.org/wikipedia/en/c/cb/Marvin_%28HHGG%29.jpg " " what can you see on the picture? "
The image shows a figure resembling a robot with a humanoid form. It has aนอกจากนี้ยังเป็นไปได้ที่จะรวม URL และรูปภาพท้องถิ่น:
$ sgpt -m " gpt-4o " -i " https://upload.wikimedia.org/wikipedia/en/c/cb/Marvin_%28HHGG%29.jpg " -i pkg/fs/testdata/marvin.jpg " what is the difference between those two pictures "
The two pictures you provided appear to be identical. There are no visible differences between them. Both show the same character in the same pose with the same lighting and background.นอกจากนี้คุณยังสามารถตั้งค่าโมเดลเริ่มต้นเป็น GPT-4O หรือ GPT-4 Vision โดยการตั้งค่าในไฟล์กำหนดค่า
สำคัญ: การรวม API GPT-4O และ GPT-4-Vision API อยู่ในช่วงเบต้าและอาจเปลี่ยนแปลงในอนาคต
หากคุณได้รับการอนุญาตสำหรับ O1 API อยู่แล้วคุณสามารถใช้งานได้โดยระบุโมเดลด้วยธง -m คุณต้องให้ --stream=false เท็จตั้งค่าสถานะเพื่อไม่สตรีมเอาต์พุตเนื่องจากไม่ได้รับการสนับสนุนโดย O1 API (นี่เป็นสิ่งจำเป็นเท่านั้นหากคุณได้ให้ตัวเลือกสตรีมผ่านไฟล์กำหนดค่า)
ตัวอย่าง:
$ sgpt -m " o1-preview " --stream=false " how many rs are in strawberry? "
There are three " r " s in the word " strawberry " . คุณยังสามารถสร้างนามแฝงทุบตีเพื่อใช้ O1 API ได้ง่ายขึ้น ตัวอย่างเช่นเพิ่มบรรทัดต่อไปนี้ใน .bashrc :
alias sgpt-o1= " sgpt -m " o1-preview " --stream=false "จากนั้นคุณสามารถใช้นามแฝงเช่นนี้:
$ sgpt-o1 " how many rs are in strawberry? "
There are three " r " s in the word " strawberry " .สำคัญ: O1 API ไม่สนับสนุนบุคคล
SGPT มีฟังก์ชั่นการแชทที่ช่วยให้การสนทนาแบบโต้ตอบกับโมเดล OpenAI คุณสามารถใช้ธง --chat เพื่อเริ่มต้นและอ้างอิงเซสชันการแชท
ความสามารถในการแชทช่วยให้คุณสามารถโต้ตอบกับโมเดล OpenAI ในแบบไดนามิกและมีส่วนร่วมมากขึ้นทำให้ง่ายต่อการได้รับคำตอบที่เกี่ยวข้องรหัสหรือคำสั่งเชลล์ผ่านการสนทนาอย่างต่อเนื่อง
ตัวอย่างด้านล่างแสดงให้เห็นถึงวิธีการปรับแต่งการตอบสนองของโมเดลสำหรับผลลัพธ์ที่ตรงเป้าหมายมากขึ้น
ls-files และขอให้โมเดล "แสดงรายการไดเรกทอรีไฟล์ทั้งหมด": $ sgpt sh --chat ls-files " list all files directory "
lsls-files และขอให้ "เรียงลำดับตามชื่อ": $ sgpt sh --chat ls-files " sort by name "
ls | sort โมเดลให้คำสั่งเชลล์ที่เหมาะสม ls | sort ซึ่งแสดงรายการไฟล์ทั้งหมดในไดเรกทอรีและเรียงลำดับตามชื่อ
SGPT สามารถสร้างคำสั่งเชลล์ตามอินพุตของคุณ:
$ sgpt sh " make all files in current directory read only "
chmod -R 444 *นอกจากนี้คุณยังสามารถสร้างคำสั่งเชลล์และดำเนินการโดยตรง:
$ sgpt sh --execute " make all files in current directory read only "
chmod -R 444 *
Do you want to execute this command ? (Y/n) y คำสั่ง sh เป็นตัวตนเริ่มต้นในการสร้างคำสั่งเชลล์ สำหรับข้อมูลเพิ่มเติมเกี่ยวกับบุคคลดูเอกสาร
ปัจจุบัน SGPT ไม่รองรับเซสชันเชลล์แบบโต้ตอบ อย่างไรก็ตาม rlwrap สามารถใช้เพื่อเปิดใช้งานเซสชันเชลล์เหมือนแบบโต้ตอบ (แหล่งที่มา):
$ rlwrap bash -c 'echo ▶; while read in; do [[ -n "$in" ]] && echo ■ && sgpt --chat chat_name "$in" && echo ▶; done'
▶
mass of sun
■
The mass of the Sun is approximately 1.989 x 10^30 kilograms, or about 330,000 times the mass of Earth. It contains about 99.86% of the total mass of the Solar System and is by far the most dominant object in it. The Sun's mass is composed mostly of hydrogen (~74%) and helium (~24%), with the remaining 2% consisting of heavier elements.
▶
convert to earth masses
■
To convert the mass of the Sun to Earth masses, you can simply divide the Sun's mass by the mass of the Earth. Given that:
A. The Sun's mass is approximately 1.989 x 10^30 kilograms.
B. The Earth's mass is approximately 5.972 x 10^24 kilograms.
Using these values, you can calculate how many Earth masses the Sun is:
(1.989 x 10^30 kg) / (5.972 x 10^24 kg/Earth) = approximately 333,000 Earth masses
So the Sun is about 333,000 times more massive than the Earth.
▶
สคริปต์ที่มีการสร้างชื่อเซสชันอัตโนมัติและการสนับสนุนการแจ้งเตือนอาจมีลักษณะเช่นนี้:
#! /usr/bin/env bash
shopt -s -o errexit
shopt -s -o pipefail
shopt -s -o nounset
shopt -s inherit_errexit
export CHAT= " $( date ' +%Y%m%d%H%M%S%3N ' ) _ $( tr -dc ' A-Za-z ' < /dev/urandom | head -c 3 ) "
rlwrap bash -c ' echo ▶; while read in; do [[ -n "$in" ]] && echo ■ && sgpt --chat "$CHAT" "$in" && echo ▶ && notify-send --urgency=low ; done 'ขอบคุณ @ilya-bystrov สำหรับการแก้ปัญหานี้
SGPT สามารถสร้างรหัสได้อย่างมีประสิทธิภาพตามคำแนะนำที่กำหนด ตัวอย่างเช่นในการแก้ปัญหา Fizzbuzz แบบคลาสสิกโดยใช้ Python เพียงแค่ให้พรอมต์ดังนี้:
$ sgpt code " Solve classic 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)SGPT จะส่งคืนรหัส Python ที่เหมาะสมเพื่อแก้ไขปัญหา Fizzbuzz
คำสั่ง code เป็นตัวตนเริ่มต้นเพื่อสร้างรหัส สำหรับข้อมูลเพิ่มเติมเกี่ยวกับบุคคลดูเอกสาร
SGPT สามารถรวมเข้ากับเวิร์กโฟลว์ของคุณได้โดยการสร้างนามแฝงและฟังก์ชั่น Bash สิ่งนี้ช่วยให้คุณสามารถทำงานร่วมกันโดยอัตโนมัติและปรับปรุงประสิทธิภาพเมื่อทำงานกับโมเดล OpenAI และคำสั่งเชลล์
แน่นอนคุณสามารถกำหนดค่า SGPT เพื่อสร้างข้อความ GIT Commit ของคุณโดยใช้ฟังก์ชั่น BASH ต่อไปนี้:
gsum () {
commit_message= " $( sgpt txt " Generate git commit message, my changes: $( git diff ) " ) "
printf " %sn " " $commit_message "
read -rp " Do you want to commit your changes with this commit message? [y/N] " response
if [[ $response =~ ^[Yy]$ ]] ; then
git add . && git commit -m " $commit_message "
else
echo " Commit cancelled. "
fi
}ตัวอย่างเช่นข้อความ commit สำหรับคำอธิบายนี้และฟังก์ชั่น bash จะปรากฏดังต่อไปนี้:
$ gsum
feat: Add bash function to generate git commit messages
Added `gsum () ` function to ` .bash_aliases ` that generates a commit message using sgpt to summarize git changes.
The user is prompted to confirm the commit message before executing ` git add . & & git commit -m " <commit_message> " ` .
This function is meant to automate the commit process and increase productivity in daily work.
Additionally, updated the README.md file to include information about the new bash function and added a section to
showcase useful bash aliases and functions found in ` .bash_aliases ` .
Do you want to commit your changes with this commit message ? [y/N] y
[main d6db80a] feat: Add bash function to generate git commit messages
2 files changed, 48 insertions(+)
create mode 100644 .bash_aliasesการรวบรวมนามแฝงและฟังก์ชั่นการทุบตีที่เป็นประโยชน์รวมถึงฟังก์ชั่น GSUM ที่อัปเดตนั้นมีอยู่ใน. BASHRC
แรงบันดาลใจจาก Shell-Gpt