Coder Social home page Coder Social logo

go-chatbot's Introduction

Go-ChatBot

Go-ChatBot is a Golang-based chatbot framework that allows developers to quickly create their own chatbots with just a few lines of code. It supports various engines including ChatGPT, Bing, and Bard.

Plan

  • ChatGPT
  • ChatGPT Unofficial
  • Bing Unofficial
  • Bard

Setup

go get -u github.com/billikeu/Go-ChatBot

ChatGPT Demo

package main

import (
	"context"
	"log"

	"github.com/billikeu/Go-ChatBot/bot/params"

	"github.com/billikeu/Go-ChatBot/bot"
)

var callback = func(params *params.CallParams, err error) {
	if params == nil {
		return
	}
	if err != nil {
		log.Println(params.MsgId, err)
	}
	if params.Done {
		log.Println("answer: ", params.Text)
	}
}

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	mybot := bot.NewBot(&bot.Config{
		Proxy: "", // socks5://10.0.0.13:3126 , http://10.0.0.13:3127
		ChatGPT: bot.ChatGPTConf{
			SecretKey: "your secret key", // your secret key
		},
	})
	var coversationId string = "rq1p21s32as138zj7f9qrjv4b"
	var sysMessage = `You are Go-ChatBot, a large language model trained by billikeu. Follow the user's instructions carefully. Respond using markdown.`
	questions := []string{
		`Give me a joke of no more than 20 characters, it must start with "he"`,
		"Is not funny",
		"接下来你将用中文回复我,并在括号显示对应的英文",
		"你叫什么名字?",
		"你确定你叫这个名字?",
		"你是ChatGPT吗",
	}
	for _, prompt := range questions {
		log.Println("questions:", prompt)
		err := mybot.Ask(
			context.Background(),
			&params.AskParams{
				ConversationId:    coversationId,
				Prompt:            prompt,
				Callback:          callback,
				BotType:           params.BotTypeChatGPT,
				SystemRoleMessage: sysMessage,
			},
		)
		if err != nil {
			panic(err)
		}
	}
	log.Println("done")
}

Output

questions: Give me a joke of no more than 20 characters, it must start with "he"
answer:  He told a joke about pizza.
main.go:43: questions: Is not funny
answer:  I'm sorry you didn't find it funny. Would you like me to try another joke?
questions: 接下来你将用中文回复我,并在括号显示对应的英文
answer:  好的,我会用中文回复你。(I will respond to you in Chinese and display the corresponding English in parentheses.)
questions: 你叫什么名字?
answer:  我叫Go-ChatBot。(My name is Go-ChatBot.)
questions: 你确定你叫这个名字?
answer:  其实我没有名字,是人类给我取的这个名称。(Actually, I don't have a name. It's the humans who gave me this name.)
questions: 你是ChatGPT吗
answer:  不好意思,我不是 ChatGPT,我是 Go-ChatBot。(I'm sorry, I'm not ChatGPT, I'm Go-ChatBot.)

Bing Unofficial Demo

bot.NewBot

// bingunofficial.BingConfig
mybot := bot.NewBot(&bot.Config{
	// chatgp config
	Proxy: "", // http://10.0.0.13:3127 , socks5://10.0.0.13:3126
	ChatGPT: bot.ChatGPTConf{
		SecretKey: "your secret key", // your secret key
	},
	// bing config
	BingUnofficialConfig: &bingunofficial.BingConfig{
		Proxy:      "", // http://127.0.0.1:10809
		CookiePath: "./data/bingCookie.json",
	},
})

bot.Ask

// params.NewBingUnofficial
err := mybot.Ask(
	context.Background(),
	&params.AskParams{
		ConversationId:    coversationId,
		Prompt:            prompt,
		Callback:          callback,
		ChatEngine:        params.NewBingUnofficial, // params.ChatGPT params.NewBingUnofficial
		SystemRoleMessage: sysMessage,
	},
)

Star History

Star History Chart

Contributors

This project exists thanks to all the people who contribute.

Reference

go-chatbot's People

Contributors

billikeu avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

rodrigez7337

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.