My buddy Dion made a great post "English will become the most popular development language in 6 years". Dion's vision is pretty expansive, but it really tickled my brain.
I've been creating a fair number of web-apps with Replit. These "agents" are awesome, they take me through the entire app process. But what if I just want a small bit of my application written in English? How far can we get?
f
is a small JavaScript library that I've created to play around with the idea of programs defined with natural language.
const isOdd = await f`is a given number odd?`;
console.log(isOdd(101))
Fun! who needs npm when when you can use an entire LLM to determine if a number is Odd or not :D
It can get a fair bit more complex. How about fetching data from a URL?
const spaceData = await f`fetch JSON from https://api.spaceflightnewsapi.net/v4/articles/`:
const news = await spaceData();
This will (in most cases) create a function that will fetch and return the data from the given URL.
Wouldn't it be nice if we could create a URL from this data?
// Describe the data structure so the the UI prompt has a better idea of what to build.
const schema = await f`Return a JSON Schema for a given object. The schema should be in the format defined in https://json-schema.org/understanding-json-schema/reference/object.html and should include all the properties of the object. The schema should include the type of the property, the format of the property, the required status of the property, and the description of the property. The schema should include all the properties of the object. The schema should include the type of the property, the format of the property, the required status of the property, and the description of the property.`;
// Describe the data
const schemeDescription = schema(spaceData);
const spaceUI = await f`Using the data defined in <output> create a UI that will best display the space flight information. The developer will provide the data as a parameter and it will be in the format defined in <output>.
<output>${JSON.stringify(schemeDescription)}</output>`;
document.body.appendChild(spaceUI(spaceData));
Fun!
I don't know if this is the future. You are heavily reliant on the LLM being good (Claude has consistently good results) - Gemini Nano and Code Llama struggle to generate valid results. Outside of simple functions it's also hard (for me) to get consistent results, so each time that you run the function it might produce a different program.
Full example:
import { create } from "@paulkinlan/f";
import {
prompt,
ClaudePromptConfiguration
} from "@paulkinlan/reactive-prompt/claude";
const config = new ClaudePromptConfiguration({ debug: true });
config.dangerouslyAllowBrowser = true;
config.key = window.prompt("API Key");
// Because we can use many different LLMs we need to pick one.
const f = create(
prompt,
config
);
const fetchNews = await f`fetch JSON from https://api.spaceflightnewsapi.net/v4/articles/`;
// Get the news.
const news = await fetchNews();
// If we can describe the object UI gnereation is a bit easier.
const schema = await f`Return a JSON Schema for a given object. The schema should be in the format defined in https://json-schema.org/understanding-json-schema/reference/object.html and should include all the properties of the object. The schema should include the type of the property, the format of the property, the required status of the property, and the description of the property. The schema should include all the properties of the object. The schema should include the type of the property, the format of the property, the required status of the property, and the description of the property.`;
const schemeDescription = schema(news);
const spaceUI = await f`Using the data defined in <output> create a UI that will best display the space flight information. The developer will provide the data as a parameter and it will be in the format defined in <output>.
<output>${JSON.stringify(schemeDescription)}</output>`;
document.body.appendChild(spaceUI(news));
Code is here - give it a go and let me know if you have any questions or ideas how you might use this (or not use it)
I lead the Chrome Developer Relations team at Google.
We want people to have the best experience possible on the web without having to install a native app or produce content in a walled garden.
Our team tries to make it easier for developers to build on the web by supporting every Chrome release, creating great content to support developers on web.dev, contributing to MDN, helping to improve browser compatibility, and some of the best developer tools like Lighthouse, Workbox, Squoosh to name just a few.
I love to learn about what you are building, and how I can help with Chrome or Web development in general, so if you want to chat with me directly, please feel free to book a consultation.
I'm trialing a newsletter, you can subscribe below (thank you!)