newbing

package module
v0.1.1 Latest Latest
Warning

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

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

README

newbing

new bing API

new bing chat


    import "github.com/KendoCross/newbing"
    
    // 通过 cookie 初始化
    bingChat, err := newbing.NewChat(" new bing cookie ")
    if err != nil {
        t.Error(err)
        return
    }
    // 发起聊天
    ans, err := bingChat.Chat(context.TODO(), "你是chatGPT吗?")
    if err != nil {
        t.Error(err)
        return
    }
    println(ans)

    ans, err = bingChat.Chat(context.TODO(), "你能做什么?")
    if err != nil {
        t.Error(err)
        return
    }
    println(ans)
    

new bing image generation


    import "github.com/KendoCross/newbing"
    
    bingImgGen := newbing.NewImgGen("new bing cookie")
    ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
    defer cancel()

    imgURLsCh, err := bingImgGen.GenImgAync(ctx, "功夫熊猫")
    if err != nil {
        t.Error(err)
        return
    }

    imgURLs := <-imgURLsCh
    for _, url := range imgURLs {
        println(url)
    }
    

Documentation

Index

Constants

View Source
const Split = `�`

Variables

View Source
var HEADERS = map[string]string{
	"accept":          "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
	"accept-language": "en-US,en;q=0.9",
	"cache-control":   "max-age=0",
	"content-type":    "application/x-www-form-urlencoded",
	"referrer":        "https://www.bing.com/images/create/",
	"origin":          "https://www.bing.com",
	"user-agent":      "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63",
}

Functions

This section is empty.

Types

type BingChat

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

func NewChat

func NewChat(cookies string) (chatRoom *BingChat, err error)

func (*BingChat) Chat

func (c *BingChat) Chat(ctx context.Context, askMsg string) (ans string, err error)

type BingImgGen

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

func NewImgGen

func NewImgGen(cookies string) (imgGen *BingImgGen)

func (*BingImgGen) GenImgAync

func (gen *BingImgGen) GenImgAync(ctx context.Context, prompt string) (ch <-chan []string, err error)

type ChatHub

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

func (*ChatHub) Close

func (c *ChatHub) Close() (err error)

func (*ChatHub) SendChatMsg

func (c *ChatHub) SendChatMsg(ctx context.Context, invocationId int, message string) (resp ChatResponse, err error)

type ChatRequest

type ChatRequest struct {
	ConversationId        string `json:"conversationId"`
	ClientId              string `json:"clientId"`
	ConversationSignature string `json:"conversationSignature"`
}

type ChatResponse

type ChatResponse struct {
	Type         int `json:"type"`
	InvocationId int `json:"invocationId,string"`
	Item         struct {
		Messages []struct {
			Text   string `json:"text"`
			Author string `json:"author"`
			From   struct {
				Id   string `json:"id"`
				Name any    `json:"name"`
			} `json:"from"`
			CreatedAt     time.Time `json:"createdAt"`
			Timestamp     time.Time `json:"timestamp"`
			Locale        string    `json:"locale"`
			Market        string    `json:"market"`
			Region        string    `json:"region"`
			Location      string    `json:"location"`
			LocationHints []struct {
				Country           string `json:"country"`
				CountryConfidence int    `json:"countryConfidence"`
				State             string `json:"state"`
				City              string `json:"city"`
				CityConfidence    int    `json:"cityConfidence"`
				ZipCode           string `json:"zipCode"`
				TimeZoneOffset    int    `json:"timeZoneOffset"`
				Dma               int    `json:"dma"`
				SourceType        int    `json:"sourceType"`
				Center            struct {
					Latitude  float64 `json:"latitude"`
					Longitude float64 `json:"longitude"`
					Height    any     `json:"height"`
				} `json:"center"`
				RegionType int `json:"regionType"`
			} `json:"locationHints"`
			MessageId uuid.UUID `json:"messageId"`
			RequestId uuid.UUID `json:"requestId"`
			Offense   string    `json:"offense"`
			Feedback  struct {
				Tag       any    `json:"tag"`
				UpdatedOn any    `json:"updatedOn"`
				Type      string `json:"type"`
			} `json:"feedback"`
			ContentOrigin string `json:"contentOrigin"`
			Privacy       any    `json:"privacy"`
			InputMethod   string `json:"inputMethod"`
			HiddenText    string `json:"hiddenText"`
			MessageType   string `json:"messageType"`
			AdaptiveCards []struct {
				Type    string `json:"type"`
				Version string `json:"version"`
				Body    []struct {
					Type    string `json:"type"`
					Inlines []struct {
						Type     string `json:"type"`
						IsSubtle bool   `json:"isSubtle"`
						Italic   bool   `json:"italic"`
						Text     string `json:"text"`
					} `json:"inlines,omitempty"`
					Text string `json:"text,omitempty"`
					Wrap bool   `json:"wrap,omitempty"`
					Size string `json:"size,omitempty"`
				} `json:"body"`
			} `json:"adaptiveCards"`
			SourceAttributions []struct {
				ProviderDisplayName string `json:"providerDisplayName"`
				SeeMoreUrl          string `json:"seeMoreUrl"`
				SearchQuery         string `json:"searchQuery"`
			} `json:"sourceAttributions"`
			SuggestedResponses []struct {
				Text        string    `json:"text"`
				Author      string    `json:"author"`
				CreatedAt   time.Time `json:"createdAt"`
				Timestamp   time.Time `json:"timestamp"`
				MessageId   string    `json:"messageId"`
				MessageType string    `json:"messageType"`
				Offense     string    `json:"offense"`
				Feedback    struct {
					Tag       any    `json:"tag"`
					UpdatedOn any    `json:"updatedOn"`
					Type      string `json:"type"`
				} `json:"feedback"`
				ContentOrigin string `json:"contentOrigin"`
				Privacy       any    `json:"privacy"`
			} `json:"suggestedResponses"`
			SpokenText string `json:"spokenText"`
		} `json:"messages"`
		FirstNewMessageIndex   int       `json:"firstNewMessageIndex"`
		SuggestedResponses     any       `json:"suggestedResponses"`
		ConversationId         string    `json:"conversationId"`
		RequestId              string    `json:"requestId"`
		ConversationExpiryTime time.Time `json:"conversationExpiryTime"`
		Telemetry              struct {
			Metrics   any       `json:"metrics"`
			StartTime time.Time `json:"startTime"`
		} `json:"telemetry"`
		ShouldInitiateConversation bool `json:"shouldInitiateConversation"`
		Result                     struct {
			Value          string `json:"value"`
			Message        string `json:"message"`
			ServiceVersion string `json:"serviceVersion"`
		} `json:"result"`
	} `json:"item,omitempty"`
}

type StrChMng

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

func NewStrChMng

func NewStrChMng() (mng *StrChMng)

func (*StrChMng) AddCh

func (mng *StrChMng) AddCh(uid string, ch chan<- string)

func (*StrChMng) DelCh

func (mng *StrChMng) DelCh(uid string)

func (*StrChMng) GetCh

func (mng *StrChMng) GetCh(uid string) (ch chan<- string, has bool)

Jump to

Keyboard shortcuts

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