Skip to content

Latest commit

Β 

History

History
94 lines (75 loc) Β· 3.76 KB

File metadata and controls

94 lines (75 loc) Β· 3.76 KB

Leximancy

Weave words into wonder.

Leximancy is a web application that explores the creative potential of AI. It takes a random set of words and uses a generative AI model to either form a coherent sentence from them or infer the user's deeper semantic intent.


✨ Core Concept

The user is presented with a set of randomly chosen words. They can then "cast leximancy" to send these words to a server-side AI flow. The AI model processes these words and returns a new, elegant sentence. An experimental mode is available to interpret the meaning behind the words rather than just using them literally.


πŸ› οΈ Tech Stack


πŸ“‚ Project Structure

Here is a simplified overview of the most important files and directories in the project.

/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ page.tsx        # Main application component and UI
β”‚   β”‚   └── layout.tsx      # Root layout
β”‚   β”œβ”€β”€ ai/
β”‚   β”‚   β”œβ”€β”€ genkit.ts       # Genkit initialization and model configuration
β”‚   β”‚   └── flows/
β”‚   β”‚       β”œβ”€β”€ generate-coherent-sentence.ts   # AI flow for standard mode
β”‚   β”‚       └── semantic-inference-experimental.ts # AI flow for experimental mode
β”‚   β”œβ”€β”€ components/       # Reusable UI components (Shadcn/ui)
β”‚   β”œβ”€β”€ hooks/            # Custom React hooks
β”‚   └── lib/
β”‚       β”œβ”€β”€ words.ts        # The master list of words
β”‚       └── utils.ts        # Utility functions
β”œβ”€β”€ public/               # Static assets
β”œβ”€β”€ firebase.json         # Firebase hosting configuration
β”œβ”€β”€ next.config.ts        # Next.js configuration
└── package.json          # Project dependencies and scripts

🌊 How It Works: The Flow of Data

Here is a step-by-step breakdown of the process, from a user's click to the AI-generated response.

  1. User Action: The user clicks the "Cast Leximancy" button in the browser.
  2. Frontend Logic (page.tsx):
    • A set of random words is selected from the master list in src/lib/words.ts.
    • The UI is updated to show these new words.
    • An asynchronous call is made to a server-side Genkit flow, passing the selected words as an argument.
  3. Backend AI Flow (/src/ai/flows/):
    • The Genkit flow (running on the server) receives the words.
    • It constructs a specific prompt, instructing the AI on how to handle the words.
    • This prompt is sent to the Google Gemini API.
  4. AI Processing: The Gemini model processes the prompt and generates a new, coherent sentence.
  5. Data Return:
    • The Gemini API returns the sentence to the Genkit flow.
    • The Genkit flow returns the sentence to the frontend.
  6. UI Update:
    • The frontend receives the sentence and displays it to the user.
    • The session history is updated with the words and the resulting sentence.

πŸš€ How to Run Locally

  1. Clone the repository.
  2. Install dependencies:
    npm install
  3. Set up your environment variables: Create a .env.local file in the root directory and add your Google AI API key:
    GEMINI_API_KEY=your_api_key_here
    
  4. Run the development server:
    npm run dev
  5. Open http://localhost:3000 in your browser.