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.3.tar.gz (44.5 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.3-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_chatbot_lib-0.0.3.tar.gz
  • Upload date:
  • Size: 44.5 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.3.tar.gz
Algorithm Hash digest
SHA256 481bc2d897aa1844cc259407c956b960a2e020e620bcbee15dc15e90af5d265c
MD5 9ed5add1df8dc882a1cca58988c1a488
BLAKE2b-256 d6b88563d0120464c1b6ddc3b9cc75f829ac71cea4537e949a8ae24f2efbd983

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_chatbot_lib-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a3cf81b4a48ec5a123b193bbdbd3827e9af07c38a18eb39c703487fc2946930
MD5 937105c2427f5ffe4390e501d1635d0b
BLAKE2b-256 4a28510d44b600972ad564ed8423e3e568dbd394e8850338ad4218bd1727b51e

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