Skip to main content

AI-based Character Name Generator

Project description

Namegiver: AI-based Character Name Generator

A lightweight, OpenAI-powered Python library for generating unique fictional character names based on user-provided prompts. Designed for writers, game developers, and world-builders.

Features

✅ AI-Generated Names – Distinctive names based on user descriptions.
✅ Ensures Name Distinctiveness – Avoids generating names too similar to previous ones.
✅ Supports CLI & API – Use from the terminal or integrate into Python projects.
✅ Economy Mode – Uses GPT-3.5 by default; switch to GPT-4 if needed.
✅ Token Usage Tracking – Monitor OpenAI API token consumption.

Installation

1. Install via pip

pip install openai python-dotenv python-Levenshtein

2. Set Up API Key

Create a .env file in the project directory:

OPENAI_API_KEY=your-api-key-here
ECONOMY_MODE=True

Alternatively, set it in your shell:

export OPENAI_API_KEY="your-api-key-here"
export ECONOMY_MODE="True"

Usage

1. Using the Python API

from name_generator import generate_unique_name, get_token_usage

past_names = ["Elwin", "Alvin", "Elvin"]

# Generate a unique name while avoiding past names
print(generate_unique_name("sci-fi bounty hunter", past_names))

# Show token usage
print("Token Usage Report:", get_token_usage())

2. Using the CLI

Generate a Name

namegen "medieval knight"

Example Output:

Sir Aldrin of Westmere

Specify Maximum Token Length

namegen "steampunk engineer" --max-tokens 5

Example Output:

Brasswick

Avoid Similar Names

namegen "elf warrior" --past-names Legolas Thranduil Elrond

Example Output:

Faerion

Check Token Usage

namegen --report

Example Output:

Token Usage Report: {'total_tokens_used': 50}

Configuration

Environment Variables

Variable Default Description
OPENAI_API_KEY (Required) Your OpenAI API key
ECONOMY_MODE True If True, uses gpt-3.5-turbo. Set to False for GPT-4

How It Works

  • The library queries OpenAI's LLM to generate a name.
  • If past_names is provided, it asks OpenAI to avoid those names.
  • After generation, the name is checked using Levenshtein distance to prevent near-duplicates.
  • If the generated name is too similar, the system regenerates up to 5 times.

Development

Run Locally

Clone the repo and install dependencies:

git clone https://github.com/yourusername/character-name-generator.git
cd character-name-generator
pip install -e .

Run Tests

(TBD: Add test cases)

pytest tests/

Contributing

Contributions are welcome! Submit issues or pull requests.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

namegiver-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

namegiver-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file namegiver-0.1.0.tar.gz.

File metadata

  • Download URL: namegiver-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for namegiver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c6086eaa587919ce9365b8e2c2d63d17337eef7e114085b4ac638f9cfe63078c
MD5 31898fab7e33efc97e3368cb8d2e8d3c
BLAKE2b-256 e0100667666a83e874a35a9b78e2e8f8fe6ee0b5b1b5248f54e2ddd07f680eff

See more details on using hashes here.

File details

Details for the file namegiver-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: namegiver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for namegiver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9edc83cc230f3c8da551dccf772c0ccc6ada8975233ba8d487629a26d0cdc3a1
MD5 b5f80d853ca00ae3c7bd2b967bda5849
BLAKE2b-256 e4b5d6439a121acdf71dc84fd2615f8864c554c7c24f8b8c3441054085a5603b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page