Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
math_tutor_dev
public_math_tutor
Commits
c67c1d57
Commit
c67c1d57
authored
Mar 16, 2026
by
Kantz
Browse files
LLM Messages direkt in Context gespeichert
parent
7aa4d91e
Changes
4
Show whitespace changes
Inline
Side-by-side
math-tutor/backend/app/deterministic_services/context_store.py
View file @
c67c1d57
...
...
@@ -3,6 +3,7 @@ from __future__ import annotations
# Shared/base API
from
app.deterministic_services.context_stores.context_store_base
import
(
add_decision
,
append_history_message
,
format_history
,
get_chat_id
,
get_chat_id_value
,
...
...
@@ -51,6 +52,7 @@ __all__ = [
"save_sheet"
,
"format_history"
,
"update_history"
,
"append_history_message"
,
"get_history"
,
"get_history_turns"
,
"update_retrieval_context"
,
...
...
math-tutor/backend/app/deterministic_services/context_stores/context_store_base.py
View file @
c67c1d57
...
...
@@ -147,6 +147,13 @@ def update_history(sheet: dict[str, Any], messages: list[dict]) -> None:
set_history
(
sheet
,
messages
)
def
append_history_message
(
sheet
:
dict
[
str
,
Any
],
role
:
str
,
content
:
str
)
->
None
:
if
not
content
:
return
sheet
.
setdefault
(
"history"
,
[]).
append
({
"role"
:
role
,
"content"
:
content
})
_touch
(
sheet
)
def
get_history
(
sheet
:
dict
[
str
,
Any
])
->
str
:
return
format_history
(
sheet
.
get
(
"history"
,
[]))
...
...
math-tutor/backend/app/deterministic_services/orchestrators/orchestrator_base.py
View file @
c67c1d57
...
...
@@ -216,6 +216,7 @@ def finalize_response(state: ChatState, reply: str | None) -> dict:
)
reply
=
decoded
context_store
.
append_history_message
(
state
.
sheet
,
"assistant"
,
reply
)
context_store
.
save_sheet
(
state
.
sheet
)
tool_logging
.
write_tool_log
(
state
.
tool_log
,
...
...
math-tutor/backend/test/context_sheet_history_test.py
0 → 100644
View file @
c67c1d57
import
unittest
from
unittest.mock
import
patch
from
app.deterministic_services.orchestrators.orchestrator_base
import
(
ChatState
,
finalize_response
,
)
def
_build_state
()
->
ChatState
:
sheet
=
{
"chat_id"
:
"test-chat"
,
"created_at"
:
"2026-03-16T00:00:00Z"
,
"history"
:
[{
"role"
:
"user"
,
"content"
:
"Was ist eine Wurzel?"
}],
"sources"
:
[],
}
return
ChatState
(
messages
=
sheet
[
"history"
][:],
draft
=
None
,
chat_id
=
"test-chat"
,
new_chat
=
True
,
sheet
=
sheet
,
tool_log
=
[],
last_user
=
"Was ist eine Wurzel?"
,
)
class
FinalizeResponseHistoryTest
(
unittest
.
TestCase
):
def
test_finalize_response_appends_decoded_reply_to_history
(
self
)
->
None
:
state
=
_build_state
()
with
patch
(
"app.deterministic_services.orchestrators.orchestrator_base.referenz_decoder.decode_references"
,
return_value
=
(
"Dekodierte Antwort"
,
[]),
),
patch
(
"app.deterministic_services.orchestrators.orchestrator_base.context_store.save_sheet"
)
as
save_sheet
,
patch
(
"app.deterministic_services.orchestrators.orchestrator_base.tool_logging.write_tool_log"
):
result
=
finalize_response
(
state
,
"Antwort mit Referenzen"
)
self
.
assertEqual
(
result
[
"reply"
],
"Dekodierte Antwort"
)
self
.
assertEqual
(
state
.
sheet
[
"history"
][
-
1
],
{
"role"
:
"assistant"
,
"content"
:
"Dekodierte Antwort"
,
},
)
save_sheet
.
assert_called_once_with
(
state
.
sheet
)
def
test_finalize_response_appends_fallback_reply_to_history
(
self
)
->
None
:
state
=
_build_state
()
with
patch
(
"app.deterministic_services.orchestrators.orchestrator_base.context_store.save_sheet"
)
as
save_sheet
,
patch
(
"app.deterministic_services.orchestrators.orchestrator_base.tool_logging.write_tool_log"
):
result
=
finalize_response
(
state
,
None
)
self
.
assertEqual
(
result
[
"reply"
],
"Dazu steht nichts im Material"
)
self
.
assertEqual
(
state
.
sheet
[
"history"
][
-
1
],
{
"role"
:
"assistant"
,
"content"
:
"Dazu steht nichts im Material"
,
},
)
save_sheet
.
assert_called_once_with
(
state
.
sheet
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment