I made a simple JavaScript to Python Converter with AI
Tags: javascript, python, ai, webdev
Published: 2024-05-26 00:59:32

Hey everyone! It's been a while since I've made a post. 
Mostly, I've been busy with random projects — analytics tools, AI stuff, and random bots…

Finally, I decided to make a side project, so I have something to post about. 😀

First things first — if you just clicked on this post so you could see my project, here's the link:
[https://ai-code-converter-best.vercel.app/convert/js-to-python](https://the-best-codes.github.io/BC_LATS/?url=https://ai-code-converter-best.vercel.app/convert/js-to-python)

## About the project
First, I needed a hosting provider. That wasn't hard to find! I just used [Vercel](https://the-best-codes.github.io/BC_LATS/?url=https://vercel.com/home), a free website for deploying React pages, APIs, serverless functions, and more. I chose React with Next.js for my frameworks.

Making this project was, in fact, very easy. The hardest part was the code editors. Textareas just look so boring! I wanted some code syntax highlighting, formatting features, etc.
I considered making something myself using Prism JS, but that got complicated. Instead, I just used Monaco editor for React, which is what VS Code is built on. If you haven't seen that, be sure to check it out! 

[https://microsoft.github.io/monaco-editor/](https://the-best-codes.github.io/BC_LATS/?url=https://microsoft.github.io/monaco-editor/)

Ugly textarea:
![so ugly](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajlfamhheyleph8wjt7r.png)

🔥 Awesome Monaco Editor 🔥
![so pretty](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3980zmew78rxer1thpv.png)


Well, after creating the code editors, the rest was a breeze. Of course, I can't have bots using my website, so you will have to complete a rather annoying bot challenge every time you convert a code. I picked [hCaptcha](https://the-best-codes.github.io/BC_LATS/?url=https://www.hcaptcha.com/), which was super easy to set up and use, plus it was free!

Then, I made a basic page layout. I'm new to React, so it took me a while to get something I liked. It's not the most mobile-friendly website in the world (sorry, phone users), but at least it works.

I had to create a simple API endpoint to handle captcha verification and API requests to my awesome AI provider, [ConvoAI](https://the-best-codes.github.io/BC_LATS/?url=https://convoai.tech/?ref=bestcodes). (ConvoAI is awesome, in case you didn't already catch that.)
Right now, the converter uses `GPT-3.5-TURBO` by OpenAI. I would use `GPT-4` (or even `GPT-4o`), but that would not be very cost-effective. 😔

The finished project looks like this:
![tada](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zusly7c24n6e804oe4d3.png)

At some point, I might make a Python to JavaScript converter (the opposite of what this one does).

Of course, this is far from perfect! There are multitudes of things the JavaScript can do which Python cannot, so not everything can be converted. Also, the AI will refuse to help you convert 'unethical' codes. I tried to convert a code that used TensorFlow to generate AI image tags for an image, but was randomly told that my code was unethical. 🤣

{% embed https://ai-code-converter-best.vercel.app/convert/js-to-python %}

## Provide feedback!
I love to know what you think about my projects. If there's a way I can improve it, or you just want to ask me about it, be sure to do so in the comments area below this post. 

Thanks for reading!

_This post is 100% by me **without** AI assistance. ✨_
_Article by [BestCodes](https://the-best-codes.github.io?dev.to=js2py_1)._