Skip to content

Latest commit

 

History

History
214 lines (138 loc) · 6.55 KB

README.md

File metadata and controls

214 lines (138 loc) · 6.55 KB

DialectMorph

Demo Gif

DialectMorph is a powerful code transpilation tool designed to convert source code from one programming language to another. It leverages the Groq API to perform intelligent code translations while maintaining the original functionality and logic.

Features

  • Supports transpilation between Python, JavaScript, Java, and C++
  • Command-line interface for easy usage
  • Automatically creates a transpiledFiles directory for output
  • By default, Utilizes Groq's language model for accurate code conversion, option to use Gemini can be specified
  • User can also provide their own API-Key to be used in this CLI Tool
  • User can also request the the list of models available in the Groq-API
  • User can also specify the model that they want to use for their use-case

Installation

  1. Clone the repository:

    git clone https://github.com/Kannav02/DialectMorph.git
    cd DialectMorph
    
  2. Install dependencies:

    To install bun, please follow this installation guide.

    bun install
    

    To skip steps 3 and 4 , you can run the following script, which will run all of these commands in a single-go

    bun run linkage:build
    
    
  3. Run the following commands to have bun build/transpile typescript files to javascript so as to run the binary

    bun run build
    
  4. Link and Install Bun Binaries in the Global Scope

    we would have to register the CLI tool globally and then also install the binaries in the global scope to make it useful in the terminal

    to register the CLI tool globally ,run the following command

    bun link
    

    after this, to install the bun binaries globally, run the following commmand

    bun link dialect-morph
    
  5. Run the following commands in the terminal to make sure that .bun/bin exists in the path variable

    export PATH="/Users/username/.bun/bin:$PATH"
    

    reload the shell config file

    source ~/.zshrc
    
  6. Set up your Groq API key:

    • Create a .env file in the root directory or run the following command in the shell

      cp .env.example .env
      
      
    • Add your Groq API key: GROQ_API_KEY=your_api_key_here

    • Add your Gemini API key: GEMINI_API_KEY=api_key_goes_here

Configuration via TOML file

You can specify your preferred settings for the CLI tool by creating and editing a TOML configuration file. It will allow you to customize the default options to tailor the tool's behaviour to your needs. Learn more about TOML on the official website.

The arguments that can be specified in the dialectMorph.config.toml:

  • api_key - provide the API key to be used
  • model - set the Large Language Model of choice
  • language - specify the output programming language
  1. A sample configuration file sample.dialectMorph.config.toml is provided in the repository.
  2. To create your own configuration file, run the following command:

To create your own configuration file in your home directory, run the following command:

cp sample.dialectMorph.config.toml ~/dialectMorph.config.toml

Important! - Make sure that the config file you create is named dialectMorph.config.toml, as the tool will be looking for this specific file in your home directory.

Usage

Run DialectMorph using the following command:

Main Command

dialectMorph <input_files...> -l <output_language>

The input_files argument can take multiple files at once and is a required argument the output_language argument is also a required argument

Examples:

Take one of the files from the examples folder and run the following command

dialectMorph ./examples/example.py -l java
dialectMorph ./examples/example.cpp -l python

Optional Arguments

  • a (--api_key) This command is one of the optional arguments and can be used with the main command or the lm command (see below)

    Command

    dialectMorph ./examples/examples.py -l C++ -a YOUR_API_KEY
    
    
  • m (--model) This command is one of the optional arguments and can be used with the main command to specify the model that you want to be used to fetch the request , by default the model is llama3-8b-8192 for Groq and gemini-1.5-flash for Gemini

    BE CAREFUL TO ONLY USE A MODEL NAME THAT EXISTS AFTER YOU USE THE LM OPTION OTHERWISE THE PROGRAM WILL THROW AN ERROR

    Command

    dialectMorph ./example/example.py -l java -a YOUR_API_KEY -m MODEL_NAME
    
    
  • lm (--list_models) This command can be used on its own without the need to provide any files and is used to fetch the list of models that are available on Groq, it can also take an API-Key as one of the optional arguments

    Command

     dialectMorph -lm -a YOUR_API_KEY
    
    
  • t (--token) This command is one of the optional arguments and can be used with the main command to specify the desire to see how many tokens are consumed (i.e., prompt tokens, completion tokens, and total tokens) from making a request to the Groq API.

     dialectMorph ./examples/example.py -l java -t
    
    
  • gem (--gemini) This command is used to indicate to the CLI tool that Gemini LLM would be used to generate the code that would be used in the transpiled files, if this option isn't provided, groq is used by default

    dialectMorph ./examples/example.py -l java -gem
    
    

Supported Languages

  • Python (.py)
  • JavaScript (.js)
  • Java (.java)
  • C++ (.cpp)

Project Structure

  • index.ts: Main entry point and CLI logic
  • LLMHandler.ts: Handles interactions with Groq API and Gemini API
  • fileHelper.ts: Utility functions for file and directory operations

Contributing

Please see CONTRIBUTING.md for details on how to contribute to this project.

License

This project is licensed under the MIT License.

Acknowledgements

  • Groq SDK for providing the language model API
  • Gemini SDK for providing the a secondary language model API
  • Commander.js for CLI argument parsing
  • Figlet for ASCII art text generation
  • Chalk for terminal styling
  • Ora for terminal spinner
  • VHS for making the demo video for the CLI tool
  • Prettier for maintaining consistent formatting throughout the code
  • TOML for parsing the contents of the config file