DEV Community

Cover image for πŸ”₯ I made a simple JavaScript to Python Converter with AI πŸ”„
Best Codes
Best Codes

Posted on

πŸ”₯ I made a simple JavaScript to Python Converter with AI πŸ”„

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

About the project

First, I needed a hosting provider. That wasn't hard to find! I just used Vercel, 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/

Ugly textarea:
so ugly

πŸ”₯ Awesome Monaco Editor πŸ”₯
so pretty

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, 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. (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

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. 🀣

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.

Top comments (0)