105复杂句:Convinced that the grounds were haunted, they decided to publish their findings in a book An Adventure (1911), under the pseudonyms of Elizabeth Morison and Frances Lamont.
简化句1:They believed the grounds were haunted. They decided to publish their findings in a book. They used the names of Elizabeth Morison and Frances Lamont.
简化句2:Convinced that the grounds were haunted, they decided to publish what they found in a book called An Adventure. They used the names Elizabeth Morison and Frances Lamont.
简化句3:Convinced that the grounds were haunted, they decided to publish their findings in a book called An Adventure (1911). They used the names Elizabeth Morison and Frances Lamont.
句1得分:流畅性[];简洁性[];充分性[]
句2得分:流畅性[];简洁性[];充分性[]
句3得分:流畅性[];简洁性[];充分性[]
fromtimeimportsleepimportopenaiimportjson# 填你的秘钥openai.api_key="sk-xxxxxx"# 一些元数据aspects=['Conciseness','Fluency','Sufficiency']students=['A','B','C']# 提问代码defchat_gpt(prompt)->str:# 你的问题# 老版本调用写法,不支持调用gpt-3.5-turbo# # 调用 ChatGPT 接口# model_engine = "text-davinci-003"# # model_engine = "gpt-3.5-turbo"# completion = openai.Completion.create(# engine=model_engine,# prompt=prompt,# max_tokens=1024,# n=1,# stop=None,# temperature=0.5,# )## response = completion.choices[0].text# return response# Call the OpenAI API to generate a responseresponse=openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{'role':'user','content':prompt}],max_tokens=1024,n=1,temperature=0.5,top_p=1,frequency_penalty=0.0,presence_penalty=0.6,)# Get the response text from the API responseresponse_text=response['choices'][0]['message']['content']# OPENAI自己做了流控,具体看官网sleep(21)returnresponse_textresult_tmplate=f'句1得分:流畅性[];简洁性[];充分性[]'no_need='[]'if__name__=='__main__':separator=':'# read filefr=open("formatted_sentences_100_250.txt","r")fo=open("formatted_sentences_result_100-250.txt","w+")sentences=[]cnt=0max_cnt=400forlineinfr:ifcnt>max_cnt:breakifline.find(separator)==-1orline.find(no_need)!=-1:continuesentence=line.split(separator)[1]sentences.append(sentence)fo.write(line)iflen(sentences)==4:# 处理结果promt=(f'From now on you are a teacher who is responsible for grading students("A", "B", "C") on the simplified results of the original sentences you propose out on a scale of 5. 'f'From the following three aspects: {aspects[0]}, {aspects[1]}, {aspects[2]}''Here is a example:'f'original:{sentence[0]}'f'"A":{sentence[1]}'f'"B":{sentence[2]}'f'"C":{sentence[3]}'f"Evaluate the score for students(\"A\", \"B\", \"C\") with the above three aspects('{aspects[0]}', '{aspects[1]}', '{aspects[2]}').""Your answer can only and just be returned in pure JSON format that can be serialized into dict format in Python.")gpt=chat_gpt(promt).replace('Answer:','')load=dict(json.loads(gpt))tmp_load={}flag=False# 修正数据,可能格式不是想要的A:..而是Conciseness:‘A’forkey,valueinload.items():iflen(key)>1:flag=Truefork,vinvalue.items():ifknotintmp_load.keys():tmp_load[k]={}tmp_load[k][key]=vifflag:load=tmp_loadforidx,studentinenumerate(students):scores=[]rating=load.get(student)foraspectinaspects:fork,vinrating.items():ifk.lower().count(aspect.lower())!=0:scores.append(v)breakresult_template=f'句{idx+1}得分:流畅性[{scores[0]}];简洁性[{scores[1]}];充分性[{scores[2]}]\n'ifidx==len(students)-1:result_template+='\n'fo.write(result_template)cnt+=1sentences=[]print(f'cur group at = {cnt}')ifcnt>=max_cnt:breakfo.close()fr.close()print(f'done, {cnt} sentences group is processed.')