chatgpt

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 15 Imported by: 3 modules, 1 package

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

chatgpt-wapi

Documentation

Index

Constants

View Source
const (
	BU        = "https://chat.openai.com/backend-api"
	Gpt3Model = "text-davinci-002-render-sha"
)

Variables

View Source
var (
	H = map[string]string{
		"User-Agent":   "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0",
		"Content-Type": "application/json; charset=utf-8",
		"Accept":       "text/event-stream",
	}
	BillingURL = "https://api.openai.com/v1/dashboard/billing/subscription"
)

Functions

func CalcTokens added in v1.0.1

func CalcTokens(prompt string) int

计算prompt的token长度

func NewError

func NewError(code int, message string) error

func TokensEndSubstr added in v1.0.1

func TokensEndSubstr(prompt string, maxToken int) string

尾部截取prompt

func TokensStartSubstr added in v1.0.1

func TokensStartSubstr(prompt string, maxToken int) string

头部截取prompt

func WebLogin added in v1.0.1

func WebLogin(email string, passwd string, proxy string) (string, error)

openai-web获取登陆凭证

Types

type Billing added in v1.0.1

type Billing struct {
	Soft   float64 `json:"soft_limit_usd"`
	Hard   float64 `json:"hard_limit_usd"`
	System float64 `json:"system_hard_limit_usd"`
}

余额

func Query added in v1.0.1

func Query(ctx context.Context, token string, proxy string) (*Billing, error)

查询api余额

type Chat

type Chat struct {
	Options
	Session struct {
		ConversationId string
		ParentId       string
	}
	// contains filtered or unexported fields
}

func New

func New(token string, reverseURL string) *Chat

func NewChat

func NewChat(opt Options) *Chat

func (*Chat) Reply

func (c *Chat) Reply(ctx context.Context, prompt string) (chan PartialResponse, error)

type Error

type Error struct {
	Code    int
	Message string
}

func (Error) Error

func (c Error) Error() string

type Options

type Options struct {
	Headers map[string]string
	BaseURL string
	Model   string
	Retry   int
}

type PartialResponse

type PartialResponse struct {
	Error error

	ConversationId string      `json:"conversation_id"`
	ResponseError  interface{} `json:"error"`

	Message struct {
		Id     string `json:"id"`
		Status string `json:"status"`

		Author struct {
			Role string `json:"role"`
		} `json:"author"`

		Content struct {
			ContentType string   `json:"content_type"`
			Parts       []string `json:"parts"`
		} `json:"content"`
	} `json:"message"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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