Skip to main content

A simple (for the moment) package that allows you to implement the back-end of a ai chat-bot with openai models in python.

Project description

ChatWeaver

ChatWeaver is a Python library that simplifies the implementation of chatbots powered by OpenAI models. Designed with developers in mind, it provides powerful features and an intuitive interface to enhance the development of conversational AI.


Features

  • Chat History Management: Easily track and manage conversation context.
  • Message Templates: Automatically remember and include previous messages in prompts.
  • File Integration: Add images and PDF files to your prompts seamlessly.
  • Custom Model Support: Compatible with various OpenAI models.
  • Extensibility: Flexible architecture for scalable chatbot solutions.

Installation

Install ChatWeaver using pip:

pip install chatweaver

Quick Start

Here’s how you can get started with ChatWeaver:

import chatweaver as cw

model = cw.Model(
    model="gpt-4o", 
    api_key="<Your OpenAI API key here>"
    )

bot = cw.Bot(
    rules=cw.chat_weaver_rules["basic"], 
    name="AiBot", 
    cw_model=model
    )

chat = cw.Chat(
    replies_limit=10, 
    user="Diego", 
    cw_bot=bot
    )

prompt = "Hi how are you?"
print(chat.get_response(prompt=prompt))

Include images and files

You may also include images and files in the prompt by specifying their file paths.

prompt = "Describe the content of the attached image."
image = "path\\to\\image.png"
print(chat.get_response(prompt=prompt, image_path=image))

Implementation of Model Rules

ChatWeaver allows the customization of chatbot behavior through a set of predefined rules, defined in the variable chat_weaver_rules. These rules determine the role, style, format, and ethical guidelines the bot must follow. Each rule is designed to suit specific scenarios, enhancing interactivity and consistency in the conversation.

Available Rules

  1. basic: Sets the bot with scientifically accurate and reliable goals. Includes:
    • No text formatting.
    • Friendly and respectful communication.
    • Complete and contextual responses.
    • Strict ethical standards.
  2. default: Optimizes the bot to keep the conversation flowing in a JSON format. Main features:
    • Single-line responses using \n.
    • JSON structure with keys like reasoning, reply, result.
  3. informal_chat: Adjusts the bot for informal conversations. Key features:
    • Friendly and conversational language.
    • Simple JSON response format.
  4. formal_chat: Adapts the bot for formal conversations. Includes:
    • Polite and respectful communication.
    • Formal JSON structure.
  5. formal_email: Optimizes the bot for formal email exchanges. Features:
    • Adherence to email structure with greetings, body, and closing.
    • Detailed JSON responses.

Implementation Example

To use a specific rule in your bot:

import chatweaver as cw

# Configure the model
model = cw.Model(
    model="gpt-4o",
    api_key="<Your OpenAI API key here>"
)

# Configure the bot with a specific rule
bot = cw.Bot(
    rules=cw.chat_weaver_rules["basic"],
    name="AiBot",
    cw_model=model
)

# Create the chat
chat = cw.Chat(
    replies_limit=10,
    user="Diego",
    cw_bot=bot
)

# User prompt
prompt = "Hello, how are you?"
response = chat.get_response(prompt=prompt)
print(response)

Requirements

  • Python 3.8 or above.
  • OpenAI Python library (openai).

Whats new in 0.1.4?

  • Implemented a new method for creating chats while ensuring backward compatibility with the existing system.
  • Enhanced the Bot's capabilities by enabling it to remember the user's name along with its own.

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

chatweaver-0.1.4.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

chatweaver-0.1.4-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file chatweaver-0.1.4.tar.gz.

File metadata

  • Download URL: chatweaver-0.1.4.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for chatweaver-0.1.4.tar.gz
Algorithm Hash digest
SHA256 54b2f3a198b33db3ecc90f4dd89326b3ed9ef7c0a7408459f44d4558e6d5b4b2
MD5 75e405feaf6605db47aba73f392e44c7
BLAKE2b-256 8a44d29bd3113a85cbd0cb6b28c746de44f3660c9e92070cbb20624befaf26e7

See more details on using hashes here.

File details

Details for the file chatweaver-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: chatweaver-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for chatweaver-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a8840312ed1f70adcaa88b73659770b95dd83d79e4fde7d0ca4fecda10ef7e27
MD5 a0800337818e058aebf3e9d59d117e66
BLAKE2b-256 73682c93d602f8843f84e06ce9451b3e636e8e17444859fb7989d2c78b64f9d5

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