go gpt3
v1.2.0
GO/Golang 프로그램이 GPT3 API와 상호 작용할 수있는 OpenAI GPT-3 API 클라이언트.
스트리밍 유무에 관계없이 완료 API를 사용하여 지원합니다.
기본 GPT-3 API를 호출하는 간단한 사용, 완료 :
client := gpt3 . NewClient ( apiKey )
resp , err := client . Completion ( ctx , gpt3. CompletionRequest {
Prompt : [] string { "2, 3, 5, 7, 11," },
})
fmt . Print ( resp . Choices [ 0 ]. Text )
// prints " 13, 17, 19, 23, 29, 31", etc
제공된 유형 및 방법에 대한 자세한 내용은 Go 문서를 확인하십시오 : https://pkg.go.dev/github.com/pullrequestinc/go-gpt3
main.go
및 Runn go run main.go
에 내용을 넣어 이러한 예제 중 하나를 사용해보십시오. GO 모듈을 사용하는 것이 좋습니다.이 경우 테스트 리포 내에서 go mod init
실행해야합니다. 또는 go run cmd/test/main.go
사용 하여이 저장소를 복제하고 테스트 스크립트를 실행할 수 있습니다.
또한이 예제를 사용하려면 이와 같이 보이는 .env
파일이 필요합니다.
API_KEY=<openAI API Key>
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/PullRequestInc/go-gpt3"
"github.com/joho/godotenv"
)
func main () {
godotenv . Load ()
apiKey := os . Getenv ( "API_KEY" )
if apiKey == "" {
log . Fatalln ( "Missing API KEY" )
}
ctx := context . Background ()
client := gpt3 . NewClient ( apiKey )
resp , err := client . Completion ( ctx , gpt3. CompletionRequest {
Prompt : [] string { "The first thing you should know about javascript is" },
MaxTokens : gpt3 . IntPtr ( 30 ),
Stop : [] string { "." },
Echo : true ,
})
if err != nil {
log . Fatalln ( err )
}
fmt . Println ( resp . Choices [ 0 ]. Text )
}