Skip to main content

AI Hooks for SQLAlchemy

Project description

Shows the Memobase Workflow

Aichemy

🚧AI Hooks for your Database🚧

Aichemy is still in development and everything in this readme is a possible concept yet.

Aichemy makes it easy to use AI in your database. Consider this as an observation layer that watch the changes in DB and act when possible. With powerful AI, many seemingly complex update logics can be implemented:

  • When age is updated, combining with title to guess interested(bool, if user wants to buy our services).
  • When bio is updated, combing with name to generate a personalized sale_dm(string, content of DM)
  • ...

All you need to do is focusing on the business logic, and write the instructions clearly.

Install

pip install aichemy SQLAlchemy

aichemy only supports SQLAlchemy for now.

QuickStart

1. Design your DB

from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.orm import declarative_base, sessionmaker


class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    name = Column(String)
    title = Column(String)
    intro = Column(String)
    dm_message = Column(String, nullable=True)
    
    
engine = create_engine("sqlite:///test.db")
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)

2. Write aichemy functions

import aichemy as ac

@ac.watch(User.intro).with(User.name, User.title).to(User.dm_message)
def write_dm(row: dict, results: dict):
  """Based on the user information, write a thank-you DM for our AI product.
### Information
Name: {users.name}
Title: {users.title}
Self-Intro: {users.intro}
"""
  
  # pre-processes
  row['users.name'] = row['users.name'].capitalize()
  yield
  # post-process
  results['users.dm_message'] = results['users.dm_message'][:200]
  • row is a dict containing the values of (User.intro, User.name, User.title)
  • You can use docstring of the function to write your instructions
  • Before yield, you can modify the values inside row for pre-process. At this time, results is always empty and any changes to results is meaningless.
  • After yield, you can modify the return values inside results before they're committed to Database

3. Start watching

write_dm.start()

with Session() as session:
    user = User(name="John", title="Software Engineer", intro="I love AI and basketball")
    session.add(user)
    session.commit()

4. Debuging

Debug the prompt is easy in aichemy:

write_dm.debug({
  "users.name": "Gus",
  "title": "Founder of Memobase",
	"users.intor": "I'm a programmer",
})

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

aichemy_py-0.0.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

aichemy_py-0.0.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file aichemy_py-0.0.1.tar.gz.

File metadata

  • Download URL: aichemy_py-0.0.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for aichemy_py-0.0.1.tar.gz
Algorithm Hash digest
SHA256 09e32526238d05b80016aace6174ab05d88f7d9e0c2c48ee292a4273d3c878b8
MD5 8b77a03173c29a698c2bf35104a75790
BLAKE2b-256 b4cdc864128e9c65ae67dfcc008ef65d3e7bca3d034828e9f88eef2e9687c874

See more details on using hashes here.

File details

Details for the file aichemy_py-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: aichemy_py-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for aichemy_py-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f7d67754a80027ea9c58a8e0b54389b4a7224ed54d72081553351a1f94b3777
MD5 8ff832140f4594bc5dbb4881e5d89ca5
BLAKE2b-256 e6f41cb0cda50f4455ffcdd5437ef9cb6c39f4fbc76e7ab52c91af85edea036a

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