Skip to content

lech-kalinowski/Spaceman-Speech

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spaceman Speech - Prompt Optimizer

A local prompt optimizer that compresses verbose English prompts into compact Spaceman Speech to reduce LLM token usage — without using a heavy LLM. Built with a Windows 95 retro UI.

Python FastAPI License

How It Works

Verbose prompt  -->  Spaceman Compressor  -->  Optimized prompt (fewer tokens, same meaning)

The compressor uses local NLP only (spaCy + sentence-transformers) to:

  1. Strip politeness, filler words, and hedge phrases
  2. Lemmatize and compress common verbose phrases
  3. Restructure into prompt-engineering best practices (ROLE/TASK/CONSTRAINTS/OUTPUT)
  4. Score variants by token count + semantic similarity
  5. Auto-select the best compression

Example

Original (76 tokens):

I would like you to act as a senior data analyst. Could you please take a look at our quarterly sales data and provide me with a comprehensive summary of the key trends? Specifically, I need you to identify which product categories are performing well and which ones are underperforming. Please present your findings in a clear bullet point format and include percentage changes compared to the previous quarter.

Space Marine (40 tokens, 47% saved):

ROLE: senior data analyst. TASK: check quarterly sale data, find product category perform well, find underperforming. OUTPUT: bullet point format, include percentage changes, compare previous quarter.

Compression Strategies

Strategy Description Typical Savings
Space Cadet Gentle cleanup — removes filler and politeness words 5-20%
Spaceman Signature mode — strips stopwords, lemmatizes, structures into ROLE/TASK/OUTPUT 25-50%
Space Marine Aggressive — extracts only keywords into structured template 30-50%
Space Commander Full rewrite into clean imperative format 30-75%

What Gets Preserved

  • Role/persona definitions
  • Negations and constraints ("don't", "never", "without")
  • Output format specs ("as JSON", "bullet list", "table")
  • Examples and few-shot blocks
  • Chain-of-thought triggers ("step by step")
  • Numbers, names, technical terms

Tech Stack

Component Technology
Frontend HTML/CSS/JS + 98.css (Windows 95 style)
Backend Python, FastAPI, Uvicorn
NLP spaCy (en_core_web_sm)
Similarity sentence-transformers (all-MiniLM-L6-v2)
Tokenizer tiktoken (cl100k_base)

Quick Start

# Clone
git clone <repo-url>
cd SpaceSpeech

# Setup
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python -m spacy download en_core_web_sm

# Run
python run.py

Open http://localhost:8000 in your browser.

Project Structure

SpaceSpeech/
├── run.py                      # Entry point
├── requirements.txt
├── backend/
│   ├── app.py                  # FastAPI app, model loading, static serving
│   ├── routes.py               # API endpoints
│   ├── models.py               # Pydantic schemas
│   ├── config.py               # Constants
│   └── optimizer/
│       ├── pipeline.py         # Orchestrator
│       ├── strategies.py       # 4 compression strategies
│       ├── scorer.py           # Token counting + semantic similarity
│       └── preprocess.py       # Text normalization
├── frontend/
│   ├── index.html              # Windows 95 style UI
│   ├── css/custom.css
│   ├── js/app.js
│   └── assets/                 # Background + logo
└── bg/                         # Source background images

API

POST /api/optimize

{
  "text": "your verbose prompt here",
  "strategy": null,
  "tokenizer": "cl100k_base",
  "similarity_threshold": 0.7
}

Response:

{
  "original_text": "...",
  "original_token_count": 76,
  "variants": [
    {"strategy": "mild", "text": "...", "token_count": 63, "similarity": 0.979},
    {"strategy": "spaceman", "text": "...", "token_count": 41, "similarity": 0.875},
    {"strategy": "extreme", "text": "...", "token_count": 40, "similarity": 0.873},
    {"strategy": "command", "text": "...", "token_count": 41, "similarity": 0.757}
  ],
  "best": {"strategy": "extreme", "text": "...", "token_count": 40, "similarity": 0.873},
  "savings_percent": 47.4
}

GET /api/health

Returns model load status.

Easter Eggs

There might be a galaxy worth clicking on...

Hackathon 2026

About

Spaceman Speech — Local NLP tool that compresses verbose prompts into optimized, structured format. 30-50% fewer tokens, same meaning. No LLM needed. Less cost, better prompts.

Resources

Stars

10 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors