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.20.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.20-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kb_bot_core-0.1.20.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.20.tar.gz
Algorithm Hash digest
SHA256 e7c5e96d99833a843b771d336a96e44eaae49394e9971fcafad5b9426ec6e03b
MD5 30e9d9317c40dc5ab227f69875b37a5f
BLAKE2b-256 36de5d4069c9f9ffde13806e0a0af3dc1006088d8828b7bf912eacdb6b9e3fbc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kb_bot.core-0.1.20-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.20-py3-none-any.whl
Algorithm Hash digest
SHA256 3a60dd2abc6e213ac78802fef7de298700153c6ed26c6b905d0f48d4ae32d728
MD5 3360c234c94d7ba947735037cd00f5e0
BLAKE2b-256 938669f2ad0edbb3b18b81756f07715b347c13f689fe94ebdca98c95b40afd08

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