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
4c17a9fc
Commit
4c17a9fc
authored
May 04, 2026
by
Kantz
Browse files
socratic dialog läde vorgenerierte startnachricht
parent
14c86080
Changes
2
Hide whitespace changes
Inline
Side-by-side
math-tutor/backend/app/api/chat.py
View file @
4c17a9fc
...
...
@@ -6,7 +6,7 @@ from typing import List, Optional
import
app.config
as
config
from
app.deterministic_services
import
session_store
from
app.deterministic_services
import
context_store
,
retrieval_store
,
task_catalog
from
app.
LLM
_services
import
socratic_
LLM
from
app.
deterministic
_services
import
socratic_
bootstrap_prompts
from
app.deterministic_services.orchestrators.registry
import
(
get_default_orchestrator
,
is_valid_orchestrator
,
...
...
@@ -204,15 +204,11 @@ def bootstrap_socratic(request: SocraticBootstrapRequest) -> SocraticBootstrapRe
context_store
.
set_initialized
(
sheet
,
True
)
context_store
.
save_sheet
(
sheet
)
sources_text
=
"
\n
"
.
join
(
source
.
to_string
()
for
source
in
sources
)
reply
=
socratic_LLM
.
generate_dialog
(
query
=
"Was sind die Themen dieses Abschnitts? Frage mich, mit welchem ich mich zuerst beschäftigen möchte."
,
subsection_refs
=
refs
,
history
=
None
,
sources
=
sources_text
,
)
if
not
reply
:
reply
=
"Was sind die Themen dieses Abschnitts? Womit möchtest du anfangen?"
try
:
reply
=
socratic_bootstrap_prompts
.
get_initial_message
(
request
.
subsection_key
)
except
ValueError
as
exc
:
logger
.
exception
(
"Socratic bootstrap prompt lookup failed"
)
raise
HTTPException
(
status_code
=
500
,
detail
=
str
(
exc
))
from
exc
context_store
.
append_history_message
(
sheet
,
"assistant"
,
reply
)
context_store
.
save_sheet
(
sheet
)
...
...
math-tutor/backend/app/deterministic_services/socratic_bootstrap_prompts.py
0 → 100644
View file @
4c17a9fc
from
__future__
import
annotations
from
functools
import
lru_cache
from
pathlib
import
Path
from
typing
import
Any
import
yaml
from
app.deterministic_services
import
task_catalog
PROMPTS_PATH
=
Path
(
__file__
).
resolve
().
parents
[
2
]
/
"sources"
/
"socratic_chats"
/
"initial_prompts.yml"
@
lru_cache
(
maxsize
=
1
)
def
load_initial_prompt_items
(
path
:
Path
=
PROMPTS_PATH
)
->
dict
[
str
,
dict
[
str
,
Any
]]:
try
:
payload
=
yaml
.
safe_load
(
path
.
read_text
(
encoding
=
"utf-8"
))
or
{}
except
Exception
as
exc
:
raise
ValueError
(
f
"invalid socratic bootstrap prompts:
{
path
}
"
)
from
exc
if
not
isinstance
(
payload
,
dict
):
raise
ValueError
(
"invalid socratic bootstrap prompts payload"
)
raw_items
=
payload
.
get
(
"items"
)
if
not
isinstance
(
raw_items
,
dict
):
raise
ValueError
(
"invalid socratic bootstrap prompts items"
)
items
:
dict
[
str
,
dict
[
str
,
Any
]]
=
{}
for
raw_key
,
raw_value
in
raw_items
.
items
():
key
=
task_catalog
.
_normalize_subsection_key
(
str
(
raw_key
))
if
not
key
or
not
isinstance
(
raw_value
,
dict
):
continue
items
[
key
]
=
raw_value
return
items
def
get_initial_message
(
subsection_key
:
str
,
path
:
Path
=
PROMPTS_PATH
)
->
str
:
normalized_key
=
task_catalog
.
_normalize_subsection_key
(
subsection_key
)
if
not
normalized_key
:
raise
ValueError
(
"invalid subsection key"
)
items
=
load_initial_prompt_items
(
path
)
item
=
items
.
get
(
normalized_key
)
if
item
is
None
:
raise
ValueError
(
f
"missing socratic bootstrap prompt for subsection '
{
normalized_key
}
'"
)
message
=
str
(
item
.
get
(
"inital_message"
)
or
""
).
strip
()
if
not
message
:
raise
ValueError
(
f
"empty socratic bootstrap prompt for subsection '
{
normalized_key
}
'"
)
return
message
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