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 and publish (uv)

Requires uv and Python 3.10+ (see requires-python in pyproject.toml). PyPI name psygen-llm, import psygen_llm, CLI psygen-llm.

There is a single path: build with uv, publish the artifacts, then install globally from the index. This README does not document local installs (for example editable installs or installing from a wheel inside the repo).

From the repository root, bump version in pyproject.toml when publishing a new release, and configure PyPI credentials for Twine (for example ~/.pypirc or the usual TWINE_* environment variables).

Build and push (maintainers):

uv build
uvx twine upload dist/*

Install globally (after the release is on PyPI; use --system so the package is not tied to a project virtual environment):

uv pip install --system "psygen-llm"

Use uv pip install --system "psygen-llm[openai]" for the optional OpenAI dependency. Before upgrading, you can remove the previous install with uv pip uninstall --system psygen-llm (it is fine if nothing is installed). Quote extras so the shell does not treat [openai] as a glob.

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-llm --config psygen.json "Linus from Stardew Valley"
psygen-llm --config psygen.json "Linus from Stardew Valley" -o /tmp/linus.json
psygen-llm --config psygen.json "Linus from Stardew Valley" -o -

Design

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

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.1.tar.gz (16.6 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.1-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psygen_llm-0.2.1.tar.gz
  • Upload date:
  • Size: 16.6 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.1.tar.gz
Algorithm Hash digest
SHA256 7eb67a7c3ca67e4a5cc06a6be954426188e926a8a502dfa4e111708af2223f9e
MD5 0afc5768fa3c770ca128a8915d1cb2a4
BLAKE2b-256 2d5e59da76bb725e5a59471de3cdca07e2390955bff920b34d36148f5656ac01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: psygen_llm-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 22.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 83fab987e8b131476dd9dfcba781634ef6b6642df6580f02302aeb20ddfd7345
MD5 450e87019bd5814972c55753c2bf7b06
BLAKE2b-256 93ff05b92579af9175b7f7b37a01966f8a7ed155ecd657d0627373548f81cb36

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