npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apple-intelligence

v1.0.0

Published

Interact with Apple Intelligence through JS

Downloads

77

Readme

apple-intelligence

The NPM package to interact with Apple Intelligence through JavaScript.

Note: This is powered through app automation. It will only work locally on Mac devices. Learn more about how this works.

API

This package gives you access to 4 Apple Intelligence Writing Tool commands (Rewrite, Make Friendly, Make Professional, Make Concise), as well as the ability to directly ask a query to or chat with Apple Intelligence through a Prompt Injection. All methods are asynchronous.

Writing Tool Commands

The 4 Writing Tool commands simply take a single input with your prompt.

import { rewrite, friendly, professional, concise } from "apple-intelligence";

console.log(await rewrite("Hello, world"));
console.log(await friendly("Hello, world"));
console.log(await professional("Hello, world"));
console.log(await concise("Hello, world"));

Ask AI Command

This command takes a input, and uses a prompt injection so you can get a normal LLM-like response. You can also choose to:

  1. Pass in a history of prior conversations as context in the format [userQuery, assistantResponse][] (Default [])
  2. Choose which command the injection runs with. Pass in a Writing Tool function. (Default rewrite)
import { askAI, professional } from "apple-intelligence";

// Ask normally
console.log(await askAI("What is 1+1?"));

// Ask with context
console.log(
	await askAI("Bear", {
		history: [
			["Cat", "Meow"],
			["Dog", "Woof"],
		],
	})
);

// Ask with another command
console.log(
	await askAI("What's 1+1?", {
		command: professional,
	})
);

Chat Class

The Chat class automatically handles history for you. When creating the class, you can optionally pass in history and a command to use, just like the askAI function.

The Chat.ask() method takes one argument, the query.

import { Chat, professional } from "apple-intelligence";

// Chat normally
let myChat = new Chat();
console.log(await myChat.ask("Who's the first president?"));
console.log(await myChat.ask("Who came after him?"));

// Chat with configuration
let otherChat = new Chat({
	history: [["Who's the first president?", "George Washington"]],
	command: professional,
});

How does this work?

Under the hood, it opens the TextEdit app, with a file that has the input as content, and uses Writing Tools to apply the command to the app. Then, it waits until the text can be copied (showing that the writing tools have completed), then returns the text in that file. It also closes the file without saving to reduce garbage buildup.

Because this is automation based, results may be unexpected. I am not responsible if anything goes wrong in the automation process, though it should rarely be destructive in any way. Please report anything that goes wrong in issues, or submit a PR to fix it.