bingdalle3

package module
v0.0.0-...-d0433c6 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 10 Imported by: 0

README

bing-dalle3

bing-dalle3 is a Golang implementation of yihong0618/BingImageCreator. It allows you to access the Image Creator from Microsoft Bing service through API calls.

In comparison to yihong0618/BingImageCreator, bing-dalle3 simplifies certain features, including:

  • The addition of a random x-forwarded-for header to disguise the source IP of requests (useful if Bing does not correctly implement code to obtain the real IP).
  • The ability to save generated images to disk.
  • Implementation of a CLI command.

Quickstart

Please refer to the README of yihong0618/BingImageCreator to obtain your Bing cookie.

package main

import (
	"fmt"
	"os"

	bingdalle3 "github.com/mrchi/bing-dalle3"
)

func main() {
	prompt := "月落乌啼霜满天,江枫渔火对愁眠。"
	bingClient := bingdalle3.NewBingDalle3("Your Bing cookie")

	balance, err := bingClient.GetTokenBalance()
	if err != nil {
		panic(err)
	}
	fmt.Println("balance: ", balance)

	writingId, err := bingClient.CreateImage(prompt)
	if err != nil {
		panic(err)
	}
	fmt.Println("writingId: ", writingId)

	imageUrls, err := bingClient.QueryResult(writingId, prompt)
	if err != nil {
		panic(err)
	}
	fmt.Println("imageUrls: ", imageUrls)

	imageContent, err := bingClient.DownloadImage(imageUrls[0])
	if err != nil {
		panic(err)
	}

	if err = os.WriteFile("output.jpeg", *imageContent, 0644); err != nil {
		panic(err)
	}
}

Thanks

I'd like to express my gratitude to @yihong0618 and the original author @acheong08 for their contributions.

Documentation

Index

Constants

View Source
const (
	UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
	Timeout   = 5 * time.Second
	PageUrl   = "https://www.bing.com/images/create"
	ResultUrl = "https://www.bing.com/images/create/async/results/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BingDalle3

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

func NewBingDalle3

func NewBingDalle3(cookie string) *BingDalle3

func NewBingDalle3WithProxy

func NewBingDalle3WithProxy(cookie, proxyUrl string) *BingDalle3

func (*BingDalle3) CreateImage

func (bing *BingDalle3) CreateImage(prompt string) (string, error)

func (*BingDalle3) DownloadImage

func (bing *BingDalle3) DownloadImage(imageUrl string) (*[]byte, error)

func (*BingDalle3) GetTokenBalance

func (bing *BingDalle3) GetTokenBalance() (int, error)

func (*BingDalle3) QueryResult

func (bing *BingDalle3) QueryResult(id string, prompt string) ([]string, error)

Jump to

Keyboard shortcuts

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