Skip to main content

LLM-chained psychological profile generator for fictional characters (Psygen revised).

Project description

psygen-llm

Python package implementing Psygen Revised: a three-stage (optional fourth) LLM pipeline that produces a structured psychological profile for a character from a natural-language query.

  • Schema: JSON Schema for each layer and the merged profile (package data).
  • Runner: ProfileGenerator chains axiom → intermediate → emergent calls, validates JSON, merges evidence.
  • Prompt surface: to_prompt_string() emits dialogue-ready text (20 emergent traits + coping style + role identity), capped at 600 characters per the design contract.

Install

pip install psygen-llm

With OpenAI client helper:

pip install psygen-llm[openai]

OpenAI config

Create a JSON file (e.g. psygen.json, keep it private — chmod 600 — and do not commit it):

{
  "openai": {
    "api_key": "sk-...",
    "model": "gpt-4o-mini",
    "base_url": null
  }
}

openai.api_key and openai.model are required. openai.base_url is optional; omit it or set it to null for the default OpenAI API URL.

Quick use

import asyncio
from psygen_llm import ProfileGenerator, OpenAiLlmClient

async def main():
    client = OpenAiLlmClient.from_config_file("psygen.json")
    gen = ProfileGenerator(client)
    profile = await gen.generate("Linus from Stardew Valley")
    print(profile.to_prompt_string())
    print(profile.to_json())

asyncio.run(main())

Custom LLM backend

Implement psygen_llm.protocols.LlmClient (complete(system, user) -> str) and pass it to ProfileGenerator.

CLI

By default the merged profile JSON is written to output/<slug>.json (slug derived from your query; the output/ directory is created if needed). Use -o for another path, or -o - to print JSON to stdout.

psygen-generate --config psygen.json "Linus from Stardew Valley"
psygen-generate --config psygen.json "Linus from Stardew Valley" -o /tmp/linus.json
psygen-generate --config psygen.json "Linus from Stardew Valley" -o -

Design

See DESIGN.md and PLAN.md in this directory.

Develop and publish

cd path/to/psygen-llm
pip install -e ".[dev]"
pytest
python -m build

Upload to PyPI (after configuring credentials):

python -m twine upload dist/*

License

MIT

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

psygen_llm-0.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

psygen_llm-0.2.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file psygen_llm-0.2.0.tar.gz.

File metadata

  • Download URL: psygen_llm-0.2.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for psygen_llm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9cd0af803d7b4d519ed31ba5e58ce0fc057f812489208331827cc5d077c34e71
MD5 e4faba2a95e797f5e4ff172145cb8cfa
BLAKE2b-256 71c6aec2d1b9dacc585ba5bce6033c3048b491b4120b771da67c8c26ac92372f

See more details on using hashes here.

File details

Details for the file psygen_llm-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: psygen_llm-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for psygen_llm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8102351a2dc6aebe866b53994434fd76d692154cb6ece5bbbe77a8c92b0ff6ed
MD5 820a00081055c688beeeb2a1d14a5e77
BLAKE2b-256 50c3b77ea8ef01989ee33f46c2d1297984b5a831d40d81b2db913f3374fac5b7

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