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
0d411eac
Commit
0d411eac
authored
Jan 23, 2026
by
Kantz
Browse files
Configutation von enviroment durch confg
parent
caed64cc
Changes
4
Hide whitespace changes
Inline
Side-by-side
math-tutor/backend/app/api/canvas.py
View file @
0d411eac
...
@@ -6,25 +6,18 @@ import time
...
@@ -6,25 +6,18 @@ import time
from
pathlib
import
Path
from
pathlib
import
Path
from
typing
import
Optional
from
typing
import
Optional
from
app
import
config
from
fastapi
import
APIRouter
,
HTTPException
from
fastapi
import
APIRouter
,
HTTPException
from
pydantic
import
BaseModel
,
Field
from
pydantic
import
BaseModel
,
Field
from
dotenv
import
load_dotenv
from
mpxpy.mathpix_client
import
MathpixClient
try
:
from
mpxpy.mathpix_client
import
MathpixClient
except
ImportError
:
# pragma: no cover - optional dependency
MathpixClient
=
None
router
=
APIRouter
()
router
=
APIRouter
()
load_dotenv
()
settings
=
config
.
get_mathpix_settings
()
MATHPIX_APP_ID
=
os
.
getenv
(
"MATHPIX_APP_ID"
)
MATHPIX_APP_KEY
=
os
.
getenv
(
"MATHPIX_APP_KEY"
)
mathpix_client
=
None
mathpix_client
=
None
if
MathpixClient
and
MATHPIX_APP_ID
and
MATHPIX_APP_KEY
:
if
settings
.
app_id
and
settings
.
app_key
:
mathpix_client
=
MathpixClient
(
app_id
=
MATHPIX_APP_ID
,
app_key
=
MATHPIX_APP_KEY
)
mathpix_client
=
MathpixClient
(
app_id
=
settings
.
app_id
,
app_key
=
settings
.
app_key
)
class
CanvasSaveRequest
(
BaseModel
):
class
CanvasSaveRequest
(
BaseModel
):
...
@@ -67,19 +60,17 @@ def save_canvas(request: CanvasSaveRequest) -> CanvasSaveResponse:
...
@@ -67,19 +60,17 @@ def save_canvas(request: CanvasSaveRequest) -> CanvasSaveResponse:
with
file_path
.
open
(
"wb"
)
as
handle
:
with
file_path
.
open
(
"wb"
)
as
handle
:
handle
.
write
(
raw
)
handle
.
write
(
raw
)
latex
=
"
\\
frac{a}{b}"
# Placeholder
try
:
if
mathpix_client
:
image
=
mathpix_client
.
image_new
(
str
(
file_path
))
try
:
mmd
=
image
.
mmd
()
image
=
mathpix_client
.
image_new
(
str
(
file_path
))
conversion
=
mathpix_client
.
conversion_new
(
mmd
=
image
.
mmd
()
mmd
=
mmd
,
conversion
=
mathpix_client
.
conversion_new
(
convert_to_md
=
True
,
mmd
=
mmd
,
)
convert_to_md
=
True
,
conversion
.
wait_until_complete
()
)
latex
=
conversion
.
to_md_text
()
conversion
.
wait_until_complete
()
except
Exception
as
exc
:
latex
=
conversion
.
to_md_text
()
raise
HTTPException
(
status_code
=
500
,
detail
=
"mathpix failed"
)
from
exc
except
Exception
as
exc
:
raise
HTTPException
(
status_code
=
500
,
detail
=
"mathpix failed"
)
from
exc
return
CanvasSaveResponse
(
return
CanvasSaveResponse
(
status
=
"ok"
,
status
=
"ok"
,
...
...
math-tutor/backend/app/api/retrieval.py
View file @
0d411eac
...
@@ -8,23 +8,21 @@ from typing import List, Optional
...
@@ -8,23 +8,21 @@ from typing import List, Optional
from
fastapi
import
APIRouter
,
HTTPException
from
fastapi
import
APIRouter
,
HTTPException
from
pydantic
import
BaseModel
,
Field
from
pydantic
import
BaseModel
,
Field
from
dotenv
import
load_dotenv
from
app
import
config
from
app.services.embeddings
import
OpenAILikeEmbeddings
from
app.services.embeddings
import
OpenAILikeEmbeddings
from
app.services
import
vector_store
from
app.services
import
vector_store
router
=
APIRouter
()
router
=
APIRouter
()
load_dotenv
()
def
_get_embedder
()
->
OpenAILikeEmbeddings
:
def
_get_embedder
()
->
OpenAILikeEmbeddings
:
base_url
=
os
.
getenv
(
"OPENAI_BASE_URL"
)
settings
=
config
.
get_embedding_settings
()
api_key
=
os
.
getenv
(
"OPENAI_API_KEY"
)
return
OpenAILikeEmbeddings
(
model
=
os
.
getenv
(
"OPENAI_EMBED_MODEL"
,
"text-embedding-3-large"
)
base_url
=
settings
.
base_url
,
if
not
base_url
or
not
api_key
:
api_key
=
settings
.
api_key
,
raise
HTTPException
(
status_code
=
500
,
detail
=
"Missing OPENAI_BASE_URL or OPENAI_API_KEY"
)
model
=
settings
.
model
,
return
OpenAILikeEmbeddings
(
base_url
=
base_url
,
api_key
=
api_key
,
model
=
model
,
target_dim
=
1024
)
target_dim
=
settings
.
target_dim
,
)
class
InitDbRequest
(
BaseModel
):
class
InitDbRequest
(
BaseModel
):
...
@@ -118,8 +116,3 @@ def subsections(pg_url: Optional[str] = None, section_index: Optional[int] = Non
...
@@ -118,8 +116,3 @@ def subsections(pg_url: Optional[str] = None, section_index: Optional[int] = Non
if
not
url
:
if
not
url
:
raise
HTTPException
(
status_code
=
500
,
detail
=
"Missing POSTGRES_URL"
)
raise
HTTPException
(
status_code
=
500
,
detail
=
"Missing POSTGRES_URL"
)
return
vector_store
.
list_subsections
(
url
,
section_index
)
return
vector_store
.
list_subsections
(
url
,
section_index
)
@
router
.
get
(
"/api/retrieval/health"
)
def
retrieval_health
()
->
dict
:
return
{
"status"
:
"ok"
}
math-tutor/backend/app/config.py
View file @
0d411eac
...
@@ -21,6 +21,11 @@ class EmbeddingSettings:
...
@@ -21,6 +21,11 @@ class EmbeddingSettings:
model
:
str
model
:
str
target_dim
:
int
target_dim
:
int
@
dataclass
(
frozen
=
True
)
class
MathpixSettings
:
app_id
:
str
app_key
:
str
def
_read_float
(
value
:
str
|
None
)
->
float
|
None
:
def
_read_float
(
value
:
str
|
None
)
->
float
|
None
:
if
value
is
None
or
value
==
""
:
if
value
is
None
or
value
==
""
:
...
@@ -30,6 +35,11 @@ def _read_float(value: str | None) -> float | None:
...
@@ -30,6 +35,11 @@ def _read_float(value: str | None) -> float | None:
except
ValueError
:
except
ValueError
:
return
None
return
None
def
get_mathpix_settings
()
->
MathpixSettings
:
return
MathpixSettings
(
app_id
=
os
.
getenv
(
"MATHPIX_APP_ID"
),
app_key
=
os
.
getenv
(
"MATHPIX_APP_KEY"
)
)
def
get_ollama_settings
()
->
OllamaSettings
:
def
get_ollama_settings
()
->
OllamaSettings
:
return
OllamaSettings
(
return
OllamaSettings
(
...
...
math-tutor/backend/app/services/retrieval_service.py
View file @
0d411eac
...
@@ -6,19 +6,6 @@ from app import config
...
@@ -6,19 +6,6 @@ from app import config
from
app.services.embeddings
import
OpenAILikeEmbeddings
from
app.services.embeddings
import
OpenAILikeEmbeddings
from
app.services
import
vector_store
from
app.services
import
vector_store
SYSTEM_PROMPT
=
(
"Du bist ein Mathe-Tutor. Antworte auf Deutsch, klar und korrekt. "
"Nutze ausschliesslich den bereitgestellten Kontext. Wenn nichts zur Frage im Kontext steht, "
'antworte mit "Dazu steht nichts im Material" und nichts weiter. '
"Gib wenn moeglich eine kurze Struktur: (1) Idee, "
"(2) Definition, "
"(3) kurzer Begruendungs-/Rechenweg, "
"(4) Mini-Beispiel. "
"Zitiere Quellen inline mit den eckigen Klammern, die im Kontext vorangestellt sind, "
"z.B. [s2/ss1/c3 | definition | ...]."
)
CONTEXT_LIMITS
=
{
CONTEXT_LIMITS
=
{
"direct"
:
4
,
"direct"
:
4
,
"indirect"
:
6
,
"indirect"
:
6
,
...
...
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