reme-ai 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reme_ai/__init__.py +6 -0
- reme_ai/app.py +17 -0
- reme_ai/config/__init__.py +0 -0
- reme_ai/config/config_parser.py +6 -0
- reme_ai/constants/__init__.py +7 -0
- reme_ai/constants/common_constants.py +48 -0
- reme_ai/constants/language_constants.py +215 -0
- reme_ai/enumeration/__init__.py +0 -0
- reme_ai/enumeration/language_constants.py +215 -0
- reme_ai/react/__init__.py +1 -0
- reme_ai/react/simple_react_op.py +21 -0
- reme_ai/retrieve/__init__.py +2 -0
- reme_ai/retrieve/personal/__init__.py +17 -0
- reme_ai/retrieve/personal/extract_time_op.py +97 -0
- reme_ai/retrieve/personal/fuse_rerank_op.py +180 -0
- reme_ai/retrieve/personal/print_memory_op.py +131 -0
- reme_ai/retrieve/personal/read_message_op.py +52 -0
- reme_ai/retrieve/personal/retrieve_memory_op.py +13 -0
- reme_ai/retrieve/personal/semantic_rank_op.py +170 -0
- reme_ai/retrieve/personal/set_query_op.py +37 -0
- reme_ai/retrieve/task/__init__.py +4 -0
- reme_ai/retrieve/task/build_query_op.py +38 -0
- reme_ai/retrieve/task/merge_memory_op.py +27 -0
- reme_ai/retrieve/task/rerank_memory_op.py +149 -0
- reme_ai/retrieve/task/rewrite_memory_op.py +149 -0
- reme_ai/schema/__init__.py +1 -0
- reme_ai/schema/memory.py +144 -0
- reme_ai/summary/__init__.py +2 -0
- reme_ai/summary/personal/__init__.py +8 -0
- reme_ai/summary/personal/contra_repeat_op.py +143 -0
- reme_ai/summary/personal/get_observation_op.py +147 -0
- reme_ai/summary/personal/get_observation_with_time_op.py +165 -0
- reme_ai/summary/personal/get_reflection_subject_op.py +179 -0
- reme_ai/summary/personal/info_filter_op.py +177 -0
- reme_ai/summary/personal/load_today_memory_op.py +117 -0
- reme_ai/summary/personal/long_contra_repeat_op.py +210 -0
- reme_ai/summary/personal/update_insight_op.py +244 -0
- reme_ai/summary/task/__init__.py +10 -0
- reme_ai/summary/task/comparative_extraction_op.py +233 -0
- reme_ai/summary/task/failure_extraction_op.py +73 -0
- reme_ai/summary/task/memory_deduplication_op.py +163 -0
- reme_ai/summary/task/memory_validation_op.py +108 -0
- reme_ai/summary/task/pdf_preprocess_op_wrapper.py +50 -0
- reme_ai/summary/task/simple_comparative_summary_op.py +71 -0
- reme_ai/summary/task/simple_summary_op.py +67 -0
- reme_ai/summary/task/success_extraction_op.py +73 -0
- reme_ai/summary/task/trajectory_preprocess_op.py +76 -0
- reme_ai/summary/task/trajectory_segmentation_op.py +118 -0
- reme_ai/utils/__init__.py +0 -0
- reme_ai/utils/datetime_handler.py +345 -0
- reme_ai/utils/miner_u_pdf_processor.py +726 -0
- reme_ai/utils/op_utils.py +115 -0
- reme_ai/vector_store/__init__.py +6 -0
- reme_ai/vector_store/delete_memory_op.py +25 -0
- reme_ai/vector_store/recall_vector_store_op.py +36 -0
- reme_ai/vector_store/update_memory_freq_op.py +33 -0
- reme_ai/vector_store/update_memory_utility_op.py +32 -0
- reme_ai/vector_store/update_vector_store_op.py +32 -0
- reme_ai/vector_store/vector_store_action_op.py +55 -0
- reme_ai-0.1.0.dist-info/METADATA +218 -0
- reme_ai-0.1.0.dist-info/RECORD +65 -0
- reme_ai-0.1.0.dist-info/WHEEL +5 -0
- reme_ai-0.1.0.dist-info/entry_points.txt +2 -0
- reme_ai-0.1.0.dist-info/licenses/LICENSE +201 -0
- reme_ai-0.1.0.dist-info/top_level.txt +1 -0
reme_ai/__init__.py
ADDED
reme_ai/app.py
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import sys
|
2
|
+
|
3
|
+
from flowllm.service.base_service import BaseService
|
4
|
+
|
5
|
+
from reme_ai.config.config_parser import ConfigParser
|
6
|
+
|
7
|
+
|
8
|
+
def main():
|
9
|
+
with BaseService.get_service(*sys.argv[1:], parser=ConfigParser) as service:
|
10
|
+
service()
|
11
|
+
|
12
|
+
|
13
|
+
if __name__ == "__main__":
|
14
|
+
main()
|
15
|
+
|
16
|
+
# python -m build
|
17
|
+
# twine upload dist/*
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# common_constants.py
|
2
|
+
# This module defines constants used as keys throughout the application to maintain a consistent reference
|
3
|
+
# for data structures related to workflow management, chat interactions, context storage, memory operations,
|
4
|
+
# node processing, and temporal inference functionalities.
|
5
|
+
|
6
|
+
WORKFLOW_NAME = "workflow_name"
|
7
|
+
|
8
|
+
MEMORYSCOPE_CONTEXT = "memoryscope_context"
|
9
|
+
|
10
|
+
RESULT = "result"
|
11
|
+
|
12
|
+
MEMORIES = "memories"
|
13
|
+
|
14
|
+
CHAT_MESSAGES = "chat_messages"
|
15
|
+
|
16
|
+
CHAT_MESSAGES_SCATTER = "chat_messages_scatter"
|
17
|
+
|
18
|
+
CHAT_KWARGS = "chat_kwargs"
|
19
|
+
|
20
|
+
USER_NAME = "user_name"
|
21
|
+
|
22
|
+
TARGET_NAME = "target_name"
|
23
|
+
|
24
|
+
MEMORY_MANAGER = "memory_manager"
|
25
|
+
|
26
|
+
QUERY_WITH_TS = "query_with_ts"
|
27
|
+
|
28
|
+
RETRIEVE_MEMORY_NODES = "retrieve_memory_nodes"
|
29
|
+
|
30
|
+
RANKED_MEMORY_NODES = "ranked_memory_nodes"
|
31
|
+
|
32
|
+
NOT_REFLECTED_NODES = "not_reflected_nodes"
|
33
|
+
|
34
|
+
NOT_UPDATED_NODES = "not_updated_nodes"
|
35
|
+
|
36
|
+
EXTRACT_TIME_DICT = "extract_time_dict"
|
37
|
+
|
38
|
+
NEW_OBS_NODES = "new_obs_nodes"
|
39
|
+
|
40
|
+
NEW_OBS_WITH_TIME_NODES = "new_obs_with_time_nodes"
|
41
|
+
|
42
|
+
INSIGHT_NODES = "insight_nodes"
|
43
|
+
|
44
|
+
TODAY_NODES = "today_nodes"
|
45
|
+
|
46
|
+
MERGE_OBS_NODES = "merge_obs_nodes"
|
47
|
+
|
48
|
+
TIME_INFER = "time_infer"
|
@@ -0,0 +1,215 @@
|
|
1
|
+
from memoryscope.enumeration.language_enum import LanguageEnum
|
2
|
+
|
3
|
+
# This dictionary maps languages to lists of words related to datetime expressions.
|
4
|
+
# It aids in recognizing and processing datetime mentions in text, enhancing the system's ability to understand
|
5
|
+
# temporal context across different languages.
|
6
|
+
DATATIME_WORD_LIST = {
|
7
|
+
LanguageEnum.CN: [
|
8
|
+
"天",
|
9
|
+
"周",
|
10
|
+
"月",
|
11
|
+
"年",
|
12
|
+
"星期",
|
13
|
+
"点",
|
14
|
+
"分钟",
|
15
|
+
"小时",
|
16
|
+
"秒",
|
17
|
+
"上午",
|
18
|
+
"下午",
|
19
|
+
"早上",
|
20
|
+
"早晨",
|
21
|
+
"晚上",
|
22
|
+
"中午",
|
23
|
+
"日",
|
24
|
+
"夜",
|
25
|
+
"清晨",
|
26
|
+
"傍晚",
|
27
|
+
"凌晨",
|
28
|
+
"岁",
|
29
|
+
],
|
30
|
+
LanguageEnum.EN: [
|
31
|
+
# Units of Time
|
32
|
+
"year", "yr",
|
33
|
+
"month", "mo",
|
34
|
+
"week", "wk",
|
35
|
+
"day", "d",
|
36
|
+
"hour", "hr",
|
37
|
+
"minute", "min",
|
38
|
+
"second", "sec",
|
39
|
+
|
40
|
+
# Days of the Week
|
41
|
+
"Monday", "Mon",
|
42
|
+
"Tuesday", "Tue", "Tues",
|
43
|
+
"Wednesday", "Wed",
|
44
|
+
"Thursday", "Thu", "Thur", "Thurs",
|
45
|
+
"Friday", "Fri",
|
46
|
+
"Saturday", "Sat",
|
47
|
+
"Sunday", "Sun",
|
48
|
+
|
49
|
+
# Months of the Year
|
50
|
+
"January", "Jan",
|
51
|
+
"February", "Feb",
|
52
|
+
"March", "Mar",
|
53
|
+
"April", "Apr",
|
54
|
+
"May", "May",
|
55
|
+
"June", "Jun",
|
56
|
+
"July", "Jul",
|
57
|
+
"August", "Aug",
|
58
|
+
"September", "Sep", "Sept",
|
59
|
+
"October", "Oct",
|
60
|
+
"November", "Nov",
|
61
|
+
"December", "Dec",
|
62
|
+
|
63
|
+
# Relative Time References
|
64
|
+
"Today",
|
65
|
+
"Tomorrow", "Tmrw",
|
66
|
+
"Yesterday", "Yday",
|
67
|
+
"Now",
|
68
|
+
"Morning", "AM", "a.m.",
|
69
|
+
"Afternoon", "PM", "p.m.",
|
70
|
+
"Evening",
|
71
|
+
"Night",
|
72
|
+
"Midnight",
|
73
|
+
"Noon",
|
74
|
+
|
75
|
+
# Seasonal References
|
76
|
+
"Spring",
|
77
|
+
"Summer",
|
78
|
+
"Autumn", "Fall",
|
79
|
+
"Winter",
|
80
|
+
|
81
|
+
# General Time References
|
82
|
+
"Century", "cent.",
|
83
|
+
"Decade",
|
84
|
+
"Millennium",
|
85
|
+
"Quarter", "Q1", "Q2", "Q3", "Q4",
|
86
|
+
"Semester",
|
87
|
+
"Fortnight",
|
88
|
+
"Weekend"
|
89
|
+
]
|
90
|
+
}
|
91
|
+
|
92
|
+
# A mapping of weekdays for each supported language, facilitating calendar-related operations and understanding
|
93
|
+
# within the application.
|
94
|
+
WEEKDAYS = {
|
95
|
+
LanguageEnum.CN: [
|
96
|
+
"周一",
|
97
|
+
"周二",
|
98
|
+
"周三",
|
99
|
+
"周四",
|
100
|
+
"周五",
|
101
|
+
"周六",
|
102
|
+
"周日"
|
103
|
+
],
|
104
|
+
LanguageEnum.EN: [
|
105
|
+
"Monday",
|
106
|
+
"Tuesday",
|
107
|
+
"Wednesday",
|
108
|
+
"Thursday",
|
109
|
+
"Friday",
|
110
|
+
"Saturday",
|
111
|
+
"Sunday",
|
112
|
+
]
|
113
|
+
}
|
114
|
+
|
115
|
+
MONTH_DICT = {
|
116
|
+
LanguageEnum.CN: [
|
117
|
+
"1月",
|
118
|
+
"2月",
|
119
|
+
"3月",
|
120
|
+
"4月",
|
121
|
+
"5月",
|
122
|
+
"6月",
|
123
|
+
"7月",
|
124
|
+
"8月",
|
125
|
+
"9月",
|
126
|
+
"10月",
|
127
|
+
"11月",
|
128
|
+
"12月",
|
129
|
+
],
|
130
|
+
LanguageEnum.EN: [
|
131
|
+
"January",
|
132
|
+
"February",
|
133
|
+
"March",
|
134
|
+
"April",
|
135
|
+
"May",
|
136
|
+
"June",
|
137
|
+
"July",
|
138
|
+
"August",
|
139
|
+
"September",
|
140
|
+
"October",
|
141
|
+
"November",
|
142
|
+
"December",
|
143
|
+
]
|
144
|
+
}
|
145
|
+
|
146
|
+
# Constants for the word 'none' in different languages
|
147
|
+
NONE_WORD = {
|
148
|
+
LanguageEnum.CN: "无",
|
149
|
+
LanguageEnum.EN: "none"
|
150
|
+
}
|
151
|
+
|
152
|
+
# Constants for the word 'repeated' in different languages
|
153
|
+
REPEATED_WORD = {
|
154
|
+
LanguageEnum.CN: "重复",
|
155
|
+
LanguageEnum.EN: "repeated"
|
156
|
+
}
|
157
|
+
|
158
|
+
# Constants for the word 'contradictory' in different languages
|
159
|
+
CONTRADICTORY_WORD = {
|
160
|
+
LanguageEnum.CN: "矛盾",
|
161
|
+
LanguageEnum.EN: "contradiction"
|
162
|
+
}
|
163
|
+
|
164
|
+
# Constants for the phrase 'included' in different languages
|
165
|
+
CONTAINED_WORD = {
|
166
|
+
LanguageEnum.CN: "被包含",
|
167
|
+
LanguageEnum.EN: "contained"
|
168
|
+
}
|
169
|
+
|
170
|
+
# Constants for the symbol ':' in different languages' representations
|
171
|
+
COLON_WORD = {
|
172
|
+
LanguageEnum.CN: ":",
|
173
|
+
LanguageEnum.EN: ":"
|
174
|
+
}
|
175
|
+
|
176
|
+
# Constants for the symbol ',' in different languages' representations
|
177
|
+
COMMA_WORD = {
|
178
|
+
LanguageEnum.CN: ",",
|
179
|
+
LanguageEnum.EN: ","
|
180
|
+
}
|
181
|
+
|
182
|
+
# Default human name placeholders for different languages
|
183
|
+
DEFAULT_HUMAN_NAME = {
|
184
|
+
LanguageEnum.CN: "用户",
|
185
|
+
LanguageEnum.EN: "user"
|
186
|
+
}
|
187
|
+
|
188
|
+
# Mapping of datetime terms from natural language to standardized keys for each supported language
|
189
|
+
DATATIME_KEY_MAP = {
|
190
|
+
LanguageEnum.CN: {
|
191
|
+
"年": "year",
|
192
|
+
"月": "month",
|
193
|
+
"日": "day",
|
194
|
+
"周": "week",
|
195
|
+
"星期几": "weekday",
|
196
|
+
},
|
197
|
+
LanguageEnum.EN: {
|
198
|
+
"Year": "year",
|
199
|
+
"Month": "month",
|
200
|
+
"Day": "day",
|
201
|
+
"Week": "week",
|
202
|
+
"Weekday": "weekday",
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
# Phrase for indicating inferred time in different languages
|
207
|
+
TIME_INFER_WORD = {
|
208
|
+
LanguageEnum.CN: "推断时间",
|
209
|
+
LanguageEnum.EN: "Inference time"
|
210
|
+
}
|
211
|
+
|
212
|
+
USER_NAME_EXPRESSION = {
|
213
|
+
LanguageEnum.CN: "用户姓名是{name}。",
|
214
|
+
LanguageEnum.EN: "User's name is {name}."
|
215
|
+
}
|
File without changes
|
@@ -0,0 +1,215 @@
|
|
1
|
+
from memoryscope.enumeration.language_enum import LanguageEnum
|
2
|
+
|
3
|
+
# This dictionary maps languages to lists of words related to datetime expressions.
|
4
|
+
# It aids in recognizing and processing datetime mentions in text, enhancing the system's ability to understand
|
5
|
+
# temporal context across different languages.
|
6
|
+
DATATIME_WORD_LIST = {
|
7
|
+
LanguageEnum.CN: [
|
8
|
+
"天",
|
9
|
+
"周",
|
10
|
+
"月",
|
11
|
+
"年",
|
12
|
+
"星期",
|
13
|
+
"点",
|
14
|
+
"分钟",
|
15
|
+
"小时",
|
16
|
+
"秒",
|
17
|
+
"上午",
|
18
|
+
"下午",
|
19
|
+
"早上",
|
20
|
+
"早晨",
|
21
|
+
"晚上",
|
22
|
+
"中午",
|
23
|
+
"日",
|
24
|
+
"夜",
|
25
|
+
"清晨",
|
26
|
+
"傍晚",
|
27
|
+
"凌晨",
|
28
|
+
"岁",
|
29
|
+
],
|
30
|
+
LanguageEnum.EN: [
|
31
|
+
# Units of Time
|
32
|
+
"year", "yr",
|
33
|
+
"month", "mo",
|
34
|
+
"week", "wk",
|
35
|
+
"day", "d",
|
36
|
+
"hour", "hr",
|
37
|
+
"minute", "min",
|
38
|
+
"second", "sec",
|
39
|
+
|
40
|
+
# Days of the Week
|
41
|
+
"Monday", "Mon",
|
42
|
+
"Tuesday", "Tue", "Tues",
|
43
|
+
"Wednesday", "Wed",
|
44
|
+
"Thursday", "Thu", "Thur", "Thurs",
|
45
|
+
"Friday", "Fri",
|
46
|
+
"Saturday", "Sat",
|
47
|
+
"Sunday", "Sun",
|
48
|
+
|
49
|
+
# Months of the Year
|
50
|
+
"January", "Jan",
|
51
|
+
"February", "Feb",
|
52
|
+
"March", "Mar",
|
53
|
+
"April", "Apr",
|
54
|
+
"May", "May",
|
55
|
+
"June", "Jun",
|
56
|
+
"July", "Jul",
|
57
|
+
"August", "Aug",
|
58
|
+
"September", "Sep", "Sept",
|
59
|
+
"October", "Oct",
|
60
|
+
"November", "Nov",
|
61
|
+
"December", "Dec",
|
62
|
+
|
63
|
+
# Relative Time References
|
64
|
+
"Today",
|
65
|
+
"Tomorrow", "Tmrw",
|
66
|
+
"Yesterday", "Yday",
|
67
|
+
"Now",
|
68
|
+
"Morning", "AM", "a.m.",
|
69
|
+
"Afternoon", "PM", "p.m.",
|
70
|
+
"Evening",
|
71
|
+
"Night",
|
72
|
+
"Midnight",
|
73
|
+
"Noon",
|
74
|
+
|
75
|
+
# Seasonal References
|
76
|
+
"Spring",
|
77
|
+
"Summer",
|
78
|
+
"Autumn", "Fall",
|
79
|
+
"Winter",
|
80
|
+
|
81
|
+
# General Time References
|
82
|
+
"Century", "cent.",
|
83
|
+
"Decade",
|
84
|
+
"Millennium",
|
85
|
+
"Quarter", "Q1", "Q2", "Q3", "Q4",
|
86
|
+
"Semester",
|
87
|
+
"Fortnight",
|
88
|
+
"Weekend"
|
89
|
+
]
|
90
|
+
}
|
91
|
+
|
92
|
+
# A mapping of weekdays for each supported language, facilitating calendar-related operations and understanding
|
93
|
+
# within the application.
|
94
|
+
WEEKDAYS = {
|
95
|
+
LanguageEnum.CN: [
|
96
|
+
"周一",
|
97
|
+
"周二",
|
98
|
+
"周三",
|
99
|
+
"周四",
|
100
|
+
"周五",
|
101
|
+
"周六",
|
102
|
+
"周日"
|
103
|
+
],
|
104
|
+
LanguageEnum.EN: [
|
105
|
+
"Monday",
|
106
|
+
"Tuesday",
|
107
|
+
"Wednesday",
|
108
|
+
"Thursday",
|
109
|
+
"Friday",
|
110
|
+
"Saturday",
|
111
|
+
"Sunday",
|
112
|
+
]
|
113
|
+
}
|
114
|
+
|
115
|
+
MONTH_DICT = {
|
116
|
+
LanguageEnum.CN: [
|
117
|
+
"1月",
|
118
|
+
"2月",
|
119
|
+
"3月",
|
120
|
+
"4月",
|
121
|
+
"5月",
|
122
|
+
"6月",
|
123
|
+
"7月",
|
124
|
+
"8月",
|
125
|
+
"9月",
|
126
|
+
"10月",
|
127
|
+
"11月",
|
128
|
+
"12月",
|
129
|
+
],
|
130
|
+
LanguageEnum.EN: [
|
131
|
+
"January",
|
132
|
+
"February",
|
133
|
+
"March",
|
134
|
+
"April",
|
135
|
+
"May",
|
136
|
+
"June",
|
137
|
+
"July",
|
138
|
+
"August",
|
139
|
+
"September",
|
140
|
+
"October",
|
141
|
+
"November",
|
142
|
+
"December",
|
143
|
+
]
|
144
|
+
}
|
145
|
+
|
146
|
+
# Constants for the word 'none' in different languages
|
147
|
+
NONE_WORD = {
|
148
|
+
LanguageEnum.CN: "无",
|
149
|
+
LanguageEnum.EN: "none"
|
150
|
+
}
|
151
|
+
|
152
|
+
# Constants for the word 'repeated' in different languages
|
153
|
+
REPEATED_WORD = {
|
154
|
+
LanguageEnum.CN: "重复",
|
155
|
+
LanguageEnum.EN: "repeated"
|
156
|
+
}
|
157
|
+
|
158
|
+
# Constants for the word 'contradictory' in different languages
|
159
|
+
CONTRADICTORY_WORD = {
|
160
|
+
LanguageEnum.CN: "矛盾",
|
161
|
+
LanguageEnum.EN: "contradiction"
|
162
|
+
}
|
163
|
+
|
164
|
+
# Constants for the phrase 'included' in different languages
|
165
|
+
CONTAINED_WORD = {
|
166
|
+
LanguageEnum.CN: "被包含",
|
167
|
+
LanguageEnum.EN: "contained"
|
168
|
+
}
|
169
|
+
|
170
|
+
# Constants for the symbol ':' in different languages' representations
|
171
|
+
COLON_WORD = {
|
172
|
+
LanguageEnum.CN: ":",
|
173
|
+
LanguageEnum.EN: ":"
|
174
|
+
}
|
175
|
+
|
176
|
+
# Constants for the symbol ',' in different languages' representations
|
177
|
+
COMMA_WORD = {
|
178
|
+
LanguageEnum.CN: ",",
|
179
|
+
LanguageEnum.EN: ","
|
180
|
+
}
|
181
|
+
|
182
|
+
# Default human name placeholders for different languages
|
183
|
+
DEFAULT_HUMAN_NAME = {
|
184
|
+
LanguageEnum.CN: "用户",
|
185
|
+
LanguageEnum.EN: "user"
|
186
|
+
}
|
187
|
+
|
188
|
+
# Mapping of datetime terms from natural language to standardized keys for each supported language
|
189
|
+
DATATIME_KEY_MAP = {
|
190
|
+
LanguageEnum.CN: {
|
191
|
+
"年": "year",
|
192
|
+
"月": "month",
|
193
|
+
"日": "day",
|
194
|
+
"周": "week",
|
195
|
+
"星期几": "weekday",
|
196
|
+
},
|
197
|
+
LanguageEnum.EN: {
|
198
|
+
"Year": "year",
|
199
|
+
"Month": "month",
|
200
|
+
"Day": "day",
|
201
|
+
"Week": "week",
|
202
|
+
"Weekday": "weekday",
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
# Phrase for indicating inferred time in different languages
|
207
|
+
TIME_INFER_WORD = {
|
208
|
+
LanguageEnum.CN: "推断时间",
|
209
|
+
LanguageEnum.EN: "Inference time"
|
210
|
+
}
|
211
|
+
|
212
|
+
USER_NAME_EXPRESSION = {
|
213
|
+
LanguageEnum.CN: "用户姓名是{name}。",
|
214
|
+
LanguageEnum.EN: "User's name is {name}."
|
215
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
from .simple_react_op import SimpleReactOp
|
@@ -0,0 +1,21 @@
|
|
1
|
+
from flowllm import C
|
2
|
+
from flowllm.context.flow_context import FlowContext
|
3
|
+
from flowllm.op.agent.react_v2_op import ReactV2Op
|
4
|
+
|
5
|
+
|
6
|
+
@C.register_op()
|
7
|
+
class SimpleReactOp(ReactV2Op):
|
8
|
+
...
|
9
|
+
|
10
|
+
|
11
|
+
if __name__ == "__main__":
|
12
|
+
from reme_ai.config.config_parser import ConfigParser
|
13
|
+
|
14
|
+
C.set_default_service_config(parser=ConfigParser).init_by_service_config()
|
15
|
+
context = FlowContext(query="茅台和五粮现在股价多少?")
|
16
|
+
|
17
|
+
op = SimpleReactOp()
|
18
|
+
op(context=context)
|
19
|
+
# from reme_ai.schema import Message
|
20
|
+
# result = op.llm.chat(messages=[Message(**{"role": "user", "content": "你叫什么名字?"})])
|
21
|
+
# print("!!!", result)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from .extract_time_op import ExtractTimeOp
|
2
|
+
from .fuse_rerank_op import FuseRerankOp
|
3
|
+
from .print_memory_op import PrintMemoryOp
|
4
|
+
from .read_message_op import ReadMessageOp
|
5
|
+
from .retrieve_memory_op import RetrieveMemoryOp
|
6
|
+
from .semantic_rank_op import SemanticRankOp
|
7
|
+
from .set_query_op import SetQueryOp
|
8
|
+
|
9
|
+
__all__ = [
|
10
|
+
"ExtractTimeOp",
|
11
|
+
"FuseRerankOp",
|
12
|
+
"PrintMemoryOp",
|
13
|
+
"ReadMessageOp",
|
14
|
+
"RetrieveMemoryOp",
|
15
|
+
"SemanticRankOp",
|
16
|
+
"SetQueryOp"
|
17
|
+
]
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import re
|
2
|
+
from typing import Dict
|
3
|
+
|
4
|
+
from flowllm import C, BaseLLMOp
|
5
|
+
from flowllm.enumeration.role import Role
|
6
|
+
from flowllm.schema.message import Message
|
7
|
+
from loguru import logger
|
8
|
+
|
9
|
+
from reme_ai.constants.common_constants import QUERY_WITH_TS, EXTRACT_TIME_DICT
|
10
|
+
from reme_ai.constants.language_constants import DATATIME_KEY_MAP
|
11
|
+
from reme_ai.utils.datetime_handler import DatetimeHandler
|
12
|
+
|
13
|
+
|
14
|
+
@C.register_op()
|
15
|
+
class ExtractTimeOp(BaseLLMOp):
|
16
|
+
file_path: str = __file__
|
17
|
+
EXTRACT_TIME_PATTERN = r"-\s*(\S+)[::]\s*(\S+)"
|
18
|
+
|
19
|
+
"""
|
20
|
+
A specialized worker class designed to identify and extract time-related information
|
21
|
+
from text generated by an LLM, translating date-time keywords based on the set language,
|
22
|
+
and storing this extracted data within a shared context.
|
23
|
+
"""
|
24
|
+
|
25
|
+
def get_language_value(self, value_dict: dict):
|
26
|
+
|
27
|
+
return value_dict.get(self.language, value_dict.get("en"))
|
28
|
+
|
29
|
+
def execute(self):
|
30
|
+
"""
|
31
|
+
Executes the primary logic of identifying and extracting time data from an LLM's response.
|
32
|
+
|
33
|
+
This method first checks if the input query contains any datetime keywords. If not, it logs and returns.
|
34
|
+
It then constructs a prompt with contextual information including formatted timestamps and calls the LLM.
|
35
|
+
The response is parsed for time-related data using regex, translated via a language-specific key map,
|
36
|
+
and the resulting time data is stored in the shared context.
|
37
|
+
"""
|
38
|
+
query, query_timestamp = self.context[QUERY_WITH_TS]
|
39
|
+
|
40
|
+
# Identify if the query contains datetime keywords
|
41
|
+
contain_datetime = DatetimeHandler.has_time_word(query, self.language)
|
42
|
+
if not contain_datetime:
|
43
|
+
logger.info(f"Query contains no datetime keywords: {contain_datetime}")
|
44
|
+
# Set empty time dict for downstream operations
|
45
|
+
self.context[EXTRACT_TIME_DICT] = {}
|
46
|
+
return
|
47
|
+
|
48
|
+
# Prepare the prompt with necessary contextual details
|
49
|
+
time_format = self.prompt_format(prompt_name="time_string_format")
|
50
|
+
query_time_str = DatetimeHandler(dt=query_timestamp).string_format(time_format, self.language)
|
51
|
+
|
52
|
+
# Create message with system and few-shot examples
|
53
|
+
system_prompt = self.prompt_format(prompt_name="extract_time_system")
|
54
|
+
few_shot = self.prompt_format(prompt_name="extract_time_few_shot")
|
55
|
+
user_prompt = self.prompt_format(prompt_name="extract_time_user_query",
|
56
|
+
query=query, query_time_str=query_time_str)
|
57
|
+
|
58
|
+
full_prompt = f"{system_prompt}\n\n{few_shot}\n\n{user_prompt}"
|
59
|
+
logger.info(f"Extracting time from query: {query[:100]}...")
|
60
|
+
|
61
|
+
# Invoke the LLM to generate a response
|
62
|
+
response = self.llm.chat([Message(role=Role.USER, content=full_prompt)])
|
63
|
+
|
64
|
+
# Handle empty or unsuccessful responses
|
65
|
+
if not response or not response.content:
|
66
|
+
logger.warning("LLM returned empty response for time extraction")
|
67
|
+
self.context[EXTRACT_TIME_DICT] = {}
|
68
|
+
return
|
69
|
+
|
70
|
+
response_text = response.content
|
71
|
+
|
72
|
+
# Extract and parse time information from the LLM's response
|
73
|
+
extract_time_dict = self._parse_time_from_response(response_text)
|
74
|
+
|
75
|
+
logger.info(f"Extracted time information: {extract_time_dict}")
|
76
|
+
self.context[EXTRACT_TIME_DICT] = extract_time_dict
|
77
|
+
|
78
|
+
def _parse_time_from_response(self, response_text: str) -> Dict[str, str]:
|
79
|
+
"""
|
80
|
+
Parse time information from LLM response using regex.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
response_text: Raw LLM response content
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
Dictionary of extracted time information
|
87
|
+
"""
|
88
|
+
extract_time_dict: Dict[str, str] = {}
|
89
|
+
matches = re.findall(self.EXTRACT_TIME_PATTERN, response_text)
|
90
|
+
key_map: dict = DATATIME_KEY_MAP[DatetimeHandler.language_transform]
|
91
|
+
|
92
|
+
for key, value in matches:
|
93
|
+
if key in key_map.keys():
|
94
|
+
extract_time_dict[key_map[key]] = value
|
95
|
+
|
96
|
+
logger.debug(f"Time extraction - Response: {response_text[:200]}... Matches: {matches}")
|
97
|
+
return extract_time_dict
|