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')
    )
)

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

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.19.tar.gz (10.3 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.19-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kb_bot_core-0.1.19.tar.gz
  • Upload date:
  • Size: 10.3 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.19.tar.gz
Algorithm Hash digest
SHA256 5fad4a2739bed12eab5ce7926296d40019f362b6dbc052d1a06cba2a69156523
MD5 cdc7616bc0546ff4a48cb1b7ce38eb7d
BLAKE2b-256 07ac3bfff36c5464bb9abe1245cef7fd9a42ff0fb07059539e9cb21c45ae9dda

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kb_bot.core-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 10.5 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.19-py3-none-any.whl
Algorithm Hash digest
SHA256 b9bc407026bbfb92c16ec67eac1f3346293b6ba51cd71fa86f0007238ae7af40
MD5 2b468fb8a6cc7266997ad9871620926e
BLAKE2b-256 3a02ef285d03d3c8692e511c64ff17102d31132b6ca0867065e243bc7a6f75ff

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