Skip to content

feat: add --label-language flag and GRAPHIFY_LABEL_LANGUAGE env var for LLM community labels#1844

Open
prvthmpcypher wants to merge 1 commit into
Graphify-Labs:v8from
prvthmpcypher:feat/label-language-flag
Open

feat: add --label-language flag and GRAPHIFY_LABEL_LANGUAGE env var for LLM community labels#1844
prvthmpcypher wants to merge 1 commit into
Graphify-Labs:v8from
prvthmpcypher:feat/label-language-flag

Conversation

@prvthmpcypher

Copy link
Copy Markdown

Fixes #1824

Problem

The prompt in _label_batch_with_retry (llm.py) was a hardcoded English
string with no language directive. Since the LLM inferred output language
ambientlyfrom sampled node labels, the same community could be named in
English in one relabel pass and in the team's natural language in another.
This made diffing labels across reclusters noisy and forced manual
normalization for non-English teams.

Solution

Added an explicit language instruction to the labeling prompt, controllable
via:

  • --label-language flag on both graphify label and graphify cluster-only
  • GRAPHIFY_LABEL_LANGUAGE environment variable as a fallback

When neither is set, behavior is identical to before (no language directive
in the prompt), so this is fully backward compatible.

Changes

graphify/llm.py

  • Added label_language: str | None = None parameter to
    _label_batch_with_retry, label_communities, and
    generate_community_labels
  • Injected _lang_clause into the labeling prompt when a language is
    specified, e.g. " Respond in Portuguese."
  • Reads GRAPHIFY_LABEL_LANGUAGE env var as fallback when no explicit
    value is passed
  • Threaded label_language through recursive retry calls so it is not
    lost on batch splits

graphify/cli.py

  • Added --label-language argument parsing (supports both
    --label-language Portuguese and --label-language=Portuguese forms)
    to the shared cluster-only / label handler
  • Passed label_language through to generate_community_labels

Usage

# CLI flag
graphify label --label-language Portuguese
graphify cluster-only . --label-language Japanese

# Environment variable
GRAPHIFY_LABEL_LANGUAGE=French graphify label

Backward Compatibility

No breaking changes. When --label-language is not set and
GRAPHIFY_LABEL_LANGUAGE is unset, the prompt is identical to before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: no way to control the output language of LLM-generated community labels

1 participant