Skip to main content

AGI.green Framework

Project description

AGI.green Framework

A modern Python framework for building AI-powered asynchonous chat applications with a browser interface, featuring markdown content rendering and a unified messaging system.

Application can be built entirely in Python or can integrate with arbitrary external services. This differs from conventional full stack solutions with a javascript frontend application making API calls to a Python backend. Instead, the frontend is a slave and the backend is the application.

Features

  • Unified Message Protocol: Consistent message handling across different communication channels
  • Rich Content Support:
    • Markdown rendering
    • Mermaid diagrams
    • MathJax equations
    • Code syntax highlighting
  • Flexible Architecture:
    • WebSocket-based real-time communication
    • AMQP integration for distributed systems
    • Extensible protocol system
  • AI Integration:
    • OpenAI API support
    • Anthropic Claude support
    • Custom model integration capability
  • Asynchronous Execution:
    • Non limited to call and response
    • Can add chat messages in response to arbitrary events, e.g. incoming email or SMS or task completion
    • Can execute arbitrary code in response to a message or other events

Quick Start

  1. Install dependencies:
# Install RabbitMQ
sudo apt-get install rabbitmq-server  # Ubuntu/Debian
brew install rabbitmq                 # macOS

# Install package
pip install agi.green
  1. Create a basic chat application:
from agi_green.dispatcher import Dispatcher

class ChatNode(Dispatcher):
    async def on_mq_chat(self, author: str, content: str):
        'Receive chat message from RabbitMQ'
        await self.send_ws('append_chat', content=content)

    async def on_ws_chat_input(self, content: str = ''):
        'Handle chat input from browser'
        await self.send_mq('chat', 
            author=self.name,
            content=content
        )

Protocol System

The framework uses a protocol-based architecture where each protocol handles specific types of communication:

  • ws: WebSocket communication with browser
  • mq: RabbitMQ for peer-to-peer messaging
  • gpt: OpenAI API integration
  • http: HTTP/HTTPS server
  • Custom protocols can be added by extending the base Protocol class

Message Formatting

Support for rich content in messages:

# Markdown with syntax highlighting
await self.send_ws('append_chat',
    content='```python\nprint("Hello")\n```'
)

# Mermaid diagrams
await self.send_ws('append_chat',
    content='```mermaid\ngraph TD;\nA-->B;\n```'
)

# Math equations
await self.send_ws('append_chat',
    content=r'\\( \int x dx = \frac{x^2}{2} + C \\)'
)

Development Status

Currently in active development (March 2024). The framework is being used in production but the API may have breaking changes.

Requirements

  • Python 3.11+
  • RabbitMQ server
  • Modern web browser

Contributing

Contributions are welcome! Please check our Contributing Guidelines for details.

License

Copyright (c) 2024 Ken Seehart, AGI Green. See LICENSE 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

agi_green-0.2.4.tar.gz (6.2 MB view details)

Uploaded Source

Built Distribution

agi.green-0.2.4-py3-none-any.whl (6.3 MB view details)

Uploaded Python 3

File details

Details for the file agi_green-0.2.4.tar.gz.

File metadata

  • Download URL: agi_green-0.2.4.tar.gz
  • Upload date:
  • Size: 6.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for agi_green-0.2.4.tar.gz
Algorithm Hash digest
SHA256 81d84c55aefcd4f4ebe716dc14f36edaec5fa475734bfb60778efd6322c8ec3f
MD5 aaa9e83dc96322782976ebc868ba0c0f
BLAKE2b-256 9d8fc8246a46c37cb6d4bd231df645e6db4af0bd02a2e6835f809176b94bf6b6

See more details on using hashes here.

File details

Details for the file agi.green-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: agi.green-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 6.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for agi.green-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a22b82d741b674cab0c5fbf5780dfe0b4cbda4238c92b0ba0059a0f400f17965
MD5 3caf1e47c889ce5c627366e1057ae547
BLAKE2b-256 ec0abe5039579d9b154d904149dc4cd072e493a64d627cd465451a4919129a26

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page