Home

Awesome

ChatGPT-Client is a ChatGPT Client with Offical OpenAI API.

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get -u github.com/go-zoox/chatgpt-client

Getting Started

Simple

package main

import (
	"fmt"
	"log"
	"os"

	_ "github.com/go-zoox/dotenv"
)


import (
  chatgpt "github.com/go-zoox/chatgpt-client"
)

func main(t *testing.T) {
	client, err := chatgpt.New(&Config{
		APIKey: os.Getenv("API_KEY"),
	})
	if err != nil {
		log.Fatal(err)
	}

	var question []byte
	var answer []byte

	question = []byte("OpenAI 是什么?")
	fmt.Printf("question: %s\n", question)
	answer, err = client.Ask(question)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("answer: %s\n\n", answer)
}

Use Conversation

package main

import (
	"fmt"
	"log"
	"os"

	_ "github.com/go-zoox/dotenv"
	"github.com/go-zoox/uuid"
)


import (
  chatgpt "github.com/go-zoox/chatgpt-client"
)

func main(t *testing.T) {
	client, err := chatgpt.New(&Config{
		APIKey: os.Getenv("API_KEY"),
	})
	if err != nil {
		log.Fatal(err)
	}

	conversation, err := client.GetOrCreateConversation(uuid.V4(), &chatgpt.ConversationConfig{})
  if err != nil {
    log.Fatal(err)
  }

	var question []byte
	var answer []byte

	question = []byte("OpenAI 是什么?")
	fmt.Printf("question: %s\n", question)
	answer, err = conversation.Ask(question)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("answer: %s\n\n", answer)

	question = []byte("可以展开讲讲吗?")
	fmt.Printf("question: %s\n", question)
	answer, err = conversation.Ask(question)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("answer: %s\n\n", answer)

	question = []byte("我们现在讨论的内容是什么?")
	fmt.Printf("question: %s\n", question)
	answer, err = conversation.Ask(question)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("answer: %s\n\n", answer)
}

License

GoZoox is released under the MIT License.