modulepackage
0.0.0-20230525095016-77c214fe4dc7
Repository: https://github.com/lonelycode/botmaker.git
Documentation: pkg.go.dev
# README
botMaker
A Go library to help create and train AI bots quickly with OpenA and PineCone. It is heavily based on code from the excellent vault-ai project.
Sample Usage
A simple chatbot:
func Chat() {
cfg := Config{
OpenAPIKey: "xxxx",
PineconeKey: "xxxx",
PineconeEndpoint: "xxxx",
}
// Client
cl := NewOAIClient(cfg.OpenAPIKey)
// Settings for the AI
bs := NewBotSettings()
bs.ID = "a-UUID-here"
// Build a prompt using the default template
pr := NewBotPrompt("", cl)
pr.Instructions = "You are an AI assistant that provides answers that are helpful in a friendly and cheerful way."
pr.Body = "What is the best way to scale a redis database?"
// Create some storage
pc := &Pinecone{
APIEndpoint: cfg.PineconeEndpoint,
APIKey: cfg.PineconeKey,
UUID: bs.ID,
}
// attach memory
bs.Memory = pc
oaiResponse, _, err := cl.CallUnifiedCompletionAPI(bs, pr)
if err != nil {
fatal("query send fail: %v", err)
}
fmt.Println("FIRST PROMPT:")
fmt.Println(pr.RenderedPrompt)
fmt.Println("GOT FIRST RESPONSE: ")
fmt.Println(oaiResponse)
time.Sleep(5 * time.Second)
// we do some string shenanigans to make a chatbot
// First: Update the context
oldBody := "Human: " + pr.Body
pr.ContextToRender = append(pr.ContextToRender, oldBody)
// Next make sure the AI's response is added too
pr.ContextToRender = append(pr.ContextToRender, oaiResponse)
// Replace the main query with a new one
pr.Body = "How is a cluster different from sentinel?"
// Make the call!
secondResponse, _, err := cl.CallUnifiedCompletionAPI(bs, pr)
if err != nil {
fatal("prompt2 fail: %v", err)
}
fmt.Println("SECOND RESPONSE")
fmt.Println(secondResponse)
}
Learning from a PDF
func TestLearning() {
cfg := Config{
OpenAPIKey: "xxx",
PineconeKey: "xxx",
PineconeEndpoint: "xxx",
}
// Client
cl := NewOAIClient(cfg.OpenAPIKey)
// Create some storage
pc := &Pinecone{
APIEndpoint: cfg.PineconeEndpoint,
APIKey: cfg.PineconeKey,
UUID: "a45dbe63-4207-419c-bca7-5d940bf3d908",
}
l := Learn{
Model: openai.GPT3TextDavinci003,
TokenLimit: 8191,
ChunkSize: 20,
Memory: pc,
Client: cl,
}
_, err := l.FromFile("/data/socrates.pdf")
if err != nil {
fatal(err)
}
}
# Packages
No description provided by the author
# Functions
No description provided by the author
GetContexts will use OpenAI to get vectors for the prompt, then use Memory to retrieve relevant contexts to include in the query prompt.
No description provided by the author
No description provided by the author
NewBotSettings Returns settings for OpenAI with sane defaults.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
# Structs
BotPrompt has the components to make a call to OpenAPI.
BotSettings holds configs for OpenAI APIs.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author