# How G0DM0D3 AutoTune Classifies Context: Regex-Based Detection and Profile Selection

> Discover how G0DM0D3 AutoTune classifies context using weighted regex pattern matching and confidence scores to select the best LLM sampling profile. Learn more about the elder-plinius/G0DM0D3 repository.

- Repository: [pliny/G0DM0D3](https://github.com/elder-plinius/G0DM0D3)
- Tags: internals
- Published: 2026-07-19

---

**G0DM0D3's AutoTune classifies conversation context by applying weighted regex pattern matching to the current user prompt and recent chat history, calculating a confidence score to select the optimal LLM sampling profile.**

The AutoTune engine in the `elder-plinius/G0DM0D3` repository provides deterministic, client-side context classification that drives adaptive LLM parameter tuning. By analyzing lexical patterns across five distinct context categories, the system automatically selects sampling strategies without requiring manual configuration.

## The Three-Stage Classification Pipeline

The classification process implemented in [`src/lib/autotune.ts`](https://github.com/elder-plinius/G0DM0D3/blob/main/src/lib/autotune.ts) operates through three distinct stages: pattern definition, weighted scoring, and profile mapping.

### Pattern Definition with CONTEXT_PATTERNS

At the core of the classification system lies the `CONTEXT_PATTERNS` map defined at lines 100–133. This static configuration groups regular-expression patterns under five high-level context types:

- **`code`**: Detects programming syntax, keywords (`function`, `class`, `variable`), and code block markers
- **`creative`**: Identifies narrative language, expressive punctuation, and artistic terminology
- **`analytical`**: Recognizes data analysis terms, logical connectors, and structured reasoning patterns
- **`conversational`**: Matches casual dialogue markers, questions, and social emojis
- **`chaotic`**: Captures erratic punctuation bursts, random capitalization, and disjointed syntax

Each pattern within the map targets specific lexical fingerprints—ranging from formal code syntax to emotional punctuation clusters—that distinguish one context type from another.

### Scoring Logic and Confidence Calculation in detectContext

The `detectContext` function (lines 112–138) executes the classification algorithm through a weighted evaluation system. The function processes the current message with a **3× weight** while applying a **1× weight** to the last four messages in the conversation history.

The scoring loop (lines 124–158) accumulates matches per context type, then normalizes these scores to percentage values. The highest-scoring type becomes `detectedContext`, while its share of the total score determines the **confidence** value—a decimal between 0 and 1 representing classification certainty.

If no patterns match the input text, the engine defaults to `conversational` with a neutral confidence of 0.5, ensuring the system never fails silently.

### Profile Selection via CONTEXT_PROFILE_MAP

When the user selects the `adaptive` strategy, the detected context maps to concrete generation parameters through `CONTEXT_PROFILE_MAP` (lines 137–177). Each context type correlates to specific temperature, top-p, and top-k values optimized for that conversational mode.

The system implements safety blending within `computeAutoTuneParams`: if confidence falls below **0.6**, the chosen profile merges with the generic `balanced` profile to prevent over-fitting to ambiguous inputs. The final parameter set may then adjust based on learned feedback, conversation-length penalties, and manual overrides.

## Implementation Details in src/lib/autotune.ts

The public entry point `computeAutoTuneParams` (lines 76–84) orchestrates the classification workflow. When `strategy === 'adaptive'` (lines 100–108), it invokes `detectContext` and populates an `AutoTuneResult` object containing:

- `detectedContext`: The classified context type string
- `confidence`: The normalized confidence score
- `contextScores`: Complete breakdown of scores across all five types
- `patternMatches`: Array of matched regex patterns for transparency

This architecture ensures that context classification remains fully deterministic and inspectable, with no external API calls or non-deterministic model inference required.

## Practical Usage Example

To leverage AutoTune's context classification in your application, import `computeAutoTuneParams` and provide the conversation context:

```typescript
import { computeAutoTuneParams } from '@/lib/autotune'

const message = "Can you write a TypeScript function that parses JSON?"
const history = [
  { role: 'assistant', content: 'Sure, what do you need?' },
  { role: 'user', content: 'I need help with some code.' }
]

// Adaptive strategy – AutoTune will infer the context
const result = computeAutoTuneParams({
  strategy: 'adaptive',
  message,
  conversationHistory: history
})

console.log('Detected context :', result.detectedContext)   // e.g. "code"
console.log('Confidence       :', (result.confidence * 100).toFixed(1) + '%')
console.log('Chosen params    :', result.params)
console.log('Scoring breakdown:', result.contextScores)
console.log('Matched patterns :', result.patternMatches.map(p => p.pattern))

```

*Example output:*

```

Detected context : code
Confidence       : 85.0%
Chosen params    : { temperature:0.15, top_p:0.8, top_k:25, … }
Scoring breakdown: [
  { type:'code', score:9, percentage:75 },
  { type:'creative', score:2, percentage:17 },
  …
]

```

For fixed behavior regardless of context detection, specify a static strategy:

```typescript
computeAutoTuneParams({
  strategy: 'creative',   // bypasses detection, uses static profile
  message,
  conversationHistory: history
})

```

## Summary

- **Pattern-based detection**: The `CONTEXT_PATTERNS` map at lines 100–133 uses regex to identify five context types: `code`, `creative`, `analytical`, `conversational`, and `chaotic`.
- **Weighted scoring**: Current messages receive 3× weight versus 1× for historical messages, with scores normalized to produce a confidence value.
- **Adaptive fallback**: Classifications below 0.6 confidence blend with the `balanced` profile to avoid over-fitting.
- **Entry point**: The `computeAutoTuneParams` function in [`src/lib/autotune.ts`](https://github.com/elder-plinius/G0DM0D3/blob/main/src/lib/autotune.ts) serves as the primary API for context-aware parameter selection.

## Frequently Asked Questions

### What are the five context types in G0DM0D3 AutoTune?

G0DM0D3 recognizes `code`, `creative`, `analytical`, `conversational`, and `chaotic` contexts. Each type maps to distinct regex patterns in `CONTEXT_PATTERNS` that detect specific lexical markers—programming keywords for code, narrative structures for creative, logical terminology for analytical, casual dialogue for conversational, and erratic punctuation for chaotic contexts.

### How does AutoTune weight current messages versus chat history?

The `detectContext` function applies a **3× multiplier** to the current user message while scoring the last four historical messages at **1×** weight. This weighting scheme prioritizes immediate intent over conversational drift, ensuring that a sudden shift to technical questions immediately triggers the `code` context regardless of prior small talk.

### What happens if no context pattern matches?

When no regex patterns match the input text, AutoTune defaults to the `conversational` context type with a neutral confidence score of **0.5**. This fallback ensures the system remains operational while avoiding high-confidence misclassification of ambiguous or novel inputs.

### Where is the context classification logic implemented?

All classification logic resides in [`src/lib/autotune.ts`](https://github.com/elder-plinius/G0DM0D3/blob/main/src/lib/autotune.ts) within the `elder-plinius/G0DM0D3` repository. Key functions include `detectContext` (lines 112–138) for pattern matching and `computeAutoTuneParams` (lines 76–84) for orchestrating the adaptive workflow. The `CONTEXT_PATTERNS` definition occupies lines 100–133, while profile mapping occurs at lines 137–177.