Skip to content

apprakash/TuniKanoon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TuniKanoon - AI Legal Assistant for Tunisian Business Law

TuniKanoon is a Telegram-based AI assistant designed to provide guidance on Tunisian business law and contract drafting, primarily for small and medium enterprises (SMEs).

Overview

This bot leverages Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) to offer concise and relevant legal information. Users can interact with TuniKanoon via text or voice messages in Telegram.

Features

  • Telegram Bot Interface: Easily accessible via Telegram.
  • AI-Powered Legal Assistance: Specializes in Tunisian business law.
  • Text and Voice Interaction: Supports both text queries and voice messages.
    • Voice messages are transcribed using OpenAI Whisper.
    • Responses can be delivered as voice messages using ElevenLabs text-to-speech.
  • Retrieval Augmented Generation (RAG): Uses a Weaviate vector database to fetch relevant legal context, enhancing the accuracy and specificity of responses.
  • Core LLM: Powered by Anthropic's Claude model.
  • Conversation History: Maintains conversation context for each user.
  • Key Commands:
    • /start: Initialize or greet the bot.
    • /reset: Clear the current conversation history and start fresh.

Tech Stack

  • Programming Language: Python 3.11.0
  • Main Libraries & Frameworks:
    • python-telegram-bot: For Telegram Bot API interaction.
    • anthropic: For interacting with Anthropic's Claude API.
    • openai: For Whisper (transcription) API.
    • elevenlabs: For text-to-speech API.
    • weaviate-client: For connecting to and querying Weaviate vector database.
    • python-dotenv: For managing environment variables.
  • AI Models/Services:
    • Anthropic Claude (e.g., claude-3-opus-20240229 or similar)
    • OpenAI Whisper (whisper-1)
    • ElevenLabs Text-to-Speech
  • Database: Weaviate (Vector Database for RAG)
  • Deployment (implied): Procfile suggests compatibility with platforms like Heroku.

Prerequisites

  • Python 3.11.0
  • Access to a Telegram Bot Token.
  • API keys for:
    • Anthropic
    • OpenAI
    • ElevenLabs
    • Weaviate (Cloud URL, API Key)
    • VoyageAI (if used for Weaviate embeddings, as suggested by utils.py)
  • A configured Weaviate instance with a collection (e.g., COLLECTION_NAME).

Setup and Installation

  1. Clone the repository:

    git clone <repository-url>
    cd Tunikanoon
  2. Create and activate a virtual environment:

    python -m venv .venv
    # On Windows
    .venv\Scripts\activate
    # On macOS/Linux
    source .venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up environment variables: Create a .env file in the root directory by copying .env.example (if one exists) or by creating a new file. Add the following variables:

    BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN"
    ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
    OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
    ELEVENLABS_API_KEY="YOUR_ELEVENLABS_API_KEY"
    
    WEAVIATE_URL="YOUR_WEAVIATE_CLUSTER_URL"
    WEAVIATE_API_KEY="YOUR_WEAVIATE_API_KEY"
    VOYAGEAI_API_KEY="YOUR_VOYAGEAI_API_KEY" # If used for Weaviate embeddings
    COLLECTION_NAME="YOUR_WEAVIATE_COLLECTION_NAME"

    Replace YOUR_..._KEY and other placeholders with your actual credentials and configuration details.

Running the Bot

Once the setup is complete and the environment variables are configured, run the bot using:

python chat_bot.py

The bot should now be active and responding to messages on Telegram.

Usage

Interact with the bot on Telegram:

  • Start a conversation: Send /start.
  • Ask questions: Send your legal or contract-related questions as text messages.
  • Send voice messages: Record and send a voice message for transcription and response.
  • Reset conversation: If you want to start a new, fresh conversation, send the /reset command.

Environment Variables

The following environment variables are required for the application to run:

  • BOT_TOKEN: Your Telegram Bot token.
  • ANTHROPIC_API_KEY: API key for Anthropic's Claude.
  • OPENAI_API_KEY: API key for OpenAI (used for Whisper).
  • ELEVENLABS_API_KEY: API key for ElevenLabs (text-to-speech).
  • WEAVIATE_URL: URL of your Weaviate cluster.
  • WEAVIATE_API_KEY: API key for your Weaviate cluster.
  • VOYAGEAI_API_KEY: API key for VoyageAI (if used for Weaviate embeddings).
  • COLLECTION_NAME: Name of the collection in Weaviate to query against.

Deployment

This project includes a Procfile:

worker: python chat_bot.py

This makes it suitable for deployment on platforms like Heroku as a worker dyno. Ensure all environment variables are set in the deployment environment.


This README was generated with the assistance of an AI coding partner.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors