ChatCraft week 9: Free Model Provider!
Tags: chatgpt, chatcraft, typescript, opensource
Published: 2024-03-16 05:54:39

---
series: Collaborating on ChatCraft
---

This week I got a PR merged which established a free new provider for new users to try out! So now, even if you don't have any Open Router or Open AI api keys in your name, you can try ChatCraft out with our free model provider!

Simply go to [https://chatcraft.org](https://chatcraft.org) and select Free AI Models from the Provider dropdown.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uynqdnidgqa659c3lb9q.png)

The responses from the free model won't be as good as Open AI's chatgpt or gpt4 models but you can try out ChatCraft and see what it's capable of! For example, editing prompts, saving or sharing chats, adding functions and more.

---

# Coding

{% github https://github.com/tarasglek/chatcraft.org/pull/498 %}

The free model provider endpoint was provided by Taras (see [issue](https://github.com/tarasglek/chatcraft.org/issues/401)). I created a new provider class called [`FreeModelProvider`](https://github.com/tarasglek/chatcraft.org/pull/498/files#diff-c7e5b9bfd927a8c000ef494e651239771e970ba010faacf3959ed6ebe7167dfc) which has the provider url. I also overloaded the parent class' `queryModels` function to fetch the available models. Lastly, I made the `validateApiKey` function always return true since this model does not require a key.

```
  async queryModels(key: string) {
    const res = await fetch(`${FREEMODELPROVIDER_API_URL}/models`, {
      method: "GET",
    });

    if (!res.ok) {
      throw new Error(`${res.status} ${await res.text()}`);
    }

    try {
      const result = await res.json();
      return result.data.map((model: { id: string }) => model.id) as string[];
    } catch (err: any) {
      throw new Error(`error querying models API: ${err.message}`);
    }
  }
```

The result of my `queryModels` function:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4juo0ilyhuypg0yha34a.png)

I also had to make modifications to other project files. For example, I had to make it so that when the user selects the free provider, instead of waiting for them to enter an api key, I would submit a mock key automatically which would be automatically validated. That means the moment they select the free provider they are taken to the next page where they can start using ChatCraft! See code [here](https://github.com/tarasglek/chatcraft.org/pull/498/files#diff-9fcdb80f3814fd658a3bb7dcaf58478d27938a43cde9049d449210652e77434c).

I also made many small code adjustments after getting feedback from Dave and Taras, and also debugged an issue where the logo was not appearing.

I'm very happy that this code is not in production, and the refactoring of provider code that I have been working on the last few weeks have finally paid off. Moving forward expect to see even more new providers on ChatCraft!

---

# Running Ruby on ChatCraft

I did functionality testing for my teammate Yumei's PR this week. This week she managed to allow ChatCraft to run Ruby code on the browser! Check out her [PR](https://github.com/tarasglek/chatcraft.org/pull/492#pullrequestreview-1938151470)! Also, see other PR's from this week's ChatCraft [release v.1.5.0](https://github.com/tarasglek/chatcraft.org/releases/tag/v1.5.0)!