vyaakaran icon indicating copy to clipboard operation
vyaakaran copied to clipboard

Grammar generation from example string

Open riya461 opened this issue 6 months ago • 1 comments

Grammar Generation Feature

Description

This PR addresses issue #14 regarding grammar generation. It introduces a new feature allowing users to generate regular grammars (RG) and context-free grammars (CFG) using natural language input through the editor console.

Prerequisites

  • An API key for one of the following services:
    • OpenAI
    • Groq
    • Claude (defined for future use, currently has CORS restrictions for browser usage)

New Feature: Grammar Generation

Usage

Users can generate grammars using the following CLI command in the editor console:

generate <grammar_type>< string > --example < example_strings>

  • <grammar_type> : rg (Regular Grammar), cfg (Context-Free Grammar), or tm (Turing Machine)
  • <description> : User input describing the desired grammar or language
  • --example <example_strings> : Optional. Comma-separated list of example strings accepted by the grammar (enhances generation accuracy)

Examples

  1. Generating a regular grammar: generate rg m number of a's followed by n number of b's | n,m>=0 --example aabb,aaa,b

  2. Generating a context-free grammar: generate cfg L={num of a in w = num of b in w, w∈{a,b}*} --example aabb,ab,aaabbb

Output

Upon successful generation, the grammar will be printed in a new playground tab corresponding to the specified grammar type.

Configuration

API Setup

  1. Create a .env file in the root folder with the following variables:

VITE_OPENAI_API_KEY=your_openai_apikey VITE_GROQ_API_KEY=your_groq_apikey VITE_ANTHROPIC_API_KEY=your_anthropic_apikey

  1. To change the active provider, modify the file: editor/src/ai/providerConfig.ts

Adding New Providers

To add a new AI provider:

  1. Create a new provider file (e.g., NewProvider.ts) in the ProviderList folder
  2. Add the new provider to ProviderFactory.ts
  3. Update providerConfig.ts to include the new provider option

Additional Changes

  • Updated help commands to include information about the new generate CLI command
  • Improved error handling during the generation process

riya461 avatar Jul 28 '24 12:07 riya461