diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..0548357
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..67b4c1d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/民航NLP.iml b/.idea/民航NLP.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/民航NLP.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/EE-eng.jpg b/examples/EE-eng.jpg
new file mode 100644
index 0000000..789205c
Binary files /dev/null and b/examples/EE-eng.jpg differ
diff --git a/examples/EE-zh.jpg b/examples/EE-zh.jpg
new file mode 100644
index 0000000..12d8965
Binary files /dev/null and b/examples/EE-zh.jpg differ
diff --git a/examples/NER-eng.jpg b/examples/NER-eng.jpg
new file mode 100644
index 0000000..52e6f8c
Binary files /dev/null and b/examples/NER-eng.jpg differ
diff --git a/examples/NER-zh.jpg b/examples/NER-zh.jpg
new file mode 100644
index 0000000..bf9635e
Binary files /dev/null and b/examples/NER-zh.jpg differ
diff --git a/examples/RE-eng.jpg b/examples/RE-eng.jpg
new file mode 100644
index 0000000..93015df
Binary files /dev/null and b/examples/RE-eng.jpg differ
diff --git a/examples/RE-zh.jpg b/examples/RE-zh.jpg
new file mode 100644
index 0000000..ee3f4c2
Binary files /dev/null and b/examples/RE-zh.jpg differ
diff --git a/examples/readme.md b/examples/readme.md
new file mode 100644
index 0000000..f158fc0
--- /dev/null
+++ b/examples/readme.md
@@ -0,0 +1 @@
+# some run examples
diff --git a/moxun b/moxun
new file mode 160000
index 0000000..cd0bdc0
--- /dev/null
+++ b/moxun
@@ -0,0 +1 @@
+Subproject commit cd0bdc08708d2d7cd7f278abf44801bb431d739f
diff --git a/public/favicon.ico b/public/favicon.ico
new file mode 100644
index 0000000..9941ace
Binary files /dev/null and b/public/favicon.ico differ
diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..8ba0672
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 基于有噪声民航数据的NLP处理系统
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/logo192.png b/public/logo192.png
new file mode 100644
index 0000000..9941ace
Binary files /dev/null and b/public/logo192.png differ
diff --git a/public/logo512.png b/public/logo512.png
new file mode 100644
index 0000000..9941ace
Binary files /dev/null and b/public/logo512.png differ
diff --git a/public/manifest.json b/public/manifest.json
new file mode 100644
index 0000000..2d130cd
--- /dev/null
+++ b/public/manifest.json
@@ -0,0 +1,25 @@
+{
+ "short_name": "GPT4IE",
+ "name": "GPT4IE",
+ "icons": [
+ {
+ "src": "favicon.ico",
+ "sizes": "64x64 32x32 24x24 16x16",
+ "type": "image/x-icon"
+ },
+ {
+ "src": "logo192.png",
+ "type": "image/png",
+ "sizes": "192x192"
+ },
+ {
+ "src": "logo512.png",
+ "type": "image/png",
+ "sizes": "512x512"
+ }
+ ],
+ "start_url": ".",
+ "display": "standalone",
+ "theme_color": "#000000",
+ "background_color": "#ffffff"
+}
\ No newline at end of file
diff --git a/public/prompts/EE-chi.prompt b/public/prompts/EE-chi.prompt
new file mode 100644
index 0000000..092d9af
--- /dev/null
+++ b/public/prompts/EE-chi.prompt
@@ -0,0 +1,4 @@
+已知事件类型和论元角色列表的对应关系如下:$prompt1
+
+给定一句话:"$prompt", 请提取出这句话的事件论元,并以字典的形式回答,字典的形式为:{事件类型: {论元角色: 论元内容}}。直接给出答案即可。如果没有论元角色没有相应的论元内容,论元内容回答:无。
+
diff --git a/public/prompts/EE-eng.prompt b/public/prompts/EE-eng.prompt
new file mode 100644
index 0000000..2a4faae
--- /dev/null
+++ b/public/prompts/EE-eng.prompt
@@ -0,0 +1,3 @@
+The correspondence between known event types and argument role lists is as follows: $prompt1
+
+Give a sentence:"$prompt", Please extract the event argument or arguments of this sentence, and answer it or them in the form of a dictionary. The dictionary is in the form of: {event type: {argument role: argument content}}. Just give the answer. If the argument role does not have the corresponding argument content, the argument content answers: None.
\ No newline at end of file
diff --git a/public/prompts/NER-chi.prompt b/public/prompts/NER-chi.prompt
new file mode 100644
index 0000000..86485b2
--- /dev/null
+++ b/public/prompts/NER-chi.prompt
@@ -0,0 +1,5 @@
+已知实体类型列表:$prompt1。
+
+给定一个句子:"$prompt"
+
+在给定的句子中可能包含哪些实体,请按照形式 (实体类型, 实体内容) 回答:
\ No newline at end of file
diff --git a/public/prompts/NER-eng.prompt b/public/prompts/NER-eng.prompt
new file mode 100644
index 0000000..cc5997c
--- /dev/null
+++ b/public/prompts/NER-eng.prompt
@@ -0,0 +1,5 @@
+List of known entity types: $prompt1.
+
+Given a sentence: "$prompt"
+
+Which entities may be included in a given sentence, please answer in the form (entity type, entity content):
\ No newline at end of file
diff --git a/public/prompts/RE-chi.prompt b/public/prompts/RE-chi.prompt
new file mode 100644
index 0000000..1e731c9
--- /dev/null
+++ b/public/prompts/RE-chi.prompt
@@ -0,0 +1,11 @@
+假设你是一个实体关系三元组抽取模型。我会给你头实体类型列表subject_types,尾实体类型列表object_types,关系列表relations,再给你一个句子,请你根据这三个列表抽出句子中的subject和object,并组成三元组,且形式为(subject, relation, object)。
+
+给定的句子为:"$prompt"
+
+relations:$prompt1
+
+subject_types:$prompt2
+
+object_types:$prompt3
+
+在给定的句子中,可能包含了哪些三元组?请按照形式(subject, relation, object)回答:
\ No newline at end of file
diff --git a/public/prompts/RE-eng.prompt b/public/prompts/RE-eng.prompt
new file mode 100644
index 0000000..dd35c30
--- /dev/null
+++ b/public/prompts/RE-eng.prompt
@@ -0,0 +1,11 @@
+Suppose you are an entity-relationship triple extraction model. I'll give you list of head entity types: subject_types, list of tail entity types: object_types, list of relations: relations. Give you a sentence, please extract the subject and object in the sentence based on these three lists, and form a triplet in the form of (subject, relation, object).
+
+The given sentence is "$prompt".
+
+relations: $prompt1
+
+subject_types: $prompt2
+
+object_types: $prompt3
+
+In the given sentence, what triples might be contained? Please answer in the form (subject, relation, object):
\ No newline at end of file
diff --git a/public/prompts/temp.txt b/public/prompts/temp.txt
new file mode 100644
index 0000000..63814b2
--- /dev/null
+++ b/public/prompts/temp.txt
@@ -0,0 +1,38 @@
+The aid group Doctors Without Borders said that since Saturday , more than 275 wounded people had been admitted and treated at Donka Hospital in the capital of Guinea , Conakry .
+
+['location-located_in', 'administrative_division-country', 'person-place_lived', 'person-company', 'person-nationality', 'company-founders', 'country-administrative_divisions', 'person-children', 'country-capital', 'deceased_person-place_of_death', 'neighborhood-neighborhood_of', 'person-place_of_birth']
+
+['organization', 'person', 'location', 'country']
+
+['person', 'location', 'country', 'organization', 'city']
+
+_____________________________________________________
+
+
+第五部:《如懿传》《如懿传》是一部古装宫廷情感电视剧,由汪俊执导,周迅、霍建华、张钧甯、董洁、辛芷蕾、童瑶、李纯、邬君梅等主演
+
+['所属专辑', '成立日期', '海拔', '官方语言', '占地面积', '父亲', '歌手', '制片人', '导演', '首都', '主演', '董事长', '祖籍', '妻子', '母亲', '气候', '面积', '主角', '邮政编码', '简称', '出品公司', '注册资本', '编剧', '创始人', '毕业院校', '国籍', '专业代码', '朝代', '作者', '作词', '所在城市', '嘉宾', '总部地点', '人口数量', '代言人', '改编自', '校长', '丈夫', '主持人', '主题曲', '修业年限', '作曲', '号', '上映时间', '票房', '饰演', '配音', '获奖']
+
+['国家', '行政区', '文学作品', '人物', '影视作品', '学校', '图书作品', '地点', '历史人物', '景点', '歌曲', '学科专业', '企业', '电视综艺', '机构', '企业/品牌', '娱乐人物']
+
+['国家', '人物', 'Text', 'Date', '地点', '气候', '城市', '歌曲', '企业', 'Number', '音乐专辑', '学校', '作品', '语言']
+_______________________________________________________
+比如本轮的比赛中就有,中甲榜首之争,再次惨败的西北狼回到主场能否止住颓势,闹剧频出的川足事态如何发展,永昌客场是否能迎来首胜。
+
+{'组织行为-罢工': ['时间', '所属组织', '罢工人数', '罢工人员'], '竞赛行为-晋级': ['时间', '晋级方', '晋级赛事'], '财经/交易-涨停':['时间', '涨停股票'] , '组织关系-解雇': ['时间', '解雇方', '被解雇人员']}
+_____________________________________________________
+He lost an election to a dead man.
+
+{'Personnel:Elect': ['Person', 'Entity', 'Position', 'Time', 'Place'], 'Business:Declare-Bankruptcy': ['Org', 'Time', 'Place'], 'Justice:Arrest-Jail': ['Person', 'Agent', 'Crime', 'Time', 'Place'], 'Life:Divorce': ['Person', 'Time', 'Place'], 'Life:Injure': ['Agent', 'Victim', 'Instrument', 'Time', 'Place']}
+————————————————————————————————————————————
+在过去的五年中,致公党在邓小平理论指引下,遵循社会主义初级阶段的基本路线,努力实践致公党十大提出的发挥参政党职能、加强自身建设的基本任务。
+
+['组织机构', '地点', '人物']
+
+_____________________________________________________
+Japan then laid siege to the Syrian penalty area and had a goal disallowed for offside in the 16th minute.
+
+['LOC', 'MISC', 'ORG', 'PER']
+
+_____________________________________________________
+"homepage": "https://cocacola-lab.github.io/GPT4IE",
\ No newline at end of file
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000..e9e57dc
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1,3 @@
+# https://www.robotstxt.org/robotstxt.html
+User-agent: *
+Disallow:
diff --git a/src/App.css b/src/App.css
new file mode 100644
index 0000000..317bd6a
--- /dev/null
+++ b/src/App.css
@@ -0,0 +1,210 @@
+@import url('https://fonts.googleapis.com/css2?family=Noticia+Text:wght@400;700&display=swap');
+
+.headerText {
+ font-family: 'Noticia Text';
+ font-weight: 900;
+ font-size: 60px;
+ text-align: center;
+ padding-top: 40px;
+}
+
+.subheaderText {
+ font-family: 'Noticia Text';
+ font-weight: 400;
+ font-size: 20px;
+ text-align: center;
+ width: 60%;
+ margin: 0 auto;
+}
+
+.subsubheaderText {
+ font-family: 'Noticia Text';
+ font-weight: 400;
+ font-size: 18px;
+ text-align: center;
+ width: 60%;
+ margin: 0 auto;
+}
+
+
+table{
+ font-family: 'Oswald', sans-serif;
+ border-collapse:collapse;
+ margin-left:auto;
+ margin-right:auto;
+ margin-top: 5px;
+}
+
+td{
+ background-color:#ffffff;
+ width:50%;
+ height:50px;
+ text-align:center;
+}
+
+tr{
+ border-bottom: 1px solid #dddddd;
+}
+
+tr:first-of-type{
+ border-top: 2px solid gray;
+}
+
+tr:last-of-type{
+ border-bottom: 2px solid gray;
+}
+
+
+.opensourceText {
+ font-family: 'Noticia Text';
+ font-weight: 400;
+ font-size: 14px;
+ text-align: center;
+ width: 60%;
+ margin: 10px auto;
+}
+
+.container {
+ padding-right: 15px;
+ padding-left: 15px;
+ margin-right: auto;
+ margin-left: auto;
+}
+
+@media (min-width: 768px) {
+ .container {
+ width: 750px;
+ }
+}
+
+@media (min-width: 992px) {
+ .container {
+ width: 970px;
+ }
+}
+
+@media (min-width: 1200px) {
+ .container {
+ width: 1170px;
+ }
+}
+
+.graphContainer {
+ width: 80%;
+ height: 80%;
+ background-color: rgb(255, 255, 255);
+ border-radius: 10px;
+ overflow: hidden;
+ border: 1px solid rgb(0, 0, 0);
+ box-shadow: 0 0 5px rgb(0 0 0 / 10%);
+ margin: 0 auto;
+ margin-bottom: 10px;
+}
+
+.ulC {
+ text-align: center
+}
+
+.footer {
+ font-family: 'Noticia Text';
+ font-weight: 400;
+ font-size: 13px;
+ text-align: center;
+ margin: 0 auto;
+ margin-bottom: 100px;
+}
+
+.inputContainer {
+ width: 60%;
+ margin: 0 auto;
+ margin-top: 50px;
+ margin-bottom: 50px;
+}
+
+.searchBar {
+ border: 1px solid rgb(0, 0, 0);
+ border-radius: 5px;
+ box-shadow: 0 0 5px rgb(0 0 0 / 10%);
+ display: block;
+ font-size: 16px;
+ height: 50px;
+ outline: none;
+ padding: 0 10px;
+ width: 90%;
+ margin-left: auto;
+ margin-right: auto;
+ margin-bottom: 20px;
+}
+
+.typeList {
+ border: 1px solid rgb(0, 0, 0);
+ border-radius: 5px;
+ box-shadow: 0 0 5px rgb(0 0 0 / 10%);
+ display: block;
+ font-size: 16px;
+ height: 50px;
+ outline: none;
+ padding: 0 10px;
+ width: 90%;
+ margin-left: auto;
+ margin-right: auto;
+ margin-bottom: 20px;
+}
+
+.apiKeyTextField {
+ border: 1px solid rgb(0, 0, 0);
+ border-radius: 5px;
+ box-shadow: 0 0 5px rgb(0 0 0 / 10%);
+ display: block;
+ font-size: 16px;
+ height: 50px;
+ outline: none;
+ padding: 0 10px;
+ width: 90%;
+ margin-left: auto;
+ margin-right: auto;
+ margin-bottom: 20px;
+}
+
+.generateButton {
+ background-color: rgb(0, 0, 0);
+ border: none;
+ border-radius: 5px;
+ color: rgb(255, 255, 255);
+ cursor: pointer;
+ font-size: 16px;
+ height: 50px;
+ outline: none;
+ width: 40%;
+ display: inline-block;
+ margin-right: 5px;
+}
+
+.generateButton:hover {
+ background-color: rgb(0, 0, 0, 0.8);
+}
+
+.generateButton:disabled {
+ background-color: rgb(0, 0, 0, 0.5);
+ cursor: wait;
+}
+
+.clearButton {
+ background-color: rgb(255, 255, 255);
+ border: 1px solid rgb(0, 0, 0);
+ border-radius: 5px;
+ color: rgb(0, 0, 0);
+ cursor: pointer;
+ font-size: 16px;
+ height: 50px;
+ outline: none;
+ width: 40%;
+ margin-left: auto;
+ margin-right: auto;
+ display: inline-block;
+ margin-left: 5px;
+}
+
+.clearButton:hover {
+ background-color: rgba(239, 239, 239, 0.8);
+}
\ No newline at end of file
diff --git a/src/App.js b/src/App.js
new file mode 100644
index 0000000..b61c75f
--- /dev/null
+++ b/src/App.js
@@ -0,0 +1,446 @@
+import './App.css';
+import React, { useState } from "react";
+
+const DEFAULT_PARAMS = {
+ "model": "text-davinci-003",
+ "temperature": 0,
+ "max_tokens": 256,
+ "top_p": 1,
+ "frequency_penalty": 0,
+ "presence_penalty": 0
+}
+
+//const SELECTED_PROMPT = "STATELESS"
+
+
+function App() {
+
+ const [structureState, setStructureState] = useState(
+ [] //[{subject: '七里香', relation: '歌手', object: '人物'}]
+ );
+
+ const clearState = () => {
+ setStructureState([])
+ };
+
+ const updateStructure = (update) =>{
+ //setStructureState([]); //清理状态值
+ //console.log(JSON.parse(JSON.stringify(structureState)));
+ var current_structure = JSON.parse(JSON.stringify(structureState));
+ if (update.length === 0) {
+ console.log("0 output")
+ return;
+ }
+
+ update.forEach(ut => {
+ current_structure.push(ut);
+ });
+ setStructureState(current_structure);
+ }
+
+ const queryREPrompt = (prompt, prompt1, prompt2, prompt3, apiKey) => {
+ console.log(lanState);
+ var file = '';
+ if (lanState.lanValue === 'english') {
+ file ='prompts/RE-eng.prompt'
+ } else {
+ file ='prompts/RE-chi.prompt'
+ };
+ console.log(file);
+
+ fetch(file)
+ .then(response => response.text()) //response转文本->
+ .then(curprompt => {
+ console.log(curprompt);
+ curprompt = curprompt.replace("$prompt", prompt);
+ if(prompt1.length === 0){
+ console.log("default relation type list");
+ if (lanState.lanValue === 'english') {
+ curprompt = curprompt.replace("$prompt1", "['location-located_in', 'administrative_division-country', 'person-place_lived', 'person-company', 'person-nationality', 'company-founders', 'country-administrative_divisions', 'person-children', 'country-capital', 'deceased_person-place_of_death', 'neighborhood-neighborhood_of', 'person-place_of_birth']");
+ } else {
+ curprompt = curprompt.replace("$prompt1", "['所属专辑', '成立日期', '海拔', '官方语言', '占地面积', '父亲', '歌手', '制片人', '导演', '首都', '主演', '董事长', '祖籍', '妻子', '母亲', '气候', '面积', '主角', '邮政编码', '简称', '出品公司', '注册资本', '编剧', '创始人', '毕业院校', '国籍', '专业代码', '朝代', '作者', '作词', '所在城市', '嘉宾', '总部地点', '人口数量', '代言人', '改编自', '校长', '丈夫', '主持人', '主题曲', '修业年限', '作曲', '号', '上映时间', '票房', '饰演', '配音', '获奖']");
+ };
+ } else{
+ curprompt = curprompt.replace("$prompt1", prompt1);
+ }
+
+ if(prompt2.length === 0){
+ console.log("default subject type list");
+ if (lanState.lanValue === 'english') {
+ curprompt = curprompt.replace("$prompt2", "['organization', 'person', 'location', 'country']");
+ } else {
+ curprompt = curprompt.replace("$prompt2", "['国家', '行政区', '文学作品', '人物', '影视作品', '学校', '图书作品', '地点', '历史人物', '景点', '歌曲', '学科专业', '企业', '电视综艺', '机构', '企业/品牌', '娱乐人物']");
+ };
+ } else{
+ curprompt = curprompt.replace("$prompt2", prompt1);
+ }
+
+ if(prompt3.length === 0){
+ console.log("default object type list");
+ if (lanState.lanValue === 'english') {
+ curprompt = curprompt.replace("$prompt3", "['person', 'location', 'country', 'organization', 'city']");
+ } else {
+ curprompt = curprompt.replace("$prompt3", "['国家', '人物', 'Text', 'Date', '地点', '气候', '城市', '歌曲', '企业', 'Number', '音乐专辑', '学校', '作品', '语言']");
+ };
+ } else{
+ curprompt = curprompt.replace("$prompt3", prompt1);
+ }
+
+ console.log(curprompt);
+ const params = { ...DEFAULT_PARAMS, prompt: curprompt };
+
+ const requestOptions = {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + String(apiKey)
+ },
+ body: JSON.stringify(params)
+ };
+ fetch('https://api.openai.com/v1/completions', requestOptions)
+ .then(response => {
+ if (!response.ok) {
+ switch (response.status) {
+ case 401: // 401: Unauthorized: API key is wrong
+ throw new Error('Please double-check your API key.');
+ case 429: // 429: Too Many Requests: Need to pay
+ throw new Error('You exceeded your current quota, please check your plan and billing details.');
+ default:
+ throw new Error('Something went wrong with the request, please check the Network log');
+ }
+ }
+ //console.log(response)
+ return response.json();
+ })
+ .then((response) => {
+ const { choices } = response;
+ //console.log(choices)
+ const text = choices[0].text;
+ console.log(text);
+
+ //const updates = JSON.parse(text);
+ //console.log(updates);
+
+ //updateGraph(updates);
+ const reg = /\(.*?\)/g; //g表示全局搜索,会进行多次match
+ var update = text.match(reg);
+ if(! update){
+ update = [text];
+ }
+ console.log(update);
+ console.log(update[0])
+ updateStructure(update);
+
+ //document.getElementsByClassName("searchBar")[0].value = "";
+ //document.getElementsByClassName("typeList")[0].value = "";
+ document.body.style.cursor = 'default';
+ document.getElementsByClassName("generateButton")[0].disabled = false;
+ }).catch((error) => {
+ console.log(error);
+ alert(error);
+ document.body.style.cursor = 'default';
+ document.getElementsByClassName("generateButton")[0].disabled = false; //出错则释放,为了能再次使用
+ });
+ })
+ };
+
+ const queryNERPrompt = (prompt, prompt1, prompt2, prompt3, apiKey) => {
+ console.log(lanState);
+ var file = '';
+ if (lanState.lanValue === 'english') {
+ file ='prompts/NER-eng.prompt'
+ } else {
+ file ='prompts/NER-chi.prompt'
+ };
+ console.log(file);
+
+ fetch(file)
+ .then(response => response.text()) //response转文本-> curprompt
+ .then(curprompt => {
+ console.log(curprompt);
+ if(prompt1.length === 0){
+ console.log("default ner type list");
+ if (lanState.lanValue === 'english') {
+ curprompt = curprompt.replace("$prompt1", "['LOC', 'MISC', 'ORG', 'PER']");
+ } else {
+ curprompt = curprompt.replace("$prompt1", "['组织机构', '地点', '人物']");
+ };
+ } else{
+ curprompt = curprompt.replace("$prompt1", prompt1);
+ }
+
+ curprompt = curprompt.replace("$prompt", prompt);
+ console.log(curprompt);
+ const params = { ...DEFAULT_PARAMS, prompt: curprompt };
+
+ const requestOptions = {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + String(apiKey)
+ },
+ body: JSON.stringify(params)
+ };
+ fetch('https://api.openai.com/v1/completions', requestOptions)
+ .then(response => {
+ if (!response.ok) {
+ switch (response.status) {
+ case 401: // 401: Unauthorized: API key is wrong
+ throw new Error('Please double-check your API key.');
+ case 429: // 429: Too Many Requests: Need to pay
+ throw new Error('You exceeded your current quota, please check your plan and billing details.');
+ default:
+ throw new Error('Something went wrong with the request, please check the Network log');
+ }
+ }
+ //console.log(response)
+ return response.json();
+ })
+ .then((response) => {
+ const { choices } = response;
+ //console.log(choices)
+ const text = choices[0].text;
+ console.log(text);
+
+ //const updates = JSON.parse(text);
+ //console.log(updates);
+
+ //updateGraph(updates);
+ const reg = /\(.*?\)/g; //g表示全局搜索,会进行多次match
+ var update = text.match(reg);
+ if(! update){
+ update = [text];
+ }
+ console.log(update);
+ console.log(update[0])
+ updateStructure(update);
+
+ //document.getElementsByClassName("searchBar")[0].value = "";
+ //document.getElementsByClassName("typeList")[0].value = "";
+ document.body.style.cursor = 'default';
+ document.getElementsByClassName("generateButton")[0].disabled = false;
+ }).catch((error) => {
+ console.log(error);
+ alert(error);
+ document.body.style.cursor = 'default';
+ document.getElementsByClassName("generateButton")[0].disabled = false; //出错则释放,为了能再次使用
+ });
+ })
+ };
+
+ const queryEEPrompt = (prompt, prompt1, prompt2, prompt3, apiKey) => {
+ console.log(lanState);
+ var file = '';
+ if (lanState.lanValue === 'english') {
+ file ='prompts/EE-eng.prompt'
+ } else {
+ file ='prompts/EE-chi.prompt'
+ };
+ console.log(file);
+
+ fetch(file)
+ .then(response => response.text()) //response转文本-> curprompt
+ .then(curprompt => {
+ console.log(curprompt);
+ if(prompt1.length === 0){
+ console.log("default event type list");
+ if (lanState.lanValue === 'english') {
+ curprompt = curprompt.replace("$prompt1", "{'Personnel:Elect': ['Person', 'Entity', 'Position', 'Time', 'Place'], 'Business:Declare-Bankruptcy': ['Org', 'Time', 'Place'], 'Justice:Arrest-Jail': ['Person', 'Agent', 'Crime', 'Time', 'Place'], 'Life:Divorce': ['Person', 'Time', 'Place'], 'Life:Injure': ['Agent', 'Victim', 'Instrument', 'Time', 'Place']}");
+ } else {
+ curprompt = curprompt.replace("$prompt1", "{'组织行为-罢工': ['时间', '所属组织', '罢工人数', '罢工人员'], '竞赛行为-晋级': ['时间', '晋级方', '晋级赛事'], '财经/交易-涨停':['时间', '涨停股票'] , '组织关系-解雇': ['时间', '解雇方', '被解雇人员']}");
+ };
+ } else{
+ curprompt = curprompt.replace("$prompt1", prompt1);
+ }
+
+ curprompt = curprompt.replace("$prompt", prompt);
+ console.log(curprompt);
+ const params = { ...DEFAULT_PARAMS, prompt: curprompt };
+ const requestOptions = {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + String(apiKey)
+ },
+ body: JSON.stringify(params)
+ };
+ fetch('https://api.openai.com/v1/completions', requestOptions)
+ .then(response => {
+ if (!response.ok) {
+ switch (response.status) {
+ case 401: // 401: Unauthorized: API key is wrong
+ throw new Error('Please double-check your API key.');
+ case 429: // 429: Too Many Requests: Need to pay
+ throw new Error('You exceeded your current quota, please check your plan and billing details.');
+ default:
+ throw new Error('Something went wrong with the request, please check the Network log');
+ }
+ }
+ //console.log(response)
+ return response.json();
+ })
+ .then((response) => {
+ const { choices } = response;
+ //console.log(choices)
+ const text = choices[0].text;
+ console.log(text);
+
+ //const updates = JSON.parse(text);
+ //console.log(updates);
+
+ //updateGraph(updates);
+ const reg = /[^,{]+?:[\x20]*\{.*?\}/g; //g表示全局搜索,会进行多次match
+ var update = text.match(reg);
+ if(! update){
+ update = [text];
+ }
+ console.log(update);
+ console.log(update[0])
+ updateStructure(update);
+
+ //document.getElementsByClassName("searchBar")[0].value = "";
+ //document.getElementsByClassName("typeList")[0].value = "";
+ document.body.style.cursor = 'default';
+ document.getElementsByClassName("generateButton")[0].disabled = false;
+ }).catch((error) => {
+ console.log(error);
+ alert(error);
+ document.body.style.cursor = 'default';
+ document.getElementsByClassName("generateButton")[0].disabled = false; //出错则释放,为了能再次使用
+ });
+ })
+ };
+
+ const queryPrompt = (prompt, prompt1, prompt2, prompt3, apiKey) => {
+ console.log(taskState.taskValue);
+ if (taskState.taskValue === 'RE') {
+ queryREPrompt(prompt, prompt1, prompt2, prompt3, apiKey);
+ } else if (taskState.taskValue === 'NER') {
+ queryNERPrompt(prompt, prompt1, prompt2, prompt3, apiKey);
+ } else if (taskState.taskValue === 'EE') {
+ queryEEPrompt(prompt, prompt1, prompt2, prompt3, apiKey);
+ } else {
+ alert("Please select a task");
+ document.body.style.cursor = 'default';
+ document.getElementsByClassName("generateButton")[0].disabled = false;
+ }
+ }
+
+
+ const createIE = () => {
+ document.body.style.cursor = 'wait';
+
+ document.getElementsByClassName("generateButton")[0].disabled = true;
+ const prompt = document.getElementsByClassName("searchBar")[0].value;
+ const prompt1 = document.getElementById("prompt1").value;
+ const prompt2 = document.getElementById("prompt2").value;
+ const prompt3 = document.getElementById("prompt3").value;
+ var apiKey = document.getElementsByClassName("apiKeyTextField")[0].value;
+ //console.log(apiKey);
+ if (apiKey.length === 0){
+ console.log("default open AI key");
+ const temp_k = "@WITy9ios86qOmgLcFT3BlbkFJi68ofPwe9IVifL3NYgZ5";
+ apiKey = "sk-nd9" + temp_k.substring(1);
+ //console.log(apiKey);
+ }
+
+ queryPrompt(prompt, prompt1, prompt2, prompt3, apiKey);
+ }
+
+ const lists = structureState.map((triplet) =>
+ {triplet}
+ );
+
+ // 语言选项
+ const [lanState, setLanState] = useState(
+ {lanValue: "english"}
+ );
+
+ const handleChange = (event) => {
+ console.log(event);
+ console.log(event.target.value);
+ //setLanState({lanValue: event.target.value},
+ // () => {console.log(lanState)});
+ setLanState({lanValue: event.target.value}); // 坑:set状态后,lanState值不会立即改变,因为react是渲染周期结束后才更新值。
+ };
+
+ // 任务选项
+ const [taskState, setTaskState] = useState(
+ {taskValue: "NER"}
+ );
+
+ const handleChange2 = (event) => {
+ console.log(event);
+ console.log(event.target.value);
+ //setLanState({lanValue: event.target.value},
+ // () => {console.log(lanState)});
+ setTaskState({taskValue: event.target.value});
+ };
+
+ //