Improve memory recall in Korean at every speech level
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+15
-11
@@ -45,28 +45,32 @@ KO_CACHE = ROOT / "logs" / "memory_check_ko.json" # title -> Korean title / su
|
||||
_ko = {}
|
||||
|
||||
|
||||
def _korean(title, summary):
|
||||
"""The Korean title and summary a live talk carries (memory.summarise asks the LLM for both): made once per talk by
|
||||
the LLM and kept in KO_CACHE, so the rules-only runs need no LLM after the first."""
|
||||
def _korean(title, summary, facts=()):
|
||||
"""The Korean title, summary and facts a live talk carries (memory.summarise asks the LLM for them): made once per
|
||||
talk by the LLM and kept in KO_CACHE, so the rules-only runs need no LLM after the first."""
|
||||
key = f"{title}|{summary}"
|
||||
if not _ko and KO_CACHE.exists():
|
||||
_ko.update(json.loads(KO_CACHE.read_text()))
|
||||
if key not in _ko:
|
||||
if key not in _ko or facts and "facts_ko" not in _ko[key]:
|
||||
from assistant import brain
|
||||
out = json.loads(brain._chat([{"role": "system", "content": "Translate this robot's memory of a talk into Korean "
|
||||
"as JSON: {\"title_ko\": \"<the title, 1-4 Korean words>\", \"summary_ko\": \"<the "
|
||||
"summary in polite Korean (-요)>\"}. Names of people, robots and companies as they are "
|
||||
"said in Korean (JAKA = 자카)."},
|
||||
{"role": "user", "content": f"title: {title}\nsummary: {summary}"}],
|
||||
{"type": "object", "properties": {"title_ko": {"type": "string"}, "summary_ko": {"type": "string"}},
|
||||
"required": ["title_ko", "summary_ko"]}))
|
||||
_ko[key] = {"title_ko": out["title_ko"].strip(), "summary_ko": out["summary_ko"].strip()}
|
||||
"summary in polite Korean (-요)>\", \"facts_ko\": [\"<each fact in polite Korean (-요)>\"]}. "
|
||||
"Names of people, robots and companies as they are said in Korean (JAKA = 자카)."},
|
||||
{"role": "user", "content": f"title: {title}\nsummary: {summary}\nfacts: {json.dumps(list(facts))}"}],
|
||||
{"type": "object", "properties": {"title_ko": {"type": "string"}, "summary_ko": {"type": "string"},
|
||||
"facts_ko": {"type": "array", "items": {"type": "string"}}},
|
||||
"required": ["title_ko", "summary_ko", "facts_ko"]}))
|
||||
old = _ko.get(key, {}) # a title already made stays (the embeddings are cached by it)
|
||||
_ko[key] = {"title_ko": old.get("title_ko") or out["title_ko"].strip(),
|
||||
"summary_ko": old.get("summary_ko") or out["summary_ko"].strip(),
|
||||
"facts_ko": [f.strip() for f in out["facts_ko"]][:len(facts)]}
|
||||
KO_CACHE.write_text(json.dumps(_ko, ensure_ascii=False, indent=0))
|
||||
return _ko[key]
|
||||
|
||||
|
||||
def _talk(t):
|
||||
ko = _korean(t["title"], t["summary"])
|
||||
ko = _korean(t["title"], t["summary"], t.get("facts", []))
|
||||
return {"t": epoch(t["when"]), "title": t["title"], "summary": t["summary"], "facts": t.get("facts", []),
|
||||
"commands": t.get("commands", []), "person": t.get("person"), **ko,
|
||||
"vec": _vec(f"{t['title']}. {t['summary']}"), "vec_ko": _vec(f"{ko['title_ko']}. {ko['summary_ko']}")}
|
||||
|
||||
Reference in New Issue
Block a user