chatgpt

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 11 Imported by: 0

README

chatgpt

使用chrome webdriver调用chatgpt 支持plus

使用方法

  1. 架梯子访问 https://chat.openai.com/chat ,登录并能成功进入聊天界面
  2. 安装chrome插件:EditThisCookie https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg
  3. 导出当前页面的cookie,保存到 cookies.json
  4. 参考example/main.go,编写自己的聊天机器人
package main

import (
	"github.com/cherish-chat/chatgpt-firefox"
	"log"
)

func main() {
	helper := chatgpt.NewHelper("cookies.json")
	err := helper.LaunchBrowser()
	if err != nil {
		log.Fatalf("launch browser error: %v", err)
	}
	eh := xxim()
	for {
		select {
		case msgData := <-eh.msgChan:
			go func() {
				if helper.IsLocked() {
					eh.sendTextMsg(msgData.ConvId, "机器人正在忙,请稍后再试")
				} else {
					page := helper.MustGetPage(msgData.ConvId)
					reply, err := helper.SendMsg(page, string(msgData.Content))
					if err != nil {
						eh.sendTextMsg(msgData.ConvId, "机器人出错了,请稍后再试: "+err.Error())
					} else {
						eh.sendTextMsg(msgData.ConvId, reply)
					}
				}
            }()
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConversationStreamResponseItem

type ConversationStreamResponseItem struct {
	Message struct {
		Id     string `json:"id"`
		Author struct {
			Role     string      `json:"role"`
			Name     interface{} `json:"name"`
			Metadata struct {
			} `json:"metadata"`
		} `json:"author"`
		CreateTime interface{} `json:"create_time"`
		UpdateTime interface{} `json:"update_time"`
		Content    struct {
			ContentType string   `json:"content_type"`
			Parts       []string `json:"parts"`
		} `json:"content"`
		EndTurn  bool    `json:"end_turn"`
		Weight   float64 `json:"weight"`
		Metadata struct {
			MessageType   string `json:"message_type"`
			ModelSlug     string `json:"model_slug"`
			FinishDetails struct {
				Type string `json:"type"`
				Stop string `json:"stop"`
			} `json:"finish_details"`
		} `json:"metadata"`
		Recipient string `json:"recipient"`
	} `json:"message"`
	ConversationId string      `json:"conversation_id"`
	Error          interface{} `json:"error"`
}

func (*ConversationStreamResponseItem) String

func (*ConversationStreamResponseItem) Text

type Helper

type Helper struct {
	CookiePath string
	// contains filtered or unexported fields
}

func NewHelper

func NewHelper(cookiePath string) *Helper

func (*Helper) ClosePage

func (h *Helper) ClosePage(id string, page playwright.Page)

func (*Helper) GetPage

func (h *Helper) GetPage(id string) (playwright.Page, error)

func (*Helper) GetPlusPage

func (h *Helper) GetPlusPage(id string) (playwright.Page, error)

func (*Helper) IsLocked

func (h *Helper) IsLocked() bool

func (*Helper) LaunchBrowser

func (h *Helper) LaunchBrowser() error

func (*Helper) MustGetPage

func (h *Helper) MustGetPage(id string) playwright.Page

Deprecated 请使用GetPage

func (*Helper) NewPage

func (h *Helper) NewPage(id string) (playwright.Page, error)

func (*Helper) NewPlusPage

func (h *Helper) NewPlusPage(id string) (playwright.Page, error)

func (*Helper) SendMsg

func (h *Helper) SendMsg(page playwright.Page, inputText string) (string, error)

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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