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に入れて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 )
}