CLI ChatGPT Client in PHP

For my personal use, I created a CLI ChatGPT client a few months ago. It has been very useful for me to have it available in the CLI quickly whenever I needed it (caveat, you need an API key!).

Unfortunately, for larger responses it can feel very slow, whereas the web version feels quite fast. But this is perceived speed because it shows you each word as it arrives and not just the whole response when finished (after all it is a completion AI that generates the response word by word).

So now, I have added streaming support to it. It now feels almost too fast :) The CLI has a few nice things such as readline support (i.e. you can go back to old queries with the up key) and it keeps all of your conversation in a text file. All of this in only 100 lines of PHP.

Posted in web

What is Matrix?

I am working on bringing Matrix to the WordPress community (see also the WP Tavern post) and part of this is also to explain what Matrix actually is, so I wrote up a few paragraphs that I’d like to share here:

Matrix is an internet-based chat system like Slack or Microsoft Teams with a few key differences:

Open Source

It is open source (Apache License 2.0). Thus it includes the four freedoms (run it for any purpose, modify it, distribute it or a modified version).

Federated

There is no centrally controlled server, similar to e-mail (or ActivityPub): to send and receive e-mail, you need to have an account on a mail server. In Matrix, these servers are called homeservers.

When you send messages, these messages are first sent from your client (computer or phone) to the server, from the server to the recipients’ servers (in e-mail, you manually list them, in Matrix, these are all other people in the room), and then the messages are delivered to the individual participant’s clients. The benefit of this is that the client (like a mobile phone app) doesn’t need to be connected when the server receives the message and can catch up when it comes back online. 

For this reason, Matrix account addresses look similar to e-mail (or Mastodon) addresses but they have the format @username:server.tld. Starting when a member of a homeserver joins a room, their homeserver will maintain a full, up-to-date copy of the chat room. Any message sent by others in the room will be sent to every participating homeserver. For this reason, joining a room can take a while because the server needs to (partially) populate its local copy from other homeservers. Because of the real-time nature of chat, the messages are exchanged very quickly between the homeservers as soon as that connection has been established.

A Matrix server can also be run in unfederated mode where it will not communicate with other servers on the internet, thus enabling a closed community. This decision can also be made on a room-by-room basis.

Encryption

Matrix rooms can be either unencrypted and openly discoverable, or end-to-end encrypted and invite-only. Because the server has no knowledge of contents or encryption keys, the latter need to be shared between the individual client software of a user. This is established through a verification step in which you use your other/old client to establish trust with the new one. Until this has happened, any encrypted communication is inaccessible.

Open Protocol

The Matrix protocol (and all of its updates, called MSC) is publicly available and can be implemented by any software. There are a couple of server implementations with best known ones by Element themselves, called Synapse (Python based) and Dendrite (Go based). Clients are easier to implement through Matrix provided SDKs that do the heavy lifting of encryption and protocol communication.

Free Choice of Clients

For the above reason, there is a wide selection of clients for mobile and desktop, different operating systems, text based, etc. We have developed a WordPress plugin called Chatrix that allows embedding Matrix inside a WordPress post or page which allows something like we demonstrated in this GIF:

Posted in web

Keeping Family History with WordPress

One thing that I like very much about my family is the anecdotes and stories. One thing that I am bad at, is reciting them.

So I had this idea to create something like a private Wikipedia for my family, where each person has their own page and family members can contribute to the stories, biographical data, and media.

Initially, I set up a MediaWiki, i.e. the same software that Wikipedia uses. It turns out, it’s not that easy to configure. The new Wiki editor is much better than directly editing wiki syntax but the complexity is high for a small project like that. Also, uploading media is quite a pain because of the importance of licensing metadata. In a private wiki, you’ll want the UI to get out of the way.

So, since I work with WordPress a lot, I had the idea to use WordPress for it. There are a number of wiki plugins for WordPress but they all seemed overly complex and not really geared towards a use case of users collaborating on creating a site.

Thus, I created my own WordPress plugin called Family Wiki, available for now at https://github.com/akirk/family-wiki/

WordPress has the advantage that you can set it up very quickly and got many options for setting it up. Plus, when you have already multiple blogs (e.g. for family members) on your domain, it’s easy to just add another blog to your WordPress multisite. The plugin works on a standalone blog, too.

Here are some screenshots that I made as a demo:

Posted in web

Using Jetpack Blocks without a connection to WordPress.com

Recently I wanted to use a Jetpack block for the WordPress Gutenberg editor, specifically the Slideshow Block, which I think is very slim and elegant compared to other Slideshow blocks on the WordPress.org plugin directory.

The one thing I didn’t want to do, though, is to connect my site to WordPress.com. For the most part because I didn’t intend to use any of the functionality that requires the WordPress.com connection.

The difficulty in this: normally, you can’t actually use Jetpack until you connect the site to your WordPress.com account. This behavior is in place so you can enjoy a friction-less experience after the connection is established (i.e. you can activate any of its features whether or not it needs the connection).

In my case, the connection is not needed for using the Slideshow block since it works with the local media library.

So, I present not a hack but an official way to use Jetpack without a WordPress.com connection: it’s called Offline Mode.

You activate it by adding a constant or filter to your wp-config.php, for example:

define( 'JETPACK_DEV_DEBUG', true );

While it is intended for local installs and actually development, it is useful if you just want to use a single feature of Jetpack that doesn’t require the connection.

Many people say that Jetpack is slow because it’s so big. It is indeed huge from a file size and feature perspective, but also it’s very optimized, so that it will only load the PHP or JS code it needs. The other files lay dormant in your file system and don’t contribute to the loading or rendering time of your site.

Posted in web

Reducing Our Dependency On Third-Party Platforms For Our Online Activity

There is something that I feel is not right with today’s web structure. We, as the population of the web, create so much content that ends up on servers of large companies. We could own our data.

Therefore, I’d like to help reduce everyone’s dependency on third party platforms for their online activity.

Vision

You use your own server for publishing and interact with other people’s content on their server.

Since everybody follows this method, your content only reaches the people it is meant for, without involving a third party in the distribution.

You interact using the same means of today: web UI, mobile apps; the difference is that they don’t talk to a third-party server, neither for publishing nor getting and interacting with others’ content.

I am trying to create a solution for this with WordPress and the Friends plugin.

Note: in the following text I use the word “server” somewhat synonymous for the WordPress+Friends setup but it there could be alternative implementations. Also, server doesn’t mean “a dedicated machine somewhere,” you just need web space where you can install WordPress, which doesn’t mean it has to be expensive. For example, wpfriends.at is hosted for €1,90/month incl. domain.

Separation of Content

Today, separate social networks exist for different types of content; for example short content has its home on Twitter, Instagram is for photos. Facebook is a mix of this but allows for private content. Instant messengers like WhatsApp (or Facebook groups) are very clear about who the content or conversation is for.

So, separating content makes for a more homogeneous experience when consuming the content, also you have a good grasp of where (and for whom) you want to publish your content.

On your own server, you can separate out different types of content as well (in WordPress this is called “post formats”). You can also post something privately, only giving access to authenticated users.

Adding a friend and subscribing to multiple platforms on which they publish

The key is to connect the different types appropriately. By fetching the content from your friends and placing them in such “buckets,” you now have the option to view everyone’s content from multiple perspectives: everything from a single friend (or a group) across content types, or everything across friends of just one content type.

By continuing to use specialized apps for different types of content, you keep the benefits but exclude the third-party having full access to the content since they now talk to your own server.

Platforms

The possibility to publish on the Internet by using your own server (most of the time: rented web space) is well-established since blogging was invented. It can become clunky when you interact with others: how do I respond?

That’s why there are several reasons why platforms are appealing:

  • It’s easy to connect with others on the same platform.
  • Leveraging network effects is easier since the platform knows who is connected to whom.
  • Spam is usually under control.

Thinking back to the era of blogging, we had lots of interactions with others using comments and pingbacks. What mainly led to its demise was automated spam which reduced everybody’s willingness to be open for interaction. Commenting meant moderating spam.

Core

So one of the core features of the Friends plugin is to solve the authentication problem between people you know and trust.

When you decide “to become friends” with someone, it means that you both get (low privilege) accounts on each other’s servers.

You can give them permission to see your privately published content, or not. When you want to respond to their post, you are automatically authenticated on their side.

This means that you could close comments for unauthenticated users (thus eliminating spam) but keep the discussion open for your friends.

Transitioning

Using your own server still has a learning curve. Getting started with a self-hosted WordPress and installing the Friends plugin is not as trivial as creating an account on a social network.

While it has become considerably easier to register a domain, get webspace connected, and a WordPress installed, there are still many further steps until you really can get started.

So, reality is that your friends likely won’t be migrating off third-party networks. Possibly never.

To still allow yourself to disconnect, the Friends plugin allows you to follow your friends across different (possibly third-party) channels including popular social networks like Twitter.

You can subscribe to someone on Twitter and their messages will be aggregated on your server under their user, in the respective post format.

This means that you can either view all the content (that you follow) for a single friend, or you can view the aggregate type of content, e.g. all the short messages your friends posted across services.

Not only for “real” Friends

Many use social networks to not only follow people they know and trust, but also to follow the news or celebrities. Despite the name of the Friends plugin, it can also do that.

You can subscribe any supported content (some out of the box, for others you can extend it with plugins) but not go into the friendship realm.

Your server takes care of fetching the content from various third-party sources and you can then consume the content in the way you see fit:

  • The local “Friends UI” on your own server,
  • an RSS reader,
  • or more specialized clients like mobile apps.

Ads

One side-effect of this could possibly be that this removes our content from being wrapped in ads and websites trying to have us spend as much time as possible on their site.

We’d all spend a little money for domain and server every month or year for our own gain. We don’t need to put ads to our content.

For journalistic content it is already not uncommon for tech publications to provide an ad-free RSS feed as part of their paid subscription.

More Ideas

You can use your server to store more things, for example:

Your personal bookmark collection and todo lists (I have a work-in-progress for transitioning my previous project called thinkery.me to a WordPress plugin thinkery to host this yourself and use the Android app as a client).

Leverage your aggregated content as your own browser start page (my WordPress plugin called Startpage).

Right now, this is only implemented for WordPress, and the authentication is only leveraged for consuming private content and posting comments. But it doesn’t need to end there.

The authentication could be used for further actions, for example you could give posting permissions to your friends to create a (private) forum, hosted by you or a friend.

The Friendship protocol is a REST API that can be implemented in other software as well.

The Friends plugin is open source and GPL.

Work in Progress

How far along the way is the Friends plugin? It’s already well usuable for your own purposes. Like I said above, you can establish friendships between servers and consume your friends’ content, even from third-party social networks.

There is still a lot to do, especially around commenting and notifications. Better tools are needed for leveraging network effects, like search your friends+ posts and explore their friends (if they allow you to do so).

Posted in web

Pocketbook Color

I read a lot of web articles on my e-reader (often using Push to Kindle which is fantastic). I left the Kindle ecosystem a while ago and Pocketbook (a TouchHD 3) has been a good home so far.

Since my content is often a mix of text and non-text, I was appealed by a color eInk screen. The Pocketbook Color recently came out and I purchased one to test it.

Here are my conclusions after about two weeks of usage:

Pro

  • While limited in their range, colors work well for diagrams, illustrations and screenshots. Photos can look a bit awkward but it’s definitely better than greyscale.
  • Before this e-reader, I haven’t read comics on a device but with color it’s quite fun. The clipping tools in the UI are useful to get rid of white borders around the actual comics.

Con

  • It’s not very suitable for night time reading (which is my main use case), the minimum brightness is high, there is only white backlight.
  • With the strong white backlight it feels like an LCD screen which kind of diminishes the idea behind eInk.
  • The technology seems to use two layers: one “common” 300dpi greyscale, and one around 150dpi color layer. This results in a pattern overlaying the whole screen making the screen less crips when reading text.
  • Pocketbook readers are rather slow. I always wonder how they do scrolling and inertia so much better than Kindles but feel so. slow. navigating through the UI.

Overall, I think color eInk is technology well worth exploring, especially when no backlight is necessary and it doesn’t need any battery power (think photo walls)

I am torn whether I’ll keep the Pocketbook Color as my main reading device because using the reader in the dark is like turning on the light in the room.

Posted in web

Decentralized Social Networking with WordPress

Over the past year, I’ve been working on the side on a WordPress plugin that implements an idea that has been growing in me over the last couple of years. Decentralized Social Networking. The plugin that does it is called Friends.

Starting with the frustration that there are few alternatives for people who use Facebook: if you don’t want them to own your data but still want to privately keep your friends and family up to date about your live and discuss what interests you, where do you go?

I realize that many people just switched to instant messaging (like WhatApp) which does allow exchanging private messages (and photos) with your friends, but overall I do like the idea of having a more structured publishing platform. I just don’t like a single entity to control it all.

So I realized: We actually had an alternative all along: blogging.

Blogging is decentralized: you decide where you host, you decide which blogs you read and nobody really knows which ones you have subscribed to.

What disqualifies it as an alternative to my wish to keep friends and family up to date, is that it public by default. While there is the option to publish something as “private,” there is not a lot you can then do with a privately published post.

So what if you were easily able to give your friends access to your private posts?

Here comes the Friends plugin. And with it, the downside to the solution:

You need to have your own blog to become friends with each other.

Right now, this is only implemented on WordPress, the technology is framework agnostic, though.

Your friends get their own user on your blog. Here my request is still pending.

When everyone involved has their own blogging platform and they’d decide where they want to host, we automatically get a decentralized platform.

The technological ingredients to this are actually pretty old:

  • RSS
  • REST API
  • Authentication via keys

After friendship has been established (this involves both parties accepting friendship and exchange private keys in the background), your server will use that key when requesting your friend’s RSS feed which will in turn (since you are friends) contain private posts. And vice versa.

For commenting, you’ll go to your friend’s blog, it’s a one-click-authentication away. This can also eliminate spam if you only allow friends to comment on your posts.

All of this is highly compatible with standard WordPress: if you want to accept a friend request on your mobile phone, use the WordPress iOS or Android app and change that user’s role to “Friend.”

Chicken-and-egg problem: I use a social network because all my friends are there.

So why use a social network that not all of your friends use (yet)? Because the Friends plugin is actually a pretty decent way to consume RSS feeds.

Since it is based on RSS, it means you can also subscribe any blog or website that offers this well-established way of distributing content.

As you are in control of the server, you can also decide what you’re interested in and tailor the feeds to your liking: you can define rules for incoming feed items and ignore posts you know you won’t be interested in.

I personally like to consume notifications via e-mail as it provides read/unread functionality and I can sort and categorize e-mails to my needs. You can now also read your friends’ posts (or subscriptions) via e-mail. But you don’t need to.

Another method to view your friend posts and subscriptions is the “Friends Page,” a timeline of friend posts and subscriptions. You can therefore scroll down the list of your friend’s posts and subcriptions, just as you see it people doing it all the time on Facebook.

Read your friends’ posts on the Friends Page

There is quite a bit more to this, you can Emoji react to a post, recommend it specifically to friends, have sections in your posts for friends/not-friends, and more.

Overall, I see this as a way to take blogging to the next level: Choose your private audience. Choose where you host. Publish publically if it’s meant to be public.

It’s clear that setting up and having your own blog is not (yet) for everyone. It’s more work than just signing up for some social network. Often you’ll need to pay for hosting (and domain). But it also gives you the freedom to take your data somewhere else if you want to. Or delete it.

We’ll have to see who will use this. As of now, it’s for a technical audience but maybe someday there will be dedicated Friends-WordPress hosting?

The Friends Plugin is open source under GPL2. If you have a WordPress blog, try it out, and if you think this could be better, different, enhanced: create an issue, or better: create a patch and send a pull request.

Probably it’s not ready for prime time yet, we’re at version 0.14. But it’s getting there, at least I am already using it daily :) There are many ideas left to be implmented, and these are only mine so far.

Oh, if you happen to be in Vienna coming week, I’m going to talk about Decentralized Social Networking with WordPress at our WordPress meetup on November 7, 2018.

November WordPress Meetup Vienna

Wednesday, Nov 7, 2018, 6:30 PM

CodeFactory Vienna
Kettenbrückengasse 23/2/12 Wien, AT

29 People Attending

Schedule 18:30 | Arrival, Registration 19:00 | Welcome & Introduction 19:15 | Alex Kirk – Decentralized Social Networking with WordPress 19:45 | Break 20:00 | Harry Martin – Hello to 5.0, a first look at the next major release and the new theme Twenty Nineteen 20:30 | Socialising! 21:00 | Leaving CodeFactory, maybe for drinks somewhere close by __…

Check out this Meetup →

Posted in web