Refiner
Tags: opensource, openai, nextjs
Published: 2023-08-10 13:04:57

I created a [Refiner](https://refiner.roman.pt), an open-source project that automatically fixes grammar and stylistic errors. It can also adjust the tone and formatting.

That is addictively useful. Now, pretty much all my git commit messages, comments to Jira tickets, and Slack comments pass through the wisdom of this tool. The post you are reading has also gone through a series of refinements.

## How does it help me?

It helps minimize any non-native speaker quirks. Sometimes, I struggle with complex grammar constructions or end up using expressions that don't quite exist. I'm sure my English writing has a noticeable Russian accent, even if I can't hear it. The refiner helps me make my writing sound more natural to native speakers.

Also, it's a lifesaver when I'm tired. There are times when my brain power is low and I can't express my thoughts clearly. My writing ends up sounding clumsy. For example, after a long day of research, when I need to share my findings with colleagues. Also, when I'm tired, my text can unintentionally come across as pessimistic or aggressive. The "friendly" and "positive" refiners help me make my text more appropriate without sounding fake.

It even does some of the work for me. I recently added an experimental "Finish the sentence" feature. Sometimes, we write things that are easy to predict. When I catch myself writing one of these clichés, I stop my sentence midway and add XXX to let the refiner complete it. Surprisingly, it works well for things like installation instructions and model definitions.

## How does it work?

The refiner is basically a wrapper around OpenAI GPT. It takes the prompt, sends the request to OpenAI, and then formats the response to show the difference.

## Why not use ChatGPT?

Initially, I used ChatGPT for this task, but I encountered two issues:

- I had to repeat the same prompt over and over again, with slight contextual modifications.
- More importantly, I had to proofread the entire text generated by GPT to make sure it didn't add any nonsensical stuff and still "sounded like me."

With Refiner, I save time by not having to type the prompt and only reviewing the highlighted parts of the text.

## How can you use it?

Since it's an open-source tool, you can run it yourself. The source code is available at [https://github.com/imankulov/refiner](https://github.com/imankulov/refiner). The only thing you need to pass is an OpenAI API token.

I also set up a testing installation at [https://refiner.roman.pt/](https://refiner.roman.pt/), where you can test it for free without SMS and registration. At least, for now.

## How much does it cost?

I was initially concerned about the cost of making it free and public. How much would it be worth for me to use it regularly?

I estimated the number of used tokens [here](https://platform.openai.com/tokenizer), and checked the prices [here](https://openai.com/pricing). Given this text as an example, it has roughly 600 tokens. Instructions take about 100-200 tokens depending on the number of refiners. Therefore, reformatting the text would take about 800 input tokens and 600 output tokens.

**The cost of editing this text is less than a quarter of a cent.**

I'm fine with running the tool without any guardrails, as long as it's just me, my friends, and anyone who stumbled upon this blog post and finds the tool helpful.