gpt go
v0.1.0
Bahasa Inggris | 中文
Referensi API Dokumen OpenAI: https://platform.openai.com/docs/api-reference/introduction
Catatan : Sudah mendukung API GPT-4, silakan gunakan API Penyelesaian Obrolan.
# 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_KEYhttps://platform.openai.com/account/api-keys
Lihatlah dokumen GO untuk dokumentasi lebih rinci tentang jenis dan metode yang disediakan: 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 )
} Harap buka masalah di GitHub sebelum Anda melakukan banyak upaya pada permintaan tarik. Kode yang mengirimkan ke PR harus disaring dengan gofmt .
Paket ini dilisensikan di bawah lisensi MIT. Lihat lisensi untuk detailnya.
Berikan ️ jika proyek ini membantu Anda!