Skip to main content

A simple package for create chatbots using LangChain

Project description

Chatbot Context Service

This project consists of a set of classes that represent a chatbot and various context services. The chatbot uses a language learning model to interact with users and retrieve context for their questions. The context services provide different methods for retrieving context, such as through an API or from Azure.

Classes

Chatbot

The Chatbot class represents a chatbot. It has methods to initiate a chat with an AI, retrieve the context for a given question, create system and human prompt messages, and retrieve the base messages and tuple messages.

ContextService

The ContextService class is an abstract base class for context services. It provides a constructor and an abstract method for retrieving context.

APIContextService

The APIContextService class extends ContextService and provides a constructor and a method for retrieving context from an API.

AzureRAGContextService

The AzureRAGContextService class extends RAGContextService and provides a constructor and a method for retrieving context from Azure Cognitive Search.

Usage

To use these classes, you need to create instances of them and call their methods. For example, to create a chatbot and initiate a chat, you can do:

from chatbot_lib.chatbots.models import Chatbot
from chatbot_lib.mappers.messages import MessageMapper
from chatbot_lib.services.models import APIContextService
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(openai_api_key='...')

azure_rag_context = AzureRAGContextService(
    azure_key='...',
    endpoint='...',
    index_name='...'
)

message_mapper = MessageMapper()

chatbot = Chatbot(llm=llm,
                  context_services=[azure_rag_context],
                  restrictions=['Do not answer questions that deviate from the informed context'],
                  personality='Friendly, helpful, and respectful',
                  language='English',
                  base_messages=None,
                  message_mapper=message_mapper)

response = chatbot('What are your business hours?')
print(response)

Requirements

This project requires Python 3.11 or later. Several of the features are built on top of the LangChain 0.1.0 library.

License

This project is licensed under the terms of the GNU General Public License v3.0. See the LICENSE file for details.

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

simple_chatbot_lib-0.0.6.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

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

simple_chatbot_lib-0.0.6-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file simple_chatbot_lib-0.0.6.tar.gz.

File metadata

  • Download URL: simple_chatbot_lib-0.0.6.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for simple_chatbot_lib-0.0.6.tar.gz
Algorithm Hash digest
SHA256 5c971b2c524ccb50499e9afa3e56d7121c8462c0d5b8bc9c09ca72e8f902c382
MD5 f2c48a0cf76e9dccd745c06bda4a4e4d
BLAKE2b-256 b9fbbdc1ff4915e219b1a0aafb0e78caf5051b0c272db9f4a649ec931a9ea6af

See more details on using hashes here.

File details

Details for the file simple_chatbot_lib-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_chatbot_lib-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ee37729a0c4b9a2a2bbae46a8adeae525340e7c48a0610c9e30c5ffb5b6387bc
MD5 846ac5d089573cb7699033f7200a1191
BLAKE2b-256 089059b40a8168b4343617c82eccb3d2f7b33382b271645205c026448ff4a95e

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