gpt go
v0.1.0
Inglés | 中文
Referencia de API de Operai Docs: https://platform.openai.com/docs/api-reference/introduction
Nota : ya admite la API GPT-4, utilice la API de finalización de chat.
# 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
Consulte los documentos GO para obtener una documentación más detallada sobre los tipos y métodos proporcionados: 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 )
}
Abra un problema en GitHub antes de poner muchos esfuerzos en la solicitud de extracción. El código que envía a PR debe filtrarse con gofmt
.
Este paquete tiene licencia bajo la licencia MIT. Vea la licencia para más detalles.
¡Dale una osa si este proyecto te ayudó!