2023-01-28 22:32:23 +04:00
2023-01-28 22:32:23 +04:00
2023-03-02 00:47:25 +04:00
2023-02-21 00:16:44 +04:00
2022-08-11 15:29:23 +06:00
2023-02-21 00:16:44 +04:00
2023-03-02 00:47:25 +04:00
2023-02-21 00:16:44 +04:00
2023-02-21 00:16:44 +04:00
2023-01-28 23:18:59 +04:00
2022-12-16 13:56:10 +04:00
2022-08-11 15:29:23 +06:00
2023-02-13 20:43:06 +04:00
2023-02-21 00:16:44 +04:00
2021-12-15 22:24:34 +03:00
2023-02-21 00:16:44 +04:00
2020-08-18 17:42:55 +03:00
2022-08-11 15:29:23 +06:00
2023-02-21 00:16:44 +04:00
2022-08-11 15:29:23 +06:00
2023-03-02 00:56:50 +04:00
2023-02-22 12:33:25 +04:00
2023-02-22 12:33:25 +04:00

go-gpt3

GoDoc Go Report Card

OpenAI ChatGPT and GPT-3 API client for Go

Installation:

go get github.com/sashabaranov/go-gpt3

Example usage:

package main

import (
	"context"
	"fmt"
	gogpt "github.com/sashabaranov/go-gpt3"
)

func main() {
	c := gogpt.NewClient("your token")
	ctx := context.Background()

	req := gogpt.CompletionRequest{
		Model:     gogpt.GPT3Ada,
		MaxTokens: 5,
		Prompt:    "Lorem ipsum",
	}
	resp, err := c.CreateCompletion(ctx, req)
	if err != nil {
		return
	}
	fmt.Println(resp.Choices[0].Text)
}

Streaming response example:

package main

import (
	"errors"
	"context"
	"fmt"
	"io"
	gogpt "github.com/sashabaranov/go-gpt3"
)

func main() {
	c := gogpt.NewClient("your token")
	ctx := context.Background()

	req := gogpt.CompletionRequest{
		Model:     gogpt.GPT3Ada,
		MaxTokens: 5,
		Prompt:    "Lorem ipsum",
		Stream:    true,
	}
	stream, err := c.CreateCompletionStream(ctx, req)
	if err != nil {
		return
	}
	defer stream.Close()

	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			fmt.Println("Stream finished")
			return
		}

		if err != nil {
			fmt.Printf("Stream error: %v\n", err)
			return
		}


		fmt.Printf("Stream response: %v\n", response)
	}
}
Description
No description provided
Readme Apache-2.0 952 KiB
Languages
Go 100%