Categorygithub.com/go-aie/gptbot
modulepackage
0.0.0-20230905142120-914b2b830c70
Repository: https://github.com/go-aie/gptbot.git
Documentation: pkg.go.dev

# README

GPTBot

Go Reference

Question Answering Bot powered by OpenAI GPT models.

Installation

$ go get -u github.com/go-aie/gptbot

Quick Start

func main() {
    ctx := context.Background()
    apiKey := os.Getenv("OPENAI_API_KEY")
    encoder := gptbot.NewOpenAIEncoder(apiKey, "")
    store := gptbot.NewLocalVectorStore()

    // Feed documents into the vector store.
    feeder := gptbot.NewFeeder(&gptbot.FeederConfig{
        Encoder: encoder,
        Updater: store,
    })
    err := feeder.Feed(ctx, &gptbot.Document{
        ID:   "1",
        Text: "Generative Pre-trained Transformer 3 (GPT-3) is an autoregressive language model released in 2020 that uses deep learning to produce human-like text. Given an initial text as prompt, it will produce text that continues the prompt.",
    })
    if err != nil {
        fmt.Printf("err: %v", err)
        return
    }

    // Chat with the bot to get answers.
    bot := gptbot.NewBot(&gptbot.BotConfig{
        APIKey:  apiKey,
        Encoder: encoder,
        Querier: store,
    })

    question := "When was GPT-3 released?"
    answer, _, err := bot.Chat(ctx, question)
    if err != nil {
        fmt.Printf("err: %v", err)
        return
    }
    fmt.Printf("Q: %s\n", question)
    fmt.Printf("A: %s\n", answer)

    // Output:
    //
    // Q: When was GPT-3 released?
    // A: GPT-3 was released in 2020.
}

NOTE:

  • The above example uses a local vector store. If you have a larger dataset, please consider using a vector search engine (e.g. Milvus).
  • With the help of GPTBot Server, you can even upload documents as files and then start chatting via HTTP!

Design

GPTBot is an implementation of the method demonstrated in Question Answering using Embeddings.

architecture

Core Concepts

ConceptsDescriptionBuilt-in Support
PreprocessorPreprocess the documents by splitting them into chunks.✅[customizable]
Preprocessor
EncoderCreates an embedding vector for each chunk.✅[customizable]
OpenAIEncoder
VectorStoreStores and queries document chunk embeddings.✅[customizable]
LocalVectorStore
Milvus
FeederFeeds the documents into the vector store./
BotQuestion answering bot to chat with./

License

MIT

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
NewBot support single and multi-turn chat request.
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

# Constants

No description provided by the author
No description provided by the author
GPT-3.5.
No description provided by the author
No description provided by the author
No description provided by the author
GPT-4.
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
GPT-3 (not recommend).
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

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
OpenAIChatEngine is an engine powered by OpenAI's Chat API /v1/chat/completions.
OpenAICompletionEngine is an engine powered by OpenAI's Completion API /v1/completions.
No description provided by the author
Preprocessor splits a list of documents into chunks.
No description provided by the author
No description provided by the author
No description provided by the author
Turn represents a round of dialogue.

# Interfaces

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
No description provided by the author