ada

package module
v0.0.0-...-3473fb8 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 10 Imported by: 0

README

Ada

Chat bot package similar to how Cleverbot works. It uses an "input" - "response" pair system to generate responses based on previous conversations.

Quick Start

Install using

go get -v -u github.com/stumburs/ada

Examples

Basic usage
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"

	ada "github.com/stumburs/ada"
)

func main() {
    // Create new bot instance
	bot := ada.NewAda()
    // Create new session
	session := bot.NewSession()
    // Create a reader to read user input from stdin
	reader := bufio.NewReader(os.Stdin)

    // Start interactive loop
	for {
		fmt.Print("> ")
		input, _ := reader.ReadString('\n')
		input = strings.ReplaceAll(input, "\n", "")

        // Get response and confidence score from the session
        response, confidence := session.GetResponse(input)
        fmt.Printf("%s (%.2f)\n", response, confidence)
	}
}
Load previously saved conversations
  • When creating a new bot instance.
bot := ada.NewAda().LoadDataset("dataset.json")
  • Replacing existing dataset with a new one.
bot.LoadDataset("dataset.json")
Save current dataset to file
bot.SaveDataset("dataset.json")
Manually set current dataset
bot := ada.NewAda()
newDataset := ada.Dataset{
    Pairs: []ada.MessagePair{
        {Input: "What's 2+2?", Response: "4"},
        {Input: "What's the capital of France?", Response: "Paris."},
    },
}
bot.Dataset = newDataset
Change fallback responses

[!NOTE] Currently manually changed fallback responses are not saved upon restarting the bot and will revert to the default fallback responses unless you specifically set them each time.

bot := ada.NewAda()
newFallback := []string{
    "Please try again.",
    "Can you tell me more?",
    "Please continue.",
}
bot.Fallback = newFallback

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ada

type Ada struct {
	Dataset  Dataset
	Fallback []string
	// contains filtered or unexported fields
}

Ada struct holding data shared across all Sessions created from this instance.

func NewAda

func NewAda() *Ada

Creates a new Ada instance with default parameters.

func (*Ada) LoadDataset

func (ada *Ada) LoadDataset(path string) *Ada

Loads dataset from .json dataset into Ada instance.

This operation overwrites any existing dataset in instance.

func (*Ada) NewSession

func (ada *Ada) NewSession() *Session

Creates a new session for chatting to Ada.

func (*Ada) SaveDataset

func (ada *Ada) SaveDataset(path string)

Saves dataset to .json file from current Ada instance.

This operation overwrites any existing data in file.

type Dataset

type Dataset struct {
	Pairs []MessagePair `json:"pairs"`
}

Dataset holding all 'input' and 'output' messages for Ada to use

type MessagePair

type MessagePair struct {
	Input    string `json:"input"`
	Response string `json:"response"`
}

Type MessagePair implements the most basic storage for 'input' and 'output' messages

type Session

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

Single session used for chatting with Ada.

func (*Session) GetResponse

func (s *Session) GetResponse(input string) (string, float64)

Returns best possible response to input text. If no "good enough" response could be found, returns a random string from the fallback dataset.

This function also trains the database with the new input.

2nd return parameter is response confidence. Lower score - less confident in response, higher score - more confident in response. This value ranges from [0..1] (approximately) Values below 0.2 are treated as not confident enough and will return fallback strings.

Jump to

Keyboard shortcuts

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