Skip to main content

A lightweight AI engineering toolkit for building natural language interfaces that are reliable, scalable, and easy to trust.

Project description

PyPI version Docs Twitter Follow

Astro

The AI engineering toolkit

Astro is a lightweight AI toolkit for building natural language interfaces that are reliable, scalable, and easy to trust.

Each of Astro's tools is simple and self-documenting, using AI to solve common but complex challenges like entity extraction, classification, and generating synthetic data. Each tool is independent and incrementally adoptable, so you can use them on their own or in combination with any other library. Astro is also multi-modal, supporting both image and audio generation as well using images as inputs for extraction and classification.

Astro is for developers who care more about using AI than building AI, and we are focused on creating an exceptional developer experience. Astro users should feel empowered to bring tightly-scoped "AI magic" into any traditional software project with just a few extra lines of code.

Astro aims to merge the best practices for building dependable, observable software with the best practices for building with generative AI into a single, easy-to-use library. It's a serious tool, but we hope you have fun with it.

Installation

Install the latest version with pip:

pip install askastro -U

To verify your installation, run astro version in your terminal.

Tools

Astro consists of a variety of useful tools, all designed to be used independently. Each one represents a common LLM use case, and packages that power into a simple, self-documenting interface.

General

🦾 Write custom AI-powered functions without source code

Text

🏷️ Classify text into categories

🔍 Extract structured entities from text

🪄 Transform text into structured data

Generate synthetic data from a schema

Images

🖼️ Create images from text or functions

📝 Describe images with natural language

🏷️ Classify images into categories

🔍 Extract structured entities from images

🪄 Transform images into structured data

Audio

💬 Generate speech from text or functions

✍️ Transcribe speech from recorded audio

🎙️ Record users continuously or as individual phrases

Video

🎙️ Record video continuously

Interaction

🤖 Chat with assistants and use custom tools

🧭 Build applications that manage persistent state

Quickstart

Here's a whirlwind tour of a few of Astro's main features. For more information, check the docs!

🏷️ Classify text

Astro can classify text using a set of labels:

import astro

astro.classify(
    "Astro is so easy to use!",
    labels=["positive", "negative"],
)

#  "positive"

Learn more about classification here.

🔍 Extract structured entities

Astro can extract structured entities from text:

import pydantic


class Location(pydantic.BaseModel):
    city: str
    state: str


astro.extract("I moved from NY to CHI", target=Location)

# [
#     Location(city="New York", state="New York"),
#     Location(city="Chicago", state="Illinois")
# ]

Almost all Astro functions can be given instructions for more control. Here we extract only monetary values:

astro.extract(
    "I paid $10 for 3 tacos and got a dollar and 25 cents back.",
    target=float,
    instructions="Only extract money"
)

#  [10.0, 1.25]

Learn more about entity extraction here.

✨ Generate data

Astro can generate synthetic data for you, following instructions and an optional schema:

class Location(pydantic.BaseModel):
    city: str
    state: str


astro.generate(
    n=4,
    target=Location,
    instructions="cities in the United States named after presidents"
)

# [
#     Location(city='Washington', state='District of Columbia'),
#     Location(city='Jackson', state='Mississippi'),
#     Location(city='Cleveland', state='Ohio'),
#     Location(city='Lincoln', state='Nebraska'),
# ]

Learn more about data generation here.

🪄 Standardize text by casting to types

Astro can cast arbitrary text to any Python type:

astro.cast("one two three", list[int])

#  [1, 2, 3]

This is useful for standardizing text inputs or matching natural language to a schema:

class Location(pydantic.BaseModel):
    city: str
    state: str


astro.cast("The Big Apple", Location)

# Location(city="New York", state="New York")

For a class-based approach, Astro's @model decorator can be applied to any Pydantic model to let it be instantiated from text:

@astro.model
class Location(pydantic.BaseModel):
    city: str
    state: str


Location("The Big Apple")

# Location(city="New York", state="New York")

Learn more about casting to types here.

🦾 Build AI-powered functions

Astro functions let you combine any inputs, instructions, and output types to create custom AI-powered behaviors... without source code. These functions can can go well beyond the capabilities of extract or classify, and are ideal for complex natural language processing or mapping combinations of inputs to outputs.

@astro.fn
def sentiment(text: str) -> float:
    """
    Returns a sentiment score for `text`
    between -1 (negative) and 1 (positive).
    """

sentiment("I love working with Astro!") # 0.8
sentiment("These examples could use some work...") # -0.2

Astro functions look exactly like regular Python functions, except that you don't have to write any source code. When these functions are called, an AI interprets their description and inputs and generates the output.

Note that Astro does NOT work by generating or executing source code, which would be unsafe for most use cases. Instead, it uses the LLM itself as a "runtime" to predict function outputs. That's actually the source of its power: Astro functions can handle complex use cases that would be difficult or impossible to express as code.

You can learn more about functions here.

🔍 Classify images (beta)

In addition to text, Astro has beta support for captioning, classifying, transforming, and extracting entities from images using the GPT-4 vision model:

astro.beta.classify(
    astro.Image("docs/images/coffee.png"),
    labels=["drink", "food"],
)

# "drink"

Record the user, modify the content, and play it back

Astro can transcribe speech and generate audio out-of-the-box, but the optional audio extra provides utilities for recording and playing audio.

import astro
import astro.audio

# record the user
user_audio = astro.audio.record_phrase()

# transcribe the text
user_text = astro.transcribe(user_audio)

# cast the language to a more formal style
ai_text = astro.cast(user_text, instructions='Make the language ridiculously formal')

# generate AI speech
ai_audio = astro.speak(ai_text)

# play the result
ai_audio.play()

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

askastro-1.0.0.tar.gz (26.9 MB view details)

Uploaded Source

Built Distribution

askastro-1.0.0-py3-none-any.whl (96.0 kB view details)

Uploaded Python 3

File details

Details for the file askastro-1.0.0.tar.gz.

File metadata

  • Download URL: askastro-1.0.0.tar.gz
  • Upload date:
  • Size: 26.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for askastro-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c10707b36853ff40aa48db4feaad561bd9053ce4673eaba2f660ef8db6cb0325
MD5 08b70de5039725c3eae777e8f20b2bf2
BLAKE2b-256 665bd9054e5ac794c8d72df814984233d7cf5cd16376f0207872b295ac2c428c

See more details on using hashes here.

File details

Details for the file askastro-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: askastro-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 96.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for askastro-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ee023b26fac67cf6a5e8e31e50b48339929f31f31bb6fbd079d2417862c1204
MD5 905f54345eac43309c932af095fe02b9
BLAKE2b-256 6083de486c76e7053b750cb34db407e6e717c5214ab16a73a69d4daa4d2f15c6

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