mooncak397 Claude Opus 5.5 commited on
Commit ·
5d71f7b
1
Parent(s): 91bf6fe
finalize: a fixed sentence comes back in the turn's language
Browse files- app/graph.py +2 -0
- tests/test_graph.py +5 -0
app/graph.py
CHANGED
|
@@ -65,6 +65,7 @@ def build_graph(model):
|
|
| 65 |
prompt = system_prompt()
|
| 66 |
fixed = fixed_sentences()
|
| 67 |
idk = {"en": fixed["idk_en"], "de": fixed["idk_de"]}
|
|
|
|
| 68 |
classifier = model.with_structured_output(Classification)
|
| 69 |
contact_model = model.bind_tools([request_contact_form]) # the only tool, only in this node
|
| 70 |
|
|
@@ -120,6 +121,7 @@ def build_graph(model):
|
|
| 120 |
if not text:
|
| 121 |
text, guard = idk[lang], "empty"
|
| 122 |
elif s := only_fixed(text, fixed):
|
|
|
|
| 123 |
text, guard = s, ("fixed_sentence" if s != text else None)
|
| 124 |
elif discretion_hit(text):
|
| 125 |
text, guard = idk[lang], "discretion"
|
|
|
|
| 65 |
prompt = system_prompt()
|
| 66 |
fixed = fixed_sentences()
|
| 67 |
idk = {"en": fixed["idk_en"], "de": fixed["idk_de"]}
|
| 68 |
+
kind = {s: k[:-3] for k, s in fixed.items()} # sentence -> "idk" or "reloc"
|
| 69 |
classifier = model.with_structured_output(Classification)
|
| 70 |
contact_model = model.bind_tools([request_contact_form]) # the only tool, only in this node
|
| 71 |
|
|
|
|
| 121 |
if not text:
|
| 122 |
text, guard = idk[lang], "empty"
|
| 123 |
elif s := only_fixed(text, fixed):
|
| 124 |
+
s = fixed[f"{kind[s]}_{lang}"] # the turn's language wins: the model sometimes picks the other one
|
| 125 |
text, guard = s, ("fixed_sentence" if s != text else None)
|
| 126 |
elif discretion_hit(text):
|
| 127 |
text, guard = idk[lang], "discretion"
|
tests/test_graph.py
CHANGED
|
@@ -187,6 +187,11 @@ def test_fixed_sentence_plus_meta_text_keeps_only_the_sentence():
|
|
| 187 |
assert only_fixed("He works at DATEV.", FS) is None
|
| 188 |
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
def test_discretion_patterns():
|
| 191 |
for hit in ["His expected salary is open.", "Er ist wechselbereit.", "Gehaltsvorstellung: offen",
|
| 192 |
"He would need a work permit sponsorship.", "Verfuegbarkeit: ab sofort verfuegbar"]:
|
|
|
|
| 187 |
assert only_fixed("He works at DATEV.", FS) is None
|
| 188 |
|
| 189 |
|
| 190 |
+
@pytest.mark.parametrize("lang, wrote, want", [("en", "idk_de", "idk_en"), ("de", "reloc_en", "reloc_de")])
|
| 191 |
+
def test_fixed_sentence_follows_the_turn_language(lang, wrote, want):
|
| 192 |
+
assert answer(FakeModel(lang=lang, reply=AIMessage(FS[wrote]))) == FS[want]
|
| 193 |
+
|
| 194 |
+
|
| 195 |
def test_discretion_patterns():
|
| 196 |
for hit in ["His expected salary is open.", "Er ist wechselbereit.", "Gehaltsvorstellung: offen",
|
| 197 |
"He would need a work permit sponsorship.", "Verfuegbarkeit: ab sofort verfuegbar"]:
|