Repository navigation
laya-ts: per-language temperature overrides (lang_temperatures) + Router lang forwarding - #398
Merged
NandhaKishorM merged 1 commit intoSep 24, 2026
Conversation
… + Router lang forwarding
Owner
|
Thank you, this is a faithful port. TypeScript users can now apply per-language temperature overrides, and the Router passes the request language through, just like Python. The tests that pin the full scale replacement and the English case make the matching behaviour easy to trust. Merging, and #329 can rebase on top so its decode helper takes the lang argument. |
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.
Why
The Python
Agentacceptslang_temperatures(laya/agent.py:357-366) — per-languagetemperature overrides fitted on multilingual evals — and
Router.predictforwards therequest language (
langargument, else the language detected for routing) intosystem_oneso the override actually applies (laya/router.py:532-534). The TS port hadzero language-aware calibration:
AgentOptionshad nolang_temperatures,systemOnehad nolang, andRouter.predictdropped the language on the floor afterrouting. This PR ports the whole path.
What
AgentOptions.lang_temperatures—{ de: { temperature: [t_choice, t_score, t_noul], temperature_by_options: {...} } }, same shape as Python. Constructornormalisation mirrors
Agent.__init__: keys normalise to the base subtag(
de-AT->de), an omittedtemperatureinherits the base raw temperature, everyvalue is
clampTemperature-clamped, and a temperature that is not a list of 3 floatsthrows immediately.
_decode_answersequivalent) — a per-requestlangselects thematching override, normalised to its base subtag on lookup too (
de-CH->de).Parity with Python: a matching override replaces the temperature scale wholesale
(its own
temperature_by_optionsfirst, then its 3-slottemperature) — it is notmerged with the base config, so an override without buckets intentionally ignores the
base per-bucket entries.
PredictOptions.langonsystemOne/predict— routing alone never sets it,exactly like Python.
Agent.load(..., { lang_temperatures })— passthrough so a loaded agent can becalibrated the same way as a constructed one.
Router.predict— forwardsopts.lang ?? detected languageintosystemOne,matching
router.py predict. Two parity notes:analyse()names English"en"where Python'sanalysereturnsNone(it onlyever names non-English languages,
laya/lang.py:344,368). A detected"en"istherefore forwarded as
null; only an explicitlang="en"can select an"en"override, exactly as in Python. (The
"en"-vs-Noneasymmetry in the detectionpayload itself is pre-existing and untouched here.)
TypeErrorretry for duck-typed agents without alangkwarg isunnecessary in TS — extra arguments are ignored, so
Router.predictkeeps workingwith plain
{ systemOne(s, q) }agent-like objects (covered by the stub-agent tests).predictBatch(#329) is intentionally unchanged; per-request lang grouping there is theTS counterpart of #381 and lands as a follow-up once both settle.
Merge-order note (verified with
git merge-tree): clean against #386(answer_confidence — same file, different hunks). Textual conflict with #329 in
agent.tsonly, and it is mechanical, not semantic: #329 refactors_systemOneCoreinto
_systemOneMany/_encodeItems/_decodeAnswerswhile this PR edits_systemOneCorein place. Whichever lands second, I rebase — resolution is just movingthe
langparam and the scale-selection lines into the refactored decode function.Tests
tests/lang-temperature.test.ts(11 tests, mirroringtests/test_system_one_lang.py):key normalisation on both sides, default-to-base temperature, clamping, wholesale scale
replacement (base
temperature_by_optionsmust not leak into an overridden language),buckets-only override inheriting the base raw temperature, invalid-shape throw,
nullentry as empty override, and Router forwarding (explicit wins, detected non-English
forwarded, detected English -> null, explicit
"en"verbatim).Verified with
npx vitest run(176/176) andnpx tsc --noEmit(clean).