Skip to main content

Idiomark Examples

Practical, copy-pasteable examples for using the Idiomark.


Quick Start Example​

Using the Demo File​

The fastest way to understand Idiomark is to explore the demo file included with the project.

# Navigate to the examples directory in the repo
cd examples

# View the demo personality file
cat demo.idiomark

Expected Output (truncated):

{
"idiomark": "1.0.0",
"id": "idiomark_demo_example",
"created": "2026-02-10T00:00:00Z",
"metadata": {
"entity": {
"name": "Demo Developer",
"type": "human",
"sources": ["text-samples"]
}
},
"personality": {
"voice": {
"tone": {
"primary": "casual",
"secondary": "humorous",
"confidence": 0.87
},
"formality": 0.25,
"humor": 0.75,
"sarcasm": 0.55,
"enthusiasm": 0.82,
"directness": 0.65
},
"domains": [
{ "name": "javascript", "confidence": 0.95 },
{ "name": "typescript", "confidence": 0.89 },
{ "name": "react", "confidence": 0.86 }
],
"values": [
{ "name": "open_source", "sentiment": "positive", "confidence": 0.94 },
{ "name": "type_safety", "sentiment": "positive", "confidence": 0.82 }
]
}
}

Validating the Demo File​

# Validate the demo file structure
idiomark validate examples/demo.idiomark

Expected Output:

Idiomark Validator

Valid Idiomark file

File Details:
Version: 1.0.0
Entity ID: idiomark_demo_example
Created: 2026-02-10T00:00:00Z
Sources: text-samples

All checks passed!

Viewing Demo File Info​

# Display detailed information about the demo personality
idiomark info examples/demo.idiomark

Expected Output:

Idiomark File Info

Metadata:
Version: 1.0.0
ID: idiomark_demo_example
Created: 2026-02-10T00:00:00Z
Last Updated: 2026-02-10T00:00:00Z

Entity:
Name: Demo Developer
Type: human
Sources: text-samples

Personality:
Voice:
Tone: casual (87%)
Formality: 25%
Humor: 75%
Sarcasm: 55%
Enthusiasm: 82%
Directness: 65%

Domains:
javascript (95%)
typescript (89%)
react (86%)

Values:
open_source (94%)
type_safety (82%)
simplicity (79%)

CLI Examples​

Full Workflow: Extraction to Inference​

1. Install the CLI​

npm install -g @idiomark/cli

2. Extract Your Personality from Text​

# Extract from text samples you provide
idiomark extract text --input "your-writing-samples-here" -o me.idiomark

# Custom sample size (more data = better analysis)
idiomark extract text --input "your-writing-samples-here" --sample-size 5000 -o me.idiomark

# Verbose output for debugging
idiomark extract text --input "your-writing-samples-here" -v -o me.idiomark

Expected Output:

Idiomark Extractor

Analyzing text samples...
✓ Voice analysis complete
✓ Pattern detection complete
✓ Domain extraction complete
✓ Value inference complete

Personality blueprint saved to me.idiomark

Extraction Summary:
Sample size: 1000
Confidence: 87.5%

Personality Preview:
Primary tone: casual
Formality: 0.30
Humor: 0.80
Enthusiasm: 0.70

3. Validate Your File​

# Basic validation
idiomark validate me.idiomark

# Strict validation (checks all fields)
idiomark validate me.idiomark --strict

4. Serve Your Personality​

# Start local inference server
idiomark serve me.idiomark

# Custom port
idiomark serve me.idiomark --port 8080

# Use different model
idiomark serve me.idiomark --model claude-3-opus

Expected Output:

Idiomark Inference Server

Server starting...

Server Details:
URL: http://localhost:3000
Model: gpt-4
Personality: casual

API Endpoints:
POST /generate Generate response with personality
GET /health Health check
GET /personality View loaded personality

Example:
curl -X POST http://localhost:3000/generate \
-H "Content-Type: application/json" \
-d '{"message": "Hello!"}'

Server ready at http://localhost:3000

5. Generate Responses​

# In another terminal, test the inference
curl -X POST http://localhost:3000/generate \
-H "Content-Type: application/json" \
-d '{"message": "What is your favorite programming language?"}'

Expected Response:

{
"response": "Oh, that's like asking me to pick my favorite child! But if I'm being real, I've been spending a ton of time with TypeScript lately. The type safety just hits different when you're working on larger projects. Plus, the tooling around it has gotten so good. What about you?",
"personality": {
"tone": "casual",
"confidence": 0.87
},
"model": "gpt-4",
"tokensUsed": 45
}

SDK Integration​

Node.js/TypeScript​

Installation​

npm install @idiomark/sdk
# or
pnpm add @idiomark/sdk
# or
yarn add @idiomark/sdk

Basic Usage​

import { IdiomarkClient } from "@idiomark/sdk";

// Initialize the client (uses your LLM provider API key)
const client = new IdiomarkClient({
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-4",
});

// Load a personality file
const personality = require("./demo.idiomark");

// Generate a response
const result = await client.generate({
message: "What's the best way to learn React?",
personality: personality,
});

console.log(result.response);

Chatbot Implementation​

import { IdiomarkClient } from "@idiomark/sdk";
import personality from "./brand-personality.idiomark";

const client = new IdiomarkClient();

async function chat(message: string): Promise<string> {
const result = await client.generate({
message,
personality,
temperature: 0.8,
});

return result.response;
}

// Usage
console.log(await chat("What's your return policy?"));

Customer Service Bot​

import { IdiomarkClient } from "@idiomark/sdk";

const client = new IdiomarkClient({
model: "gpt-4",
});

const brandPersonality = require("./brand-personality.idiomark");

async function customerService(query: string): Promise<string> {
const result = await client.generate({
message: query,
personality: brandPersonality,
temperature: 0.5, // Lower temp for consistency
maxTokens: 300, // Shorter responses for CS
});

return result.response;
}

Content Generator​

import { IdiomarkClient } from "@idiomark/sdk";

async function generateTweet(
topic: string,
personality: IdiomarkFile,
): Promise<string> {
const result = await client.generate({
message: `Write a tweet about ${topic}`,
personality,
temperature: 0.9, // Higher for creativity
maxTokens: 100, // Twitter limit
});

return result.response;
}

Multiple Personalities​

import { IdiomarkClient } from "@idiomark/sdk";

const client = new IdiomarkClient();

const personalities = {
professional: require("./prof.idiomark"),
casual: require("./casual.idiomark"),
sarcastic: require("./sarcasm.idiomark"),
};

async function respond(message: string, tone: string): Promise<string> {
const personality = personalities[tone] || personalities.casual;

const result = await client.generate({
message,
personality,
});

return result.response;
}

Next.js Integration​

Create app/api/chat/route.ts:

import { IdiomarkClient } from "@idiomark/sdk";
import personality from "@/lib/brand-personality.idiomark";

const client = new IdiomarkClient();

export async function POST(req: Request) {
const { message } = await req.json();

const result = await client.generate({
message,
personality,
});

return Response.json({ response: result.response });
}

Express Integration​

import express from "express";
import { IdiomarkClient } from "@idiomark/sdk";

const app = express();
const client = new IdiomarkClient();

app.post("/chat", async (req, res) => {
const { message } = req.body;
const personality = req.app.locals.personality;

const result = await client.generate({
message,
personality,
});

res.json({ response: result.response });
});

Error Handling​

import { IdiomarkClient, IdiomarkError } from "@idiomark/sdk";

const client = new IdiomarkClient();

try {
const result = await client.generate({
message: "Hello",
personality: invalidData, // Invalid Idiomark file
});
} catch (error) {
if (error instanceof IdiomarkError) {
console.error("Idiomark Error:", error.code, error.message);

if (error.code === "INVALID_PERSONALITY") {
// Handle invalid personality
} else if (error.code === "API_ERROR") {
// Handle API error
}
}
}

Advanced Examples​

Batch Processing​

import { IdiomarkClient } from "@idiomark/sdk";

const client = new IdiomarkClient();

async function processBatch(personalities: IdiomarkFile[], messages: string[]) {
const results: Record<string, string[]> = {};

for (const personality of personalities) {
results[personality.metadata.entity.name] = [];

for (const message of messages) {
const result = await client.generate({
message,
personality,
temperature: 0.7,
});

results[personality.metadata.entity.name].push(result.response);
}
}

return results;
}

// Usage
const personalities = [
require("./personality1.idiomark"),
require("./personality2.idiomark"),
require("./personality3.idiomark"),
];

const messages = [
"What's your favorite programming language?",
"How do you handle errors?",
"What's your coding style?",
];

const results = await processBatch(personalities, messages);
console.log(results);

Custom Personality Creation​

Sometimes you want to create a personality without extraction. Here's how:

{
"idiomark": "1.0.0",
"id": "custom_assistant",
"created": "2026-02-10T00:00:00Z",
"updated": "2026-02-10T00:00:00Z",
"metadata": {
"entity": {
"name": "Helpful Assistant",
"type": "bot",
"sources": []
},
"extraction": {
"date": "2026-02-10T00:00:00Z",
"sample_size": 0,
"timeframe": {
"from": "2026-02-10T00:00:00Z",
"to": "2026-02-10T00:00:00Z"
}
},
"validator": "manual"
},
"personality": {
"voice": {
"tone": {
"primary": "professional",
"secondary": "friendly",
"confidence": 1.0
},
"formality": 0.7,
"humor": 0.3,
"sarcasm": 0.1,
"enthusiasm": 0.6,
"directness": 0.8
},
"patterns": {
"sentence_length": {
"mean": 15.0,
"stddev": 5.0
},
"paragraph_length": {
"mean": 2.0,
"stddev": 1.0
},
"emoji_usage": {
"frequency": "low",
"top_emojis": ["👍", "🙏"],
"position": "end"
},
"punctuation": {
"exclamation_frequency": 0.1,
"question_frequency": 0.2,
"ellipsis_usage": "none"
},
"capitalization": {
"all_caps_frequency": 0.0,
"random_caps": false
}
},
"domains": [
{
"name": "general_assistance",
"confidence": 1.0,
"evidence": ["manual_configuration"]
}
],
"values": [
{
"name": "helpfulness",
"sentiment": "positive",
"confidence": 1.0
},
{
"name": "accuracy",
"sentiment": "positive",
"confidence": 1.0
}
],
"knowledge": {
"frequent_terms": ["help", "assist", "answer"],
"mentions": {
"people": [],
"projects": [],
"organizations": []
},
"topics": {
"primary": ["general"],
"secondary": []
}
}
},
"signature": "manual"
}

Troubleshooting Examples​

Common Issues and Solutions​

Issue: Invalid Idiomark File​

# Validate your file
idiomark validate my.idiomark --strict

# Common errors:
# - Missing required fields
# - Confidence values outside 0-1 range
# - Invalid date formats (must be ISO 8601)

Issue: Low Confidence Scores​

# Solution: Increase sample size and provide more representative writing samples
idiomark extract text --input "more-samples" --sample-size 5000 -o me.idiomark

Best Practices​

1. Sample Size Selection​

# ❌ Too small - inaccurate results
idiomark extract text --input "short-sample" --sample-size 50 -o me.idiomark

# ✅ Good - minimum viable
idiomark extract text --input "moderate-samples" --sample-size 500 -o me.idiomark

# ✅ Better - good accuracy
idiomark extract text --input "rich-samples" --sample-size 1500 -o me.idiomark

# ✅ Best - maximum accuracy
idiomark extract text --input "extensive-samples" --sample-size 3000 -o me.idiomark

2. Representative Samples​

Use writing that reflects how you actually communicate day to day — a mix of contexts (casual messages, longer-form writing) produces a more accurate profile than one narrow style.

3. Regular Updates​

# Update your personality quarterly
idiomark extract text --input "recent-samples" --sample-size 2000 -o me-q1.idiomark
idiomark extract text --input "newer-samples" --sample-size 2000 -o me-q2.idiomark

4. Backup Your Personality​

# Always keep backups
cp me.idiomark me-backup-$(date +%Y%m%d).idiomark

Additional Resources​


Need help? Open an issue at github.com/idiomark