Skip to main content

Library to build a bot from Knowledge Base

Project description

kb-bot.core

The core library of kb-bot. This handles indexing of content, and chatting with the bot.

Getting Started

pip install kb-bot.core

Preparing the KB

import os
from kb_bot import KBBot
from kb_bot.scraper import WebScraper
from kb_bot.db import TiDBProvider
from kb_bot.chunkers import SemanticChunker
from kb_bot.embedding import OpenAIEmbedClient
from kb_bot.llm import OpenAI

# Configure env variables TIDB_DATABASE, TIDB_USERNAME, TIDB_PASSWORD, TIDB_HOST, TIDB_PORT
tidb = TiDBProvider()
tidb.connect()

embed_client = OpenAIEmbedClient(
    api_key=os.environ.get('OPENAI_API_KEY')
)

scraper = WebScraper(
    urls=["https://www.pingcap.com/blog/"],
    follow_links=True,
    restrict_navigation_css=".tmpl-archive.tmpl-archive-blog",
    restrict_css=".tmpl-single-post__content",
    ignore_css=".tmpl-archive-sidebar",
    chunker=SemanticChunker(
        embedding_client=embed_client
    ),
    db_provider=tidb,
    group="<user user id or project id according to your need>",
    embedding_client=embed_client
)

scraper.crawl()

Chat with the bot

bot = KBBot(
    db_provider=tidb,
    embedding_client=embed_client,
    group="new-user-id",
    llm_client=OpenAI(
        api_key=os.environ.get('OPENAI_API_KEY')
    ),
    history=[],
    tasks_prompt="<Additional instructions to bot>"
)

response = bot.chat(message="what are the benefits of vector search ?")
print(response)

TODO

  • Add support for multiple llm(s)
  • Implement Agentic Chunker
  • Add test cases

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kb_bot_core-0.1.21.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kb_bot.core-0.1.21-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file kb_bot_core-0.1.21.tar.gz.

File metadata

  • Download URL: kb_bot_core-0.1.21.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for kb_bot_core-0.1.21.tar.gz
Algorithm Hash digest
SHA256 a95bef72955bd80dae80644ea299403fd1e1831de5d5574061f48c1956e58718
MD5 5facb40d8e826f69dd989964d6be34c8
BLAKE2b-256 3db21080c8dd98bd693b43c5fd4a47df37bedda825f9b6a04e3038040b42a08b

See more details on using hashes here.

File details

Details for the file kb_bot.core-0.1.21-py3-none-any.whl.

File metadata

  • Download URL: kb_bot.core-0.1.21-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for kb_bot.core-0.1.21-py3-none-any.whl
Algorithm Hash digest
SHA256 b104bd82d9c15bf4ded478d2a49582a4d39dfc4f0080893aa7614b466962c17e
MD5 d58c9f39fc56145e62fefb88df6ab024
BLAKE2b-256 1151571150be8b12b59bfa2bfd10e178b886ee3e065c3507be86f30b38142caa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page