feat: add --label-language flag and GRAPHIFY_LABEL_LANGUAGE env var for LLM community labels#1844
Open
prvthmpcypher wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1824
Problem
The prompt in
_label_batch_with_retry(llm.py) was a hardcoded Englishstring 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-languageflag on bothgraphify labelandgraphify cluster-onlyGRAPHIFY_LABEL_LANGUAGEenvironment variable as a fallbackWhen neither is set, behavior is identical to before (no language directive
in the prompt), so this is fully backward compatible.
Changes
graphify/llm.pylabel_language: str | None = Noneparameter to_label_batch_with_retry,label_communities, andgenerate_community_labels_lang_clauseinto the labeling prompt when a language isspecified, e.g.
" Respond in Portuguese."GRAPHIFY_LABEL_LANGUAGEenv var as fallback when no explicitvalue is passed
label_languagethrough recursive retry calls so it is notlost on batch splits
graphify/cli.py--label-languageargument parsing (supports both--label-language Portugueseand--label-language=Portugueseforms)to the shared
cluster-only/labelhandlerlabel_languagethrough togenerate_community_labelsUsage
Backward Compatibility
No breaking changes. When
--label-languageis not set andGRAPHIFY_LABEL_LANGUAGEis unset, the prompt is identical to before.