xgpt3

package module
v0.1.1-0...-0783f25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

xgpt3

go-gpt3 API wrapper that supports conversation

Installation

go get github.com/fanchunke/xgpt3

Usage

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/fanchunke/xgpt3"
	"github.com/fanchunke/xgpt3/conversation/ent"
	"github.com/fanchunke/xgpt3/conversation/ent/chatent"
	gogpt "github.com/sashabaranov/go-gpt3"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	// 连接数据库
	entClient, err := chatent.Open("mysql", "root:12345678@tcp(127.0.0.1:3306)/chatgpt?parseTime=True")
	if err != nil {
		log.Fatalf("Open database failed: %s", err)
	}

	// 生成数据库表
	if err := entClient.Schema.Create(context.Background()); err != nil {
		log.Fatalf("Create database schema failed: %s", err)
	}

	// conversation handler
	handler := ent.New(entClient)

	// gogpt client
	gptClient := gogpt.NewClient("authToken")

	// xgpt3 client
	xgpt3Client := xgpt3.NewClient(gptClient, handler)

	// 请求
	req := gogpt.CompletionRequest{
		Model:           gogpt.GPT3TextDavinci003,
		MaxTokens:       100,
		Prompt:          "Lorem ipsum",
		TopP:            1,
		Temperature:     0.9,
		PresencePenalty: 0.6,
		User:            "fanchunke",
	}
	resp, err := xgpt3Client.CreateConversationCompletion(context.Background(), req)
	if err != nil {
		log.Fatalf("CreateConversationCompletion failed: %s", err)
	}
	fmt.Println(resp.Choices[0].Text)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*gogpt.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(client *gogpt.Client, ch conversation.Handler) *Client

func (*Client) CloseConversation

func (c *Client) CloseConversation(ctx context.Context, userId string) error

func (*Client) CreateConversationChatCompletion

func (c *Client) CreateConversationChatCompletion(
	ctx context.Context,
	request gogpt.ChatCompletionRequest,
) (gogpt.ChatCompletionResponse, error)

func (*Client) CreateConversationChatCompletionWithChannel

func (c *Client) CreateConversationChatCompletionWithChannel(
	ctx context.Context,
	request gogpt.ChatCompletionRequest,
	channel string,
) (gogpt.ChatCompletionResponse, error)

func (*Client) CreateConversationCompletion

func (c *Client) CreateConversationCompletion(
	ctx context.Context,
	request gogpt.CompletionRequest,
) (gogpt.CompletionResponse, error)

func (*Client) CreateConversationCompletionWithChannel

func (c *Client) CreateConversationCompletionWithChannel(
	ctx context.Context,
	request gogpt.CompletionRequest,
	channel string,
) (gogpt.CompletionResponse, error)

func (*Client) WithLogger

func (c *Client) WithLogger(l zerolog.Logger) *Client

func (*Client) WithMaxTurn

func (c *Client) WithMaxTurn(n int) *Client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址