background

The next generation language for human and AI.

Dedicated for building AI applications.

GitHubGitHub
Latest Versionv0.2.0
cargo install aiscript

Prompt

The prompt keyword allows direct interaction with AI models. It supports both simple string inputs and advanced configurations with model parameters like temperature and token limits, making AI interactions a first-class language feature.

prompt.ai
.env
// Simple prompt usage
let answer = prompt "What is the capital of France?";
print(answer); // Paris

// Advanced syntax with model configuration
let detailed_answer = prompt {
    input: "Explain quantum computing",
    model: "gpt-4",
    max_tokens: 500,
    temperature: 0.7,
    system_prompt: "You are a quantum physics expert"
};
print(detailed_answer);

Route DSL

Define web routes with a simple, intuitive DSL that combines the clarity of RESTful design with AIScript's type system. Routes support AI-powered endpoints, path parameters, and comprehensive request validation without additional middleware.

get.ai
post.ai
put.ai
delete.ai
get /repo {
    """Repo API"""

    query {
        """repo name"""
        @string(min_len=3, max_len=30)
        name: str
    }

    return f"repo: {query.name}";
}

Enum

Enums in AIScript provide a type-safe way to define a set of named constants. With full pattern matching support and the ability to associate values with variants, enums help create more expressive and error-resistant code.

enum.ai
evaluate_enum.ai
enum Status {
  Pending   = 1,
  Active    = 2, 
  Suspended = 3,
}
fn process_status(status: Status) {
    match status {
        Status::Pending => print("Pending"),
        Status::Active => print("Active"),
        Status::Suspended => print("Suspended"),
    }
}
print(process_status(Status::Active)); // expect: Status::Active(1)

Database

Native database operations with type-safe queries and comprehensive drivers for PostgreSQL, SQLite, and Redis. The database modules support transactions, prepared statements, and result mapping to typed objects for type-safe data access.

query.ai
transaction.ai
redis.ai
project.toml
// Import postgres module from std library
use std.db.pg;

pg.query("INSERT INTO language (name) VALUES($1) RETURNING id, name;", "Rust");
let languages = pg.query("select id, name from language;");
print(languages); // expect: [1, "Rust"]
let languages = pg.query_as(Language, "select id, name from language where id > 3 limit 10;");
class Language {
    id: int,
    name: str,
}
print(languages);