vyaakaran
vyaakaran copied to clipboard
Grammar generation from example string
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
-
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
-
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
- 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
- To change the active provider, modify the file:
editor/src/ai/providerConfig.ts
Adding New Providers
To add a new AI provider:
- Create a new provider file (e.g.,
NewProvider.ts
) in theProviderList
folder - Add the new provider to
ProviderFactory.ts
- 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