Skip to content

Commit cf86b39

Browse files
committed
refactor(chain): extract ebbinghaus
1 parent f9865e3 commit cf86b39

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

server/apis/question.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def examine_question(data: types.AnswerQuestion):
1616
)
1717

1818
return chain.aexamine_answer(
19-
id=data.id,
19+
quesiton_id=data.id,
2020
context=document_info["document"],
2121
question=question_info["content"],
2222
role=question_info["designated_role"],

server/llm_services/langchain_chain.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import db_services as _dbs_
1212

13+
from utils.ebbinghaus import handle_ebbinghaus_memory
1314
from .langchain_llm import LLM
1415
from prompts import choose_prompt
1516

@@ -80,15 +81,15 @@ async def _agenerate_questions(
8081

8182
async def aexamine_answer(
8283
self,
83-
id: int,
84+
quesiton_id: int,
8485
context: str,
8586
question: str,
8687
answer: str,
8788
role: str,
8889
question_type: str,
8990
):
9091
llm_chain = self._init_llm_chain(60, role, question_type)
91-
coroutine = wait_done(llm_chain.apredict(
92+
coroutine = _wait_done(llm_chain.apredict(
9293
context=context,
9394
question=question,
9495
answer=answer,
@@ -110,7 +111,7 @@ async def aexamine_answer(
110111
score = _extract_score(exmine)
111112
push_date = _get_push_date(score)
112113
await _dbs_.question.update_question_state(
113-
id=id,
114+
id=quesiton_id,
114115
answer=f"{answer} ||| {exmine}",
115116
score=score,
116117
push_date=push_date
@@ -138,7 +139,7 @@ def _init_llm_chain(self, timeout: int, role: str, question_type: str):
138139
)
139140

140141

141-
async def wait_done(
142+
async def _wait_done(
142143
fn: Awaitable,
143144
event: asyncio.Event
144145
):
@@ -209,15 +210,5 @@ def _extract_score(anwser: str):
209210

210211
def _get_push_date(score: int):
211212
now = datetime.datetime.now()
212-
days = 0
213-
214-
if (0 <= score <= 3):
215-
days = 1
216-
if (4 <= score <= 6):
217-
days = 3
218-
if (7 <= score <= 9):
219-
days = 7
220-
if (10 == score):
221-
days = 14
222-
213+
days = handle_ebbinghaus_memory(score)
223214
return ((now+datetime.timedelta(days)).strftime("%Y-%m-%d"))

server/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .file_handler import upload_file
22

33
__all__ = [
4-
"upload_file"
4+
"upload_file",
55
]

server/utils/ebbinghaus.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def handle_ebbinghaus_memory(score: int):
2+
if (0 <= score <= 3):
3+
days = 1
4+
if (4 <= score <= 6):
5+
days = 3
6+
if (7 <= score <= 9):
7+
days = 7
8+
if (10 == score):
9+
days = 14
10+
11+
return days

0 commit comments

Comments
 (0)