gpt go
v0.1.0
ภาษาอังกฤษ | 中文
การอ้างอิง Openai Docs API: https://platform.openai.com/docs/api-reference/introduction
หมายเหตุ : รองรับ GPT-4 API แล้วโปรดใช้ API การแชทเสร็จสมบูรณ์
# clone the project
git clone https://github.com/hanyuancheung/gpt-go.git
# go to the project directory
cd gpt-go
# set API_KEY as environment variable
export API_KEY={YOUR_API_KEY} chatgpt
# go build example binary
make chatgpt-example
# run example
./chatgpt
API_KEY
https://platform.openai.com/account/api-keys
ตรวจสอบเอกสาร GO สำหรับเอกสารรายละเอียดเพิ่มเติมเกี่ยวกับประเภทและวิธีการที่มีให้: https://pkg.go.dev/github.com/hanyuancheung/gpt-go
func main () {
client := gpt . NewClient ( "API_KEY" )
err := client . ChatCompletionStream ( context . Background (), & gpt. ChatCompletionRequest {
Model : gpt . GPT3Dot5Turbo ,
Messages : []gpt. ChatCompletionRequestMessage {
{
Role : "user" ,
Content : "Hello!" ,
},
},
}, func ( response * gpt. ChatCompletionStreamResponse ) {
fmt . Print ( response . Choices [ 0 ]. Delta . Content )
})
if err != nil {
fmt . Printf ( "ChatCompletionStream error: %v n " , err )
return
}
}
func main () {
client := gpt . NewClient ( "API_KEY" )
rsp , err := client . CompletionWithEngine ( context . Background (), & gpt. CompletionRequest {
Model : gpt . TextDavinci003Engine ,
Prompt : [] string { "Hello!" },
})
if err != nil {
fmt . Printf ( "ChatCompletionStream error: %v n " , err )
return
}
fmt . Print ( rsp . Choices [ 0 ]. Text )
}
func main () {
client := gpt . NewClient ( "API_KEY" )
rsp , err := client . Image ( context . Background (), & gpt. ImageRequest {
Prompt : "Chicken" ,
})
if err != nil {
fmt . Printf ( "ChatCompletionStream error: %v n " , err )
return
}
fmt . Print ( rsp . Data [ 0 ]. URL )
}
โปรดเปิดปัญหาเกี่ยวกับ GitHub ก่อนที่คุณจะใช้ความพยายามอย่างมากในการขอการดึง รหัสที่ส่งไปยัง PR จะต้องถูกกรองด้วย gofmt
แพ็คเกจนี้ได้รับใบอนุญาตภายใต้ใบอนุญาต MIT ดูใบอนุญาตสำหรับรายละเอียด
ให้️ถ้าโครงการนี้ช่วยคุณได้!