core

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LOG_DEBUG   log.Mode = log.DEBUG
	LOG_SILENCE log.Mode = log.SILENCE
	LOG_ERROR   log.Mode = log.ERROR
)
View Source
var RequestConnTypeHttpEventStream = 4

Functions

func SetLogMode added in v1.0.4

func SetLogMode(mode log.Mode)

Types

type AskRequest

type AskRequest struct {
	UserId              int64
	Question            string
	CallbackFuncName    string
	AskResponseCallBack AskRequestResponseCallBack
}

AskRequest like the JSONP callback if you are older ,you know what i mean:) CallbackFuncName when your client send it to server, also reply back to client when you are using websocket.Send, you can build a global callback function to handle the response

type AskRequestCallBack

type AskRequestCallBack func(askRequest *AskRequest, response []byte)

type AskRequestResponseCallBack

type AskRequestResponseCallBack func(askRequest *AskRequest, message *CallbackMessageResponse)

type CallbackMessageResponse added in v1.0.8

type CallbackMessageResponse struct {
	Type             string      `json:"type"`
	CallbackFuncName string      `json:"callback_func_name"`
	Data             *GptMessage `json:"data"`
}

type GetSettingResponse added in v1.0.3

type GetSettingResponse struct {
	Formkey      string `json:"formkey"`
	TchannelData struct {
		MinSeq          string `json:"minSeq"`
		Channel         string `json:"channel"`
		ChannelHash     string `json:"channelHash"`
		BoxName         string `json:"boxName"`
		BaseHost        string `json:"baseHost"`
		TargetUrl       string `json:"targetUrl"`
		EnableWebsocket bool   `json:"enableWebsocket"`
	} `json:"tchannelData"`
}

type GptInterface

type GptInterface interface {
	Talk(ctx context.Context, askRequest *AskRequest) (*GptMessage, error)
	Publish(message *messageQueue.Message)
	AddConsumer(consumer *messageQueue.ConsumerConfigure)
	RemoveConsumer(consumerName string)
	GetMessageId() string
	SetConversationID(cid string)
	SetParentMessageID(parentMessageID string)
	GetMidCidAndPid() (mid, cid, pid string)
}

type GptMessage

type GptMessage struct {
	Id              string   `json:"id"`
	Account         string   `json:"account"`
	ParentMessageId string   `json:"parent_message_id"`
	ConversationId  string   `json:"conversation_id"`
	IsEnd           bool     `json:"is_end"`
	Text            string   `json:"text"`
	Suggestions     []string `json:"suggestions"`
	Error           any      `json:"error"`
}

type GptType

type GptType uint
var GptTypeBingGpt GptType = 1
var GptTypeOfficialApi GptType = 3
var GptTypePoeUnofficial GptType = 4
var GptTypeUnOfficial GptType = 2

type MultiUserGpt

type MultiUserGpt struct {
	GptMap map[int64]*UserChat
	// contains filtered or unexported fields
}

func NewMutLtiUserGpt

func NewMutLtiUserGpt(gptType GptType) *MultiUserGpt

func (*MultiUserGpt) Talk

func (m *MultiUserGpt) Talk(askRequest *AskRequest)

type PoeGPT

type PoeGPT struct {
	MessageBus                                 *messageQueue.MemoryMessageQueue
	PoeURl                                     string
	MessageID, ConversationID, ParentMessageID string
	// contains filtered or unexported fields
}

func NewPoeGPT

func NewPoeGPT(parentMessageID string, messageConsumer *messageQueue.ConsumerConfigure) *PoeGPT

func (*PoeGPT) AddConsumer

func (poe *PoeGPT) AddConsumer(configure *messageQueue.ConsumerConfigure)

func (*PoeGPT) GetHistory

func (poe *PoeGPT) GetHistory() (*PoeGetHistoryMessage, error)

func (*PoeGPT) GetMessageId

func (poe *PoeGPT) GetMessageId() string

func (*PoeGPT) GetMidCidAndPid

func (poe *PoeGPT) GetMidCidAndPid() (string, string, string)

func (*PoeGPT) GetSettings

func (poe *PoeGPT) GetSettings() (seq string, hash string, boxName string, channel string, err error)

func (*PoeGPT) NewPoeRequest

func (poe *PoeGPT) NewPoeRequest(parentMessageId, prompt string) *PoeRequest

func (*PoeGPT) PoeRequest added in v1.0.3

func (poe *PoeGPT) PoeRequest(httpMethod, urlStr string, body *bytes.Reader) (*http.Response, error)

func (*PoeGPT) PoeWsClient

func (poe *PoeGPT) PoeWsClient() bool

func (*PoeGPT) Publish

func (poe *PoeGPT) Publish(message *messageQueue.Message)

func (*PoeGPT) ReOpenWsClient

func (poe *PoeGPT) ReOpenWsClient()

func (*PoeGPT) RemoveConsumer

func (poe *PoeGPT) RemoveConsumer(consumerName string)

func (*PoeGPT) SetConversationID

func (poe *PoeGPT) SetConversationID(cid string)

func (*PoeGPT) SetParentMessageID

func (poe *PoeGPT) SetParentMessageID(parentMessageID string)

func (*PoeGPT) Talk

func (poe *PoeGPT) Talk(ctx context.Context, askRequest *AskRequest) (*GptMessage, error)

type PoeGetHistoryMessage

type PoeGetHistoryMessage struct {
	Data struct {
		ChatOfBot struct {
			Id                 string `json:"id"`
			Typename           string `json:"__typename"`
			MessagesConnection struct {
				Typename string `json:"__typename"`
				PageInfo struct {
					Typename        string `json:"__typename"`
					HasPreviousPage bool   `json:"hasPreviousPage"`
				} `json:"pageInfo"`
				Edges []struct {
					Typename string         `json:"__typename"`
					Node     PoeHistoryNode `json:"node"`
				} `json:"edges"`
			} `json:"messagesConnection"`
		} `json:"chatOfBot"`
	} `json:"data"`
	Extensions struct {
		IsFinal bool `json:"is_final"`
	} `json:"extensions"`
}

type PoeGetHistoryPayload added in v1.0.3

type PoeGetHistoryPayload struct {
	OperationName string `json:"operationName"`
	Query         string `json:"query"`
	Variables     struct {
		Before interface{} `json:"before"`
		Bot    string      `json:"bot"`
		Last   int         `json:"last"`
	} `json:"variables"`
}

type PoeHistoryNode

type PoeHistoryNode struct {
	Typename         string      `json:"__typename"`
	Id               string      `json:"id"`
	MessageId        int         `json:"messageId"`
	Text             string      `json:"text"`
	LinkifiedText    string      `json:"linkifiedText"`
	AuthorNickname   string      `json:"authorNickname"`
	State            string      `json:"state"`
	Vote             interface{} `json:"vote"`
	VoteReason       interface{} `json:"voteReason"`
	CreationTime     int64       `json:"creationTime"`
	SuggestedReplies []string    `json:"suggestedReplies"`
}

type PoeRequest

type PoeRequest struct {
	Prompt          string `json:"prompt"`
	ParentMessageId string `json:"parentMessageId"`
	Mode            string `json:"mode"`
}

type PoeResponse

type PoeResponse struct {
	Response  string `json:"response"`
	MessageId string `json:"messageId"`
	Result    struct {
		Value   string      `json:"value"`
		Code    int         `json:"code"`
		Message interface{} `json:"message"`
	} `json:"result"`
}

type PoeSendMessageResponse

type PoeSendMessageResponse struct {
	Data struct {
		MessageEdgeCreate struct {
			Typename string `json:"__typename"`
			Message  struct {
				Typename string `json:"__typename"`
				Node     struct {
					Typename         string      `json:"__typename"`
					Id               string      `json:"id"`
					MessageId        int         `json:"messageId"`
					Text             string      `json:"text"`
					LinkifiedText    string      `json:"linkifiedText"`
					AuthorNickname   string      `json:"authorNickname"`
					State            string      `json:"state"`
					Vote             interface{} `json:"vote"`
					VoteReason       interface{} `json:"voteReason"`
					CreationTime     int64       `json:"creationTime"`
					SuggestedReplies []string    `json:"suggestedReplies"`
					Chat             struct {
						Typename             string `json:"__typename"`
						Id                   string `json:"id"`
						ShouldShowDisclaimer bool   `json:"shouldShowDisclaimer"`
					} `json:"chat"`
				} `json:"node"`
			} `json:"message"`
			ChatBreak interface{} `json:"chatBreak"`
		} `json:"messageEdgeCreate"`
	} `json:"data"`
	Extensions struct {
		IsFinal bool `json:"is_final"`
	} `json:"extensions"`
}

type RequestConnType

type RequestConnType int
var RequestConnTypeGrpc RequestConnType = 3
var RequestConnTypeJSON RequestConnType = 2
var RequestConnTypeWebsocket RequestConnType = 1

type UserChat

type UserChat struct {
	UserId int64
	Gpt    GptInterface
	// contains filtered or unexported fields
}

func (*UserChat) Ask

func (u *UserChat) Ask(askRequest *AskRequest)

func (*UserChat) NewMessageNotify

func (u *UserChat) NewMessageNotify(askRequest *AskRequest, lastResponse *GptMessage, ctx context.Context, cancel context.CancelFunc) *messageQueue.ConsumerConfigure

func (*UserChat) NewPersistenceConsumer

func (u *UserChat) NewPersistenceConsumer() *messageQueue.ConsumerConfigure

func (*UserChat) NewPoeGpt

func (u *UserChat) NewPoeGpt(store *UserStore)

type UserStore

type UserStore struct {
	UserId          int64
	ConversationId  string
	ParentMessageId string
}

Jump to

Keyboard shortcuts

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