DEV Community

Ingi
Ingi

Posted on

My web admin is a chat

This article is about the Plang programming language, intent based programming language written in natural language. For more info checkout plang.is

When you write code in Plang, you write it as intent of what you would like to happen. For example

- read file.txt into %content%
Enter fullscreen mode Exit fullscreen mode

This will read the content of the file.txt file and load into the variable %content%.

To convert your statement into an executable code, we need to send it to LLM service, which will understand your intent and map it to the correct functionality.

This LLM service is running at llm.plang.is. Like for any service you need some admin management tool, for example, list out registered users, get the revenue for the day, give some user some credit on his account, etc.

The usual way to do this is to create a admin web interface, for llm.plang.is, there is a chat client and no web interface.

Like with any admin system you need to implements some methods that you want to have, I have 3 of them. These methods are called Goals in the Plang language

  • AddAmount
  • ExecuteSql
  • SystemStatus

Those 3 goals gives me all I need at the moment, in the future I might need more. Before I go into those method, lets see how this is possible in plang in few lines of code

My first step is to listen to a message from a specific address. Plang uses the Nostr protocol underneath but you don't really see that, just tell it what you want :)

Start
- list to message from %Settings.AdminAddress%, 
    call !ProcessMessage content=%message%
Enter fullscreen mode Exit fullscreen mode

When a new message comes in from the %Settings.AdminAddress% (this is nostr public address), it should call the ProcessMessage goal and load the content into the %message% variable.

ProcessMessage
- read file llm/processMessageSystem.txt into %system%
- read file llm/processMessageAssistant.txt into %assistant%
- [llm] system: %system%
        assistant: %assistant%
        user: %message%
        model: 'gpt-4-0125-preview'
        scheme:  {goalName:string, parameters:any}
- call goal !admin/%goalName% %parameters%
Enter fullscreen mode Exit fullscreen mode

We start by loading the content from processMessageSystem.txt and processMessageAssistant.txt into the variables %system% and %assistant%.

Those two files contain information for the LLM, it states that there are 3 goals available to choose from and how it should format the parameters for each goal.

On my phone, I have a Nostr client setup, this client has the address the server is waiting for messages from.

When I send the message add $10 to user id 7, the ProcessMessage will determine that I want to call the AddAmount goal. It then formats the parameters as {userId:7, amount:10}.

The AddAmount goal looks like this

AddAmount
- begin transaction
- insert into transaction %userId%, %amount%, 'free'
- update users set balance=balance+%amount% where id=%userId%
- end transaction
- send message to %Settings.AskUserMessageAddress%, 
    content: Amount set on userId:%userId%
Enter fullscreen mode Exit fullscreen mode

Shortly after I send the message, I get a message back confirming that the amount has been added.

I can then send the server,

tell me the revenue for the last 24 hours and 7 days
Enter fullscreen mode Exit fullscreen mode

The ProcessMessage will decide to call the ExecuteSql goal. The ExecuteSql goal has all the database information it needs to construct the sql to get this data. It looks something like this

ExecuteSql
- read file tableInfo.txt into %tableInfo%
- [llm] system: construct a SELECT sql statment to fullfill user request
    assistant: %tableInfo%
    user: %message%
    scheme:{sql:string}
- execute %sql%, write to %result%
- [llm] system: format these result from sql database to send to a user. 
        assistant: "Results: %result%"
        user: %message%
        write to %messageResponse%
- send message to %Settings.AskUserMessageAddress%, 
    content: %messageResponse%
Enter fullscreen mode Exit fullscreen mode

I now receive the information I requested sent to my Nostr client.

For system status, I can ask

how are you feeling
Enter fullscreen mode Exit fullscreen mode

Where he will call the SystemStatus goal, which runs top for 5 iteration, and sends back the information collected, but of course well formatted by the LLM

The benefits?

  • The time saved is huge, not having to setup web framework.
  • The security is much much higher, since there is no username and password to login.
  • All communication is signed, making it even securer.
  • I have huge range of data analyses, supporting all I need
  • Total lines of code are less than 100 🤯

And that is how I have no web admin on my llm.plang.is server

To discover more about Plang you can checkout our Github repo

Top comments (0)