Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar generation from example string #25

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

riya461
Copy link
Contributor

@riya461 riya461 commented Jul 28, 2024

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

Copy link

vercel bot commented Jul 28, 2024

@riya461 is attempting to deploy a commit to the Akash Hamirwasia's projects Team on Vercel.

A member of the Team first needs to authorize it.

@blenderskool blenderskool linked an issue Aug 10, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grammar generation from example strings
2 participants