Joining ChatCraft.org
Tags: opensource, ai, openai, webdev
Published: 2024-01-13 07:18:48

There is no doubt that [Artificial Intelligence](https://en.wikipedia.org/wiki/Artificial_intelligence) is the **future**, not just of **IT**, but any **domain** you could think of. 

Just last month, I was chilling in office and one of the testers on my team called me for a quick **chit-chat**. He sounded worried and was confused if his son should get into **programming**, as he feared that **AI** would render programmers **obsolete** soon. Even though, I tried to convince him that nothing of the sort is happening in the near future, it didn't help much. This goes on to show how much of an impact AI has had on people's lives since last year, and the **importance** of staying up-to-date with it.

Not long ago, if anyone ever thought of **experimenting** with AI, they would imagine themselves in the middle of a **research lab** working on **complicated** models and algorithms. However, the release of [OpenAI API](https://openai.com/blog/openai-api) has not only lowered the **entry barrier** for AI experimentation but has also given rise to lots of innovative tools, making the once seemingly complex world of AI way more **approachable**.

![OpenAI API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ufhv6wk7cfwsoapdnxr.png)

This semester, I am taking my second [open-source](https://en.wikipedia.org/wiki/Open_source) course [OSD700](https://wiki.cdot.senecacollege.ca/wiki/OSD700) allowing the students to manage an existing open source project and taking it to the next [major release](https://www.techtarget.com/searchsoftwarequality/definition/release).

And this term, we have a **super interesting** project called [ChatCraft](https://github.com/tarasglek/chatcraft.org/). This was a **cheerful surprise** for me as I've already contributed to this project a few times last term.

These are the **posts** for more context.
1. [No backing away when hacking away 🎃🚀](https://dev.to/amnish04/no-backing-away-when-hacking-away-2h27)
2. [Enhancing Sidebar](https://dev.to/amnish04/contributing-to-chatcraft-55pj)

## Table of Contents
&nbsp;1. [What is ChatCraft ⁉️](#what-is-chatcraft)
&nbsp;2. [Setting up the Project ⚙️](#setting-up-the-project)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.1. [Generating an SSH key](#generating-an-ssh-key)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.2. [Adding my key to the project](#adding-my-key-to-the-project)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.3. [Decrypting the KEY 🔐](#decrypting-the-key)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.4. [Saving the key in ChatCraft 💬](#saving-the-key-in-chatcraft)
&nbsp;3. [How do I feel](#how-do-i-feel)

## What is ChatCraft ⁉️

[ChatCraft](https://chatcraft.org/c/jbQxTEc_q62TUHnlCWCYA) is a developer-oriented [GPT](https://www.iotforall.com/what-does-gpt-stand-for) client, that extends upon OpenAI's [ChatGPT](https://chat.openai.com/) by allowing various additional functionalities like **forking** from chats like in [Github](https://github.com/), image and graph generation, **customisable** response rules, and support for image inputs (coming soon).

My professor [David Humphrey](https://github.com/humphd) is a major contributor for this project and in his words,
> ChatCraft is a kind of R&D laboratory for exploring emerging technologies and techniques for working with LLMs. It will allow us to explore and build all kinds of interesting things together, from advanced UX (multi-modal prompting, voice assistants, mobile, etc.) to embedding native code in the web (run non-JS programming languages in the browser via WASM) to cloud computing (data syncing) to working with the latest AI models.

![ChatCraft Demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ht72wp010q2akxx05ay.png)

Apart from all these extra functionalities, the biggest advantage it offers is that its **open source**, which means **you can choose** how it works by [contributing](https://github.com/tarasglek/chatcraft.org/blob/main/CONTRIBUTING.md) to the project.

But the most shocking part for me was that even the **Creator of Javascript** knows **ChatCraft**.

https://x.com/humphd/status/1743346747382935854?s=46&t=2CRGLNQI0xDqULxhK1Fi6w

![Creator of Javascript knows ChatCraft](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqjhu5r6olpbgll0nzbs.png)

## Setting up the Project ⚙️

Now that I knew I was part of the team and would be contributing to it throughout the term, the **first step** was to setup the project.

Since I was a previous contributor, I already had it cloned on my machine. However, [OpenAI](https://openai.com/) is **not free** and one thing that was left to do was getting and saving my API key 🔑. The **project owner** [Taras Glek](https://github.com/tarasglek) was **generous** enough to buy it for all the students who would be contributing.

As much as it sounds, this process **wasn't** as **straightforward** since the project was using [SOPS](https://medium.com/@seifeddinerajhi/the-sops-way-the-only-way-to-keep-your-secrets-safe-in-git-4a17e83ef6c6) to manage [secrets](https://delinea.com/what-is/application-secrets)!

As I was hearing this term for the first time, I had to do some research and I found this article
https://medium.com/@seifeddinerajhi/the-sops-way-the-only-way-to-keep-your-secrets-safe-in-git-4a17e83ef6c6

![SOPS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3j7m35qhe5gbkccm9gv.png)

Now that I had some basic idea about what craft SOPS (**S**ecure **Op**eration**s**) was, I went through the [README](https://github.com/tarasglek/chatcraft.org/blob/main/README.sops.md) file, that specifically focused on working with secrets using **SOPS**. With that, I started following the **steps** mentioned.

### Generating an SSH key

The first step was to generate an [ed25519 ](https://ed25519.cr.yp.to/) - [ssh key](https://www.ssh.com/academy/ssh-keys) for my Github account.

This was **fairly simple** as I had done it multiple times in the past.

```bash
ssh-keygen -t ed25519 -C "amnishsingh04@gmail.com"
```

It gave me some prompts like **key location**, private key **passphrase**, and I chose defaults.

![ssh-keygen prompts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xo27xebhklk8c2foz7qv.png)

After the **key pair** was generated, I copied the **public key**

![ssh key pub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kc4ld4ia83f32lourswx.png)

and added it to my github account

![Adding ssh key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gu7cj0e2gmgm9ancix5.png)

I skipped adding it to the [ssh agent](https://smallstep.com/blog/ssh-agent-explained/) as I has chosen an **empty passphrase**.

### Adding my key to the project

Next, I had to [ask the project admins](https://github.com/tarasglek/chatcraft.org/pull/326) to encrypt and include my key into the project.

![Request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bd17obxztwgyz1vb2hcz.png)

And soon, my [age encrypted](https://pkg.go.dev/filippo.io/age) API key was included in [.sops.yaml](https://github.com/tarasglek/chatcraft.org/blob/main/sops/.sops.yaml) and [keys.enc.yaml](https://github.com/tarasglek/chatcraft.org/blob/main/sops/keys.enc.yaml) file.

![age key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kcg1fj3n1sy81ghc251u.png)

### Decrypting the KEY 🔐

The final step was to decrypt the **API key** to be used in **ChatCraft**.

The instructions were simple and included in [**README.sops.md**](https://github.com/tarasglek/chatcraft.org/blob/main/sops/README.sops.md).

After installing the **dependencies**,
```bash
# install prereqs
go install github.com/getsops/sops/v3/cmd/sops@v3.8.1
go install github.com/Mic92/ssh-to-age/cmd/ssh-to-age@latest
```

```bash
export SOPS_AGE_KEY=scripts/sops_age_key.sh

sops -d sops/keys.enc.yaml
```

However, this did not work out for me.

![Decrypt Fail](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlpgqpusfjei6ui5qrpw.png)

After banging some head against the wall, I figured out that `export SOPS_AGE_KEY=scripts/sops_age_key.sh` wasn't actually returning the result of the [**script**](https://github.com/tarasglek/chatcraft.org/blob/main/scripts/sops_age_key.sh).

**The Script**
```bash
#!/bin/bash

# Source the library script
SCRIPT_DIR=$(dirname "$(realpath "$0")")
source "$SCRIPT_DIR/lib/ssh-to-age.sh"

# Define the path to your private SSH key
SSH_PRIVATE_KEY_PATH="$HOME/.ssh/id_ed25519"

# Find the ssh-to-age binary using the library function
BINARY_PATH=$(find_ssh_to_age_binary)
if [ $? -ne 0 ]; then
    exit 1
fi

# Convert the SSH private key to an age private key using the library function
AGE_PRIVATE_KEY=$(convert_ssh_private_key_to_age "$BINARY_PATH" "$SSH_PRIVATE_KEY_PATH")
if [ $? -ne 0 ]; then
    exit 1
fi

# Output the age private key
echo "$AGE_PRIVATE_KEY"
```

It looked like it was retrieving my **ssh private key**

![retrieve private key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsm1570eicpd6knwtrqp.png)

and echoing the **result** after converting to an [age](https://github.com/FiloSottile/age) private key

![age key result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4gda2g3tfwvtkbjd0et.png)

I decided to run the script manually and use the returned result for the next steps.

```bash
./scripts/sops_age_key.sh

> AGE-xxxxxxxxxxxxxxxxxxxxxxxxxx
```

```bash
export SOPS_AGE_KEY=<The returned key>

sops -d sops/keys.enc.yaml
```

And **finally**, I got the key…

Hope you weren't reading till now in hopes I'd accidentally reveal it 😉

### Saving the key in ChatCraft 💬

Now that I had the key, it was time to test it in the application.

![Pasting api key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hv762ybh33iar0220lgz.png)

After clicking **Save**, I was routed to the main page with my first chat automatically created.

![Main Screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhp7f5vft4yarshwaeug.png)

I tried a couple of test conversations and fortunately, it was working as expected!

![ChatCraft Working](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxg6romg2y2b0j99c40k.png)

## How do I feel

In this post, I talked a bit about the importance of **AI** and how I am getting a chance to explore and experiment with one of the most popular [LLMs](https://en.wikipedia.org/wiki/Large_language_model) out there.

Although I am **excited** to contribute, I am also **intimidated** at the same time as I feel like venturing into completely **uncharted territory**. So much so, that my **voice** cracked up while **introducing** myself in the **first meeting** (this has never happened in a long time). 

I've never worked with AI before, I've never **managed** a real project as a team. Seems like there are tonnes of challenges waiting for me on the way, but I am **glad** I am getting a chance to **face them**.