1
1
import os
2
2
import re
3
3
import asyncio
4
+ import datetime
4
5
5
6
from typing import Awaitable
6
7
from langchain import LLMChain
@@ -24,17 +25,6 @@ def __init__(
24
25
temperature : int = 0 ,
25
26
streaming : bool = False
26
27
):
27
- """
28
- Initializes a Chain instance.
29
-
30
- :param note_id: The ID of the note.
31
- :param file_id: The ID of the file.
32
- :param filename: The filename.
33
- :param prompt_language: The language for prompts.
34
- :param prompt_type: The type of prompt.
35
- :param temperature: The temperature for language model.
36
- :param streaming: Whether streaming is enabled.
37
- """
38
28
self .semaphore = asyncio .Semaphore (
39
29
_adjust_concurrency_by_payment_status ())
40
30
self .note_id = note_id
@@ -52,12 +42,6 @@ async def agenerate_questions(
52
42
title : str ,
53
43
question_type : str
54
44
):
55
- """
56
- Generates questions for documents.
57
-
58
- :param docs: List of Document objects.
59
- :param title: The title of the questions.
60
- """
61
45
tasks = []
62
46
llm_chain = self ._init_llm_chain (60 , "" , question_type )
63
47
for doc in docs :
@@ -80,14 +64,6 @@ async def _agenerate_questions(
80
64
doc_id : int ,
81
65
question_type : str
82
66
):
83
- """
84
- Generates questions for a document using the language model.
85
-
86
- :param llm_chain: The LLMChain instance.
87
- :param doc: The Document object.
88
- :param title: The title for questions.
89
- :param doc_id: The ID of the document.
90
- """
91
67
async with self .semaphore :
92
68
res = await llm_chain .apredict (
93
69
title = title ,
@@ -111,16 +87,6 @@ async def aexamine_answer(
111
87
role : str ,
112
88
question_type : str ,
113
89
):
114
- """
115
- Examines an answer using the language model.
116
-
117
- :param id: The ID of the question.
118
- :param context: The context for examination.
119
- :param question: The question for examination.
120
- :param answer: The answer for examination.
121
- :param role: The role for the examination.
122
- :yield: The examination results.
123
- """
124
90
llm_chain = self ._init_llm_chain (60 , role , question_type )
125
91
coroutine = wait_done (llm_chain .apredict (
126
92
context = context ,
@@ -141,16 +107,16 @@ async def aexamine_answer(
141
107
yield str (e )
142
108
return
143
109
144
- await _dbs_ .question .update_question_state (id , f"{ answer } ||| { exmine } " )
110
+ score = _extract_score (exmine )
111
+ push_date = _get_push_date (score )
112
+ await _dbs_ .question .update_question_state (
113
+ id = id ,
114
+ answer = f"{ answer } ||| { exmine } " ,
115
+ score = score ,
116
+ push_date = push_date
117
+ )
145
118
146
119
def _init_llm_chain (self , timeout : int , role : str , question_type : str ):
147
- """
148
- Initializes the language model chain.
149
-
150
- :param timeout: The timeout value.
151
- :param role: The role for the examination.
152
- :return: The initialized LLMChain instance.
153
- """
154
120
llm_instance = LLM (
155
121
temperature = self .temperature ,
156
122
streaming = self .streaming ,
@@ -231,3 +197,27 @@ def _is_legal_question_structure(
231
197
def _remove_prefix_numbers (text ):
232
198
cleaned_text = re .sub (r'^\s*(?:\d+\.|-)\s*' , '' , text )
233
199
return cleaned_text .strip ()
200
+
201
+
202
+ def _extract_score (anwser : str ):
203
+ score = re .findall (r"\d+\.?\d*" , anwser )
204
+ if score :
205
+ return int (float (score [0 ]))
206
+ else :
207
+ return 0
208
+
209
+
210
+ def _get_push_date (score : int ):
211
+ 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
+
223
+ return ((now + datetime .timedelta (days )).strftime ("%Y-%m-%d" ))
0 commit comments