-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpart_review.py
More file actions
217 lines (195 loc) · 12 KB
/
part_review.py
File metadata and controls
217 lines (195 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import os,json,re
from autogen import AssistantAgent,UserProxyAgent,register_function
import sys
from setenvrion import get_llm_config,template_dir,image_dir,layout_config,googleSearchKey,pdf_dir,workspace
from serpapi import GoogleSearch
from autogen.agentchat.contrib.multimodal_conversable_agent import MultimodalConversableAgent
from get_rag import get_all_rag
def check_layout(pdfname:str)->str:
'''
Filter out papers that do not meet the standard template
'''
templatestr=""
templatepath=template_dir
for filename in os.listdir(templatepath):
templatestr+=f"<img src=\"{templatepath}/{filename}\">.\n\t"
image_agent = MultimodalConversableAgent(
name="image-explainer",
#max_consecutive_auto_reply=10,
#system_message="""Reply "TERMINATE" in the end when everything is done.""",
llm_config=layout_config,
)
user_proxy =UserProxyAgent(
name="User_proxy",
system_message="A human admin.",
human_input_mode="NEVER", # Try between ALWAYS or NEVER
max_consecutive_auto_reply=0,
code_execution_config={
"use_docker": False
},
)
#sys.stdout=open(chatout_dir+"/chatout1","a+")
a=user_proxy.initiate_chat(
image_agent,
message=f"""
This is the standard template for papers.
{templatestr}
Please check if the template of the following paper meets the standards.
<img src="{image_dir}/{pdfname}.jpg">.
For whether a template is suitable, please pay attention to their layout and the relative positions of the title, author, and abstract.
At last just need to reply YES or NO.
""",
)
#sys.stdout=sys.__stdout__
flag=a.chat_history[-1]["content"]
return flag
def writeinfo(papername:str,score:str,comment:str,number:int)->str:
with open(workspace+f"/out/1_out_{number}.txt", mode='a+') as filename:#a+(append) w+(from top)
filename.write(papername)
filename.write('\n')
filename.write(score)
filename.write('\n')
filename.write(comment)
filename.write('\n')
filename.write('\n')
return "Write Excute Success"
def search_google_scholar(keyword:str)->str:
search = GoogleSearch({
"q":keyword,
"engine": "google_scholar",
"hl": "en",
"num":5,
#"tbm": "",
"api_key":googleSearchKey # https://serpapi.com/manage-api-key
})
result = search.get_dict()
#print(result)
return [item['snippet'] for item in result['organic_results']]
def review(number:int,pdf:list,retrieval_function):
'''
review the paper and record the conversation in chatout1
'''
assistant = AssistantAgent(
name="assistant",
llm_config=get_llm_config(),
system_message="You are a paper review AI assistant."
)
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
#max_consecutive_auto_reply=4,
code_execution_config=False,
llm_config=get_llm_config(),
#system_message="""Reply TERMINATE if the task has been solved at full satisfaction.
#Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""",
#function_map={f"answer_{i}": retrieval_functions[pdf[i]] for i in range(len(pdf))}
is_termination_msg=lambda msg: "{\"comment\":" in str(msg["content"]) or "**Paper:**" in str(msg["content"]),
)
#for i in range(len(pdf)):
register_function(
retrieval_function,
caller=assistant,
executor=user_proxy,
name="QuestionAnswer",
description=f"useful when you want to answer questions about the papers",
)
register_function(
check_layout,
caller=assistant,
executor=user_proxy,
name="layoutchecker",
description=f"useful when you want to check the layout of the paper",
)
'''register_function(
search_google_scholar,
caller=assistant,
executor=user_proxy,
name="search_google_scholar",
description="useful when need to see a paper's originality and innovation",
)'''
standards="""
The paper should have a strong research background and address an important question.
The paper should have a complete paper structure.
The paper should have a clear theme, analysis, and conclusion.
The content of the paper must be original to enhance the existing knowledge system in the given topic area.
Experiments, statistics, and other analyses must be conducted in accordance with high-tech standards and described in sufficient detail. Experiments, data, and analysis should be able to support the current conclusion.
If there is algorithm design, it is necessary to ensure that the algorithm is feasible and effective.
The conclusion must be clear, correct, reliable, and valuable.
The paper should have a certain contribution and driving effect on the given thematic area.
"""
message=rf"""
Assume you are a reviewer of a conference, your job is to review papers in {pdf} and give every paper a reasonable score.
To review the papers, you must finish this job step-by-step:
- Step 1:CHECK PAPER'S LAYOUT.
You should check the layout of the paper by calling layoutchecker function.
If the answer is "YES", then the paper's layout is qualified and the paper can proceed to the following steps.
If the answer is "NO", then the paper's layout is not qualified, and this paper does not need to proceed to the next evaluation steps. The score of this paper will be set to 0.00 and the comments will be left blank.
- Step 2:EVALUATE QUALIFIED PAPERS.
To find the paper related content, you are supposed to call the QuestionAnswer function.
You cannot ask vague questions. It is recommended that your questions based on each of the following standords.
To evaluate the qualified papers, you should check that if the paper meets each of the following standards one bye one:
{standards}
For the questions, you should not response "I don't know"!
At this time, you should provide the basis for your answer, that is, which content in this paper did you derive this answer from.
Pay attention to using uniform evaluation standards for the papers. In your questions, there must be the paper's name.
Here are the examples of your questions of paper named 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN':
"Does the paper 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' have a strong research background and address an important question?"
"Does the paper 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' have a complete paper structure?"
"Does the paper 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' have a clear theme, analysis, and conclusion?"
"Is the content of 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' original and does it enhance the existing knowledge system in the given topic area?"
"Does the paper 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' conduct experiments, statistics, and analyses in accordance with high-tech standards and describe them in sufficient detail?"
"Is the algorithm in 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' feasible and effective?"
"Does the paper 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' have a clear, correct, reliable, and valuable conclusion?"
"Does the paper 'FEKNN A Wi-Fi Indoor Localization Method Based on Feature Enhancement and KNN' have a certain contribution and driving effect on the given thematic area?"
- Step 3:COMPARE THE PAPERS.
You should compare the advantages and disadvantages of the papers and give a rank of these papers.
- Step 4:GENERATE REVIEW COMMENTS.
You must generate the review comments of the paper. The review comments of each paper should be personalized and pertinence and it should include the advantages and disadvantages of corresponding paper.
- Step 5:SCORE ALL PAPERS.
You must think step by step. Then decide a final score of the paper based on the responses of all tool calls and the comparison. (The maximum score is 100.00, which should be accurate to two decimal places.)
Note that the paper with disqualified layout should be given a score of 0.00.
- Step 6:EXPLAIN THE SCORES.
At the same time, you must explain why you give that score to the papers.
- Step 7:REPLY ALL PAPERS' INFORMATION.
After you explain the scores, you just need to reply the information of all paper in {pdf} in the template of the following examples and terminate the conversation.
Here is the template of one paper's information, you must follow this format to output the information:
**Paper:**\n<paper's name>\n**Comment:**\n<comment on paper>\n**Score:**\n<score of paper>\n
Start the work now.
"""
sys.stdout=open(workspace+f"/chat/1_chat_{number}","a+")
a=user_proxy.initiate_chat(assistant,message=message,max_turns=30)
sys.stdout=sys.__stdout__
s=""
for i in range(-1,-5,-1):
if "**Paper:**" in a.chat_history[i]['content']:
s=a.chat_history[i]['content']
break
pattern=r'\*\*Paper:\*\*\s*(.*?)\n\*\*Comment:\*\*\s*(.*?)\n\*\*Score:\*\*\s*([0-9.]+)'
paper_sections = re.findall(pattern, s)
if len(paper_sections)<len(pdf):
return False
for element in paper_sections:
writeinfo(element[0].replace(':','').replace('\n','').replace('*','').rstrip(),element[2],element[1].replace('\n',''),number)
return True
def testfunc():
get_llm_config()
pdfs=[]
pdfs_path=pdf_dir
for filename in os.listdir(pdfs_path):#read all pdf names
if filename.endswith('.pdf'):
new_filename,_ = os.path.splitext(filename)
pdfs.append(new_filename)
retrieval_function=get_all_rag(pdfs[0:5])
review(pdfs[0:5],retrieval_function)
'''d={'content': '{"comment": "This paper introduces a framework utilizing deep learning techniques to enhance data quality in mobile crowd sensing. It presents innovative solutions to current gaps related to data reliability, although specific details regarding the completeness of the paper structure and high-tech standards for experiments are lacking. The results are promising but require comprehensive validation. The conclusion presented is relevant, but its overall reliability needs further evaluation.", "papername": "A Data Aggregation Framework based on Deep Learning for Mobile Crowd-sensing Paradigm", "score": "78.00"}\n{"comment": "This paper effectively addresses the pressing issue of blockchain integration through two distinct methodologies. It provides a strong structure and clear analysis, successfully demonstrating the proposed solutions\' potential impact on blockchain interoperability. While the conclusion is valuable, further empirical validation would enhance its credibility. The contributions are significant and offer promising directions for future research in this thematic area.", "papername": "A Novel Merging Framework for Homogeneous and Heterogeneous Blockchain Systems", "score": "85.00"}\n{"comment": "This paper proposes a novel approach to enhance physical layer security in mobile communication via cooperative jamming. While it provides significant contributions to the field and addresses key challenges, some details regarding the comprehensiveness of experimental validation were not assessed. Nevertheless, the conclusions drawn about the scheme\'s effectiveness are insightful and indicate a strong potential for future developments in secure transmission.", "papername": "An Effective Cooperative Jamming-based Secure Transmission Scheme for a Mobile Scenario", "score": "82.00"}', 'role': 'assistant'}
ss=d["content"]
pdfs=ss.split("\n")
print(pdfs)
dd1=json.loads(pdfs[0])
dd2=json.loads(pdfs[1])
dd3=json.loads(pdfs[2])
print(dd1['comment'])
print(dd1['score'])
print(dd1['papername'])'''
#testfunc()
#is terminate msg[content]={"comment"