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

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_chatbot_lib-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 4682e6f565da485705465e8a129f456b2569f9d1b492313e5377b8f298042b19
MD5 695f888d12143e9a73a04a07c9191588
BLAKE2b-256 923bc78e0b5583babd2268019706edf913df617ab2e70fd854921a7c4988314f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_chatbot_lib-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1e335e90672af673123c0ee2d136e11f23a5e1dd4b97e7d7fa8bc7996bbc7a52
MD5 56fa176c75f0f5804cc31d370ea32a13
BLAKE2b-256 c03ef4cad8f1f991e69b9418c8915ced1906ea150ff35112265e473a2ab31bba

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