Skip to main content

Create AI chatbots with a single prompt

Project description

BlockXAI Chat

A Python package that enables developers to create AI chatbots with just two lines of code. BlockXAI Chat uses Google's Gemini API to enhance simple prompts into comprehensive system prompts, which are then used with OpenAI's GPT models to generate chatbot responses.

Includes a preset Gemini API key - No need to obtain your own Gemini API key to get started!

✨ Create a Chatbot in Just Two Lines

from blockxai_chat.interface import create_and_run
create_and_run("A friendly assistant that helps users with their daily tasks.")

That's it! This will launch a beautiful Gradio interface where you can interact with your chatbot.

Features

  • Simple Prompt Enhancement: Transform basic prompts into detailed system prompts using Gemini AI
  • Gradio Interface: Beautiful, interactive web interface for chatbot creation and conversation
  • Flexible API: Use as a package in your code or run as a standalone application
  • Customizable: Configure model parameters, temperature, and other settings
  • Developer-Friendly: Create a chatbot with just two lines of code
  • Preset API Key: Includes a Gemini API key so you can get started immediately
  • Robust Error Handling: Gracefully handles API key issues and model errors
  • Latest Gemini Models: Compatible with gemini-2.0-flash for prompt enhancement
  • Optional OpenAI API Key: Provide your OpenAI API key through code, environment variables, or directly in the interface

Installation

pip install blockxai-chat

Quick Start

Method 1: The Simplest Way (Two Lines of Code)

from blockxai_chat.interface import create_and_run
create_and_run("A friendly assistant that helps users with their daily tasks.")

Method 2: Step-by-Step Approach

from blockxai_chat.enhancer import enhance_prompt
from blockxai_chat.chatbot import Chatbot
from blockxai_chat.interface import run_interface

# Define a simple prompt
simple_prompt = "A friendly assistant that helps users with their daily tasks."

# Enhance the prompt using Gemini
enhanced_prompt = enhance_prompt(simple_prompt)

# Initialize the chatbot with the enhanced prompt
chatbot = Chatbot(enhanced_prompt)

# Launch the Gradio interface with the chatbot
run_interface(chatbot)

Method 3: Using Just the Prompt

from blockxai_chat.interface import run_interface

# Just provide the prompt to the interface
run_interface(prompt="A friendly assistant that helps users with their daily tasks.")

Environment Variables

Create a .env file in your project directory with the following variable:

OPENAI_API_KEY=your_openai_api_key

Note: A Gemini API key is pre-included in the package, so you don't need to provide one unless you want to use your own key. If you want to use your own key, you can add it to your .env file:

GEMINI_API_KEY=your_gemini_api_key

Alternatively, you can provide these keys directly in your code or through the Streamlit interface.

API Reference

Enhancer Module

from blockxai_chat.enhancer import enhance_prompt

# Enhance a simple prompt
enhanced_prompt = enhance_prompt("A helpful assistant", api_key="your_gemini_api_key")

Chatbot Module

from blockxai_chat.chatbot import Chatbot

# Create a chatbot
chatbot = Chatbot(
    system_prompt="You are a helpful assistant...",
    api_key="your_openai_api_key",
    model="gpt-3.5-turbo"
)

# Get a response
response = chatbot.get_response("Hello, who are you?")

# Clear conversation history
chatbot.clear_history()

# Get conversation history
history = chatbot.get_conversation_history()

Interface Module

from blockxai_chat.interface import run_interface, create_and_run

# Run interface with an existing chatbot
run_interface(chatbot)

# Create and run a chatbot in one line
create_and_run("A helpful assistant")

Development

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
    
  3. Run tests:
    pytest
    

License

MIT License

Created By

BlockX - Simplifying AI Development

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

blockxai_chat-0.1.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

blockxai_chat-0.1.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file blockxai_chat-0.1.2.tar.gz.

File metadata

  • Download URL: blockxai_chat-0.1.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for blockxai_chat-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4a2df07fbfe4e72f4d83b72ef2a8b370cbe204c26b5d6428073287c7d0cc262b
MD5 3648d2e480dac75c704397cb568560de
BLAKE2b-256 4d1ff9c18359ad8eb06b164489dbefd69191eefa77f8490d8a3d0f40fb05e57f

See more details on using hashes here.

File details

Details for the file blockxai_chat-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: blockxai_chat-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for blockxai_chat-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4620550ad237397c79128195507bd9e845c10e98b55a6b9edc5247684faebd2f
MD5 b4287731abd0846e707e5cde20ea584e
BLAKE2b-256 4cc5f044cacd35cb8761d604c3de23f6477176eea5e5f0c26a4421178610079e

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