messagesource

package
v0.0.0-...-d68ec4c Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SimulateUserAgent       = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
	AuthHeaderTokenPrefix   = "Bearer"
	LoginURL                = "https://chat.openai.com/auth/login"
	InteractiveLoginTimeout = time.Second * 30
	CacheJWTTokenPath       = "db/_cached_jwt_token"
)
View Source
const (
	JWTTokenEnvName = "CHATGPT_JWT_TOKEN"
)

Variables

View Source
var (
	ErrInteractiveGetTokenTimeout = errors.New("timeout while getting token (did you login?)")
)

Functions

This section is empty.

Types

type ChatGPTMessageSource

type ChatGPTMessageSource struct {
	// contains filtered or unexported fields
}

ChatGPTMessageSource is a message source backed by ChatGPT

Note: Since the ChatGPT engine (text-davinci-002-render) is not yet available using the official OpenAI GPT-3 API (at time of writing) we use the go-ChatGPT library that just calls the same endpoints as otherwise would be used when interacting with ChatGPT at https://chat.openai.com/chat. This does mean authentication to the API is slightly complicated since we cannot use the OpenAI API token. We need to copy the JWT token from an active ChatGPT session which has the downside of expiring at some point. You can use the CHATGPT_JWT_TOKEN to set this token, or rely on the interactive browser session that this script will open. (For this to work, chromium-browser needs to be installed.)

func NewChatGPTMessageSource

func NewChatGPTMessageSource() (*ChatGPTMessageSource, error)

func (*ChatGPTMessageSource) GetResponse

func (source *ChatGPTMessageSource) GetResponse(message string) (string, error)

type InteractiveJWTTokenGetter

type InteractiveJWTTokenGetter struct {
}

func NewInteractiveJWTTokenGetter

func NewInteractiveJWTTokenGetter() *InteractiveJWTTokenGetter

func (*InteractiveJWTTokenGetter) GetToken

func (getter *InteractiveJWTTokenGetter) GetToken() (string, error)

chatGPTGetJWTTokenInteractive attempts to retrieve a JWT token from an interactive ChatGPT session by firing up a browser using chromedm and intercepting the bearer token after login

func (*InteractiveJWTTokenGetter) IsJWTToken

func (getter *InteractiveJWTTokenGetter) IsJWTToken(token string) bool

isJWTToken checks if the passed string is a valid JWT token. We only check if the token can be parsed, no further validation of keys or claims is done.

type MessageSource

type MessageSource interface {
	GetResponse(message string) (string, error)
}

Jump to

Keyboard shortcuts

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