Hyperlambda, a Web Query Language
We've just launched a new addition to Magic, which is our Natural Language API. The thing is built upon Hyperlambda, so it's "a bajillion" times faster than anything similar built in Python, and a code-gen request probably costs less than 1 cent. In fact, the average request executes in 1 to 4 seconds, allowing you to literally create API methods "on the fly", which again allows you to treat the web as a "queryable database". Examples of things you can ask it are ...
- "Scrape ainiro.io and return the first 5 hyperlinks you find"
- "Return all links from the sitemap at ainiro.io NOT containing /blog/"
- "Invoke Chuck Norris API and return some random joke"
- "Invoke Chuck Norris API and return some random joke"
To understand, consider the following request; "Scrape ainiro.io and return the first 5 external Hyperlinks you find" - Which results in the following JSON being returned.
[
"https://seattleballooning.com",
"https://github.com/polterguy/magic",
"https://docs.ainiro.io/",
"https://www.2xplain.nl/",
"https://app.fintell.ai"
]
Instant API
Due to its speed, you can literally depend upon it dynamically generating your code on the fly, by semantically scraping web pages for information. In the following video I'm walking you through parts of its implementation.
Implementation
The way it works, is as follows.
- A natural language request comes to the server
- Magic checks its database to see if it's previously succeeded in generating code for the request
- If it finds cached code, it executes the code and returns the result of the execution
- If it does not find a cached result, it generates the code, stores it in its cache, executes it, and return its response
This means that on the first invocation it takes between 1 to 4 seconds to generate the specified code. Consecutive requests executes in 150ms, implying it's faster than Python. In fact, it's got roughly 10 better performance and throughput than Python according to tests we've conducted previously.
Wrapping up
If you want to play with this, you can clone Magic, install the "natural-language-api" plugin, and test it from Hyper IDE. If this is too much hassle, you can also purchase a cloudlet from us.