shaocongma commited on
Commit
c731c18
1 Parent(s): 9476105
Files changed (3) hide show
  1. auto_backgrounds.py +1 -1
  2. chat.py +74 -64
  3. utils/gpt_interaction.py +1 -1
auto_backgrounds.py CHANGED
@@ -68,7 +68,7 @@ def _generation_setup(title, description="", template="ICLR2022",
68
  # print("Generation setup...")
69
  # paper = {}
70
  # paper_body = {}
71
- llm = GPTModel()
72
 
73
  # Create a copy in the outputs folder.
74
  bibtex_path, destination_folder = copy_templates(template, title)
 
68
  # print("Generation setup...")
69
  # paper = {}
70
  # paper_body = {}
71
+ llm = GPTModel(model="gpt-3.5-turbo")
72
 
73
  # Create a copy in the outputs folder.
74
  bibtex_path, destination_folder = copy_templates(template, title)
chat.py CHANGED
@@ -7,29 +7,62 @@ from utils.prompts import SYSTEM
7
 
8
  openai_key = os.getenv("OPENAI_API_KEY")
9
  default_model = os.getenv("DEFAULT_MODEL")
10
- openai.api_key = openai_key
 
11
 
12
- contribution_system_prompt_1 = '''You are an assistant designed to propose potential contributions of a given title of the paper. Ensure follow the following instructions:
13
- Instruction:
14
- - Your response should follow the JSON format.
15
- - Your response should have the following structure: {"contribution1": {"statement": "briefly describe what the contribution is", "reason": "reason why this contribution has not been made by other literatures"}, "contribution2": {"statement": "briefly describe what the contribution is", "reason": "reason why this contribution has not been made by other literatures"}, ...}'''
16
 
17
- contribution_system_prompt_2 = '''You are an assistant designed to criticize the contributions of a paper. You will be provided Paper's Title, References and Contributions. Ensure follow the following instructions:
 
18
  Instruction:
19
  - Your response should follow the JSON format.
20
  - Your response should have the following structure:
21
- {"contribution1": {"statement": "briefly describe what the contribution is", "reason": "reason why this becomes a contribution from the user", "think":"your thought about if this is a novel contribution", "criticism": "reason why this can or cannot be a novel contribution"},
22
- "contribution2": {"statement": "briefly describe what the contribution is", "reason": "reason why this becomes a contribution from the user", "think":"your thought about if this is a novel contribution", "criticism": "reason why this can or cannot be a novel contribution"}, ...}
23
- - You need to carefully check if the claimed contribution has been made in the provided references, which makes the contribution not novel.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  '''
25
 
26
- suggestions_system_prompt = '''You are an assistant designed to help improve the novelty of a paper. You will be provided Paper's Title, References, Criticism, and Contributions. Ensure follow the following instructions:
 
27
  Instruction:
28
  - Your response should follow the JSON format.
29
  - Your response should have the following structure:
30
- {"title": {"suggestion": "your suggestion on the title", "new title": "your suggested title based on your suggestion", "reason": "your reason why you want to make such modification based on the references and criticism"},
31
- "contributions": {"new contribution 1": {"statement": "your proposed new contribution", "reason": "why this is a novel contribution"}, "new contribution 2": {"statement": "your proposed new contribution", "reason": "why this is a novel contribution"}, ...}}
32
- - Your reason should be based on the references and solve the criticism.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  '''
34
 
35
 
@@ -39,47 +72,16 @@ ANNOUNCEMENT = """
39
  Criticize your paper's contribution by searching related references online! This nice bot will also give you some suggestions.
40
  """
41
 
42
-
43
- def reset():
44
- return "", "", {}, {}, {}
45
-
46
-
47
- def search_refs(title, contributions):
48
- ref = References(title=title, description=contributions)
49
-
50
  keywords, _ = llm(systems=SYSTEM["keywords"], prompts=title, return_json=True)
51
  keywords = {keyword: 10 for keyword in keywords}
52
-
53
  ref.collect_papers(keywords)
54
- return ref.to_prompts(max_tokens=8192)
55
-
56
 
57
- def criticize_my_idea(title, contributions, refined_contributions, suggestions):
58
- if refined_contributions:
59
- cont = {k: {"statement": v["statement"]} for k, v in refined_contributions.items()}
60
-
61
- ref = References(title=title, description=f"{cont}")
62
- keywords, _ = llm(systems=SYSTEM["keywords"], prompts=title, return_json=True)
63
- keywords = {keyword: 10 for keyword in keywords}
64
- ref.collect_papers(keywords)
65
- ref_prompt = ref.to_prompts(max_tokens=4096)
66
-
67
- prompt = f"Title: {title}\n References: {ref_prompt}\n Contributions: {cont}"
68
- output, _ = llm(systems=contribution_system_prompt_2, prompts=prompt, return_json=True)
69
-
70
- suggestions, _ = llm(systems=suggestions_system_prompt, prompts=str(output), return_json=True)
71
-
72
- return output, ref_prompt, suggestions
73
- else:
74
- ref = References(title=title, description=f"{contributions}")
75
- keywords, _ = llm(systems=SYSTEM["keywords"], prompts=title, return_json=True)
76
- keywords = {keyword: 10 for keyword in keywords}
77
- ref.collect_papers(keywords)
78
- ref_prompt = ref.to_prompts(max_tokens=4096)
79
-
80
- prompt = f"Title: {title}\n References: {ref_prompt}\n Contributions: {contributions}"
81
- output, _ = llm(systems=contribution_system_prompt_1, prompts=prompt, return_json=True)
82
- return output, ref_prompt, {}
83
 
84
  def paste_title(suggestions):
85
  if suggestions:
@@ -90,7 +92,9 @@ def paste_title(suggestions):
90
  else:
91
  return "", "", {}, {}, {}
92
 
93
-
 
 
94
 
95
 
96
 
@@ -99,26 +103,32 @@ with gr.Blocks() as demo:
99
  gr.Markdown(ANNOUNCEMENT)
100
 
101
  with gr.Row():
102
- with gr.Column():
 
 
 
 
 
 
 
 
103
  title_input = gr.Textbox(label="Title")
104
  contribution_input = gr.Textbox(label="Contributions", lines=5)
 
 
105
 
106
  with gr.Row():
107
- button_reset = gr.Button("Reset")
108
- button_submit = gr.Button("Submit", variant="primary")
 
 
109
 
110
  with gr.Column(scale=1):
111
  contribution_output = gr.JSON(label="Contributions")
112
- suggestions_output = gr.JSON(label="Suggestions")
113
- button_copy = gr.Button("Send Title and Contributions to the Left")
114
- references_output = gr.JSON(label="References")
115
-
116
- button_reset.click(fn=reset, inputs=[], outputs=[title_input, contribution_input, contribution_output, references_output, suggestions_output])
117
- button_submit.click(fn=criticize_my_idea, inputs=[title_input, contribution_input, contribution_output, suggestions_output], outputs=[contribution_output, references_output, suggestions_output])
118
- button_copy.click(fn=paste_title, inputs=suggestions_output, outputs=[title_input, contribution_input, contribution_output, references_output, suggestions_output])
119
- # clear_button_refs.click(fn=clear_inputs_refs, inputs=[title_refs, slider_refs], outputs=[title_refs, slider_refs])
120
- # submit_button_refs.click(fn=wrapped_references_generator,
121
- # inputs=[title_refs, slider_refs, key], outputs=json_output)
122
 
 
 
123
  demo.queue(concurrency_count=1, max_size=5, api_open=False)
124
  demo.launch(show_error=True)
 
7
 
8
  openai_key = os.getenv("OPENAI_API_KEY")
9
  default_model = os.getenv("DEFAULT_MODEL")
10
+ if default_model is None:
11
+ default_model = "gpt-3.5-turbo-16k"
12
 
13
+ openai.api_key = openai_key
 
 
 
14
 
15
+ paper_system_prompt = '''You are an assistant designed to propose choices of research direction.
16
+ The user will input questions or some keywords of a fields. You need to generate some paper titles and main contributions. Ensure follow the following instructions:
17
  Instruction:
18
  - Your response should follow the JSON format.
19
  - Your response should have the following structure:
20
+ {
21
+ "your suggested paper title":
22
+ {
23
+ "summary": "an overview introducing what this paper will include",
24
+ "contributions": {
25
+ "contribution1": {"statement": "briefly describe this contribution", "reason": "reason why this contribution can make this paper outstanding"},
26
+ "contribution2": {"statement": "briefly describe this contribution", "reason": "reason why this contribution can make this paper outstanding"},
27
+ ...
28
+ }
29
+ }
30
+ "your suggested paper title":
31
+ {
32
+ "summary": "an overview introducing what this paper will include",
33
+ "contributions": {
34
+ "contribution1": {"statement": "briefly describe this contribution", "reason": "reason why this contribution can make this paper outstanding"},
35
+ "contribution2": {"statement": "briefly describe this contribution", "reason": "reason why this contribution can make this paper outstanding"},
36
+ ...
37
+ }
38
+ }
39
+ ...
40
+ }
41
+ - Please list three to five suggested title and at least three contributions for each paper.
42
  '''
43
 
44
+
45
+ contribution_system_prompt = '''You are an assistant designed to criticize the contributions of a paper. You will be provided Paper's Title, References and Contributions. Ensure follow the following instructions:
46
  Instruction:
47
  - Your response should follow the JSON format.
48
  - Your response should have the following structure:
49
+ {
50
+ "title": "the title provided by the user",
51
+ "comment": "your thoughts on if this title clearly reflects the key ideas of this paper and explain why"
52
+ "contributions": {
53
+ "contribution1": {"statement": "briefly describe what the contribution is",
54
+ "reason": "reason why the user claims it is a contribution",
55
+ "judge": "your thought about if this is a novel contribution and explain why",
56
+ "suggestion": "your suggestion on how to modify the research direction to enhance the novelty "},
57
+ "contribution2": {"statement": "briefly describe what the contribution is",
58
+ "reason": "reason why the user claims it is a contribution",
59
+ "judge": "your thought about if this is a novel contribution and explain why",
60
+ "suggestion": "your suggestion on how to modify the research direction to enhance the novelty "},
61
+ ...
62
+ }
63
+ }
64
+ - You need to carefully check if the claimed contribution has been made in the provided references, which makes the contribution not novel.
65
+ - You also need to propose your concerns on if any of contributions could be incremental or just a mild modification on an existing work.
66
  '''
67
 
68
 
 
72
  Criticize your paper's contribution by searching related references online! This nice bot will also give you some suggestions.
73
  """
74
 
75
+ def criticize_my_idea(title, contributions, max_tokens=4096):
76
+ ref = References(title=title, description=f"{contributions}")
 
 
 
 
 
 
77
  keywords, _ = llm(systems=SYSTEM["keywords"], prompts=title, return_json=True)
78
  keywords = {keyword: 10 for keyword in keywords}
 
79
  ref.collect_papers(keywords)
80
+ ref_prompt = ref.to_prompts(max_tokens=max_tokens)
 
81
 
82
+ prompt = f"Title: {title}\n References: {ref_prompt}\n Contributions: {contributions}"
83
+ output, _ = llm(systems=contribution_system_prompt, prompts=prompt, return_json=True)
84
+ return output, ref_prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  def paste_title(suggestions):
87
  if suggestions:
 
92
  else:
93
  return "", "", {}, {}, {}
94
 
95
+ def generate_choices(thoughts):
96
+ output, _ = llm(systems=paper_system_prompt, prompts=thoughts, return_json=True)
97
+ return output
98
 
99
 
100
 
 
103
  gr.Markdown(ANNOUNCEMENT)
104
 
105
  with gr.Row():
106
+ with gr.Tab("Make it an idea!"):
107
+ thoughts_input = gr.Textbox(label="Thoughts")
108
+ with gr.Accordion("Show prompts", open=False):
109
+ prompts_1 = gr.Textbox(label="Prompts", interactive=False, value=paper_system_prompt)
110
+
111
+ with gr.Row():
112
+ button_generate_idea = gr.Button("Make it an idea!", variant="primary")
113
+
114
+ with gr.Tab("Criticize my idea!"):
115
  title_input = gr.Textbox(label="Title")
116
  contribution_input = gr.Textbox(label="Contributions", lines=5)
117
+ with gr.Accordion("Show prompts", open=False):
118
+ prompts_2 = gr.Textbox(label="Prompts", interactive=False, value=contribution_system_prompt)
119
 
120
  with gr.Row():
121
+ button_submit = gr.Button("Criticize my idea!", variant="primary")
122
+
123
+ with gr.Tab("Make it a paper!"):
124
+ gr.Markdown("## Coming Soon!")
125
 
126
  with gr.Column(scale=1):
127
  contribution_output = gr.JSON(label="Contributions")
128
+ with gr.Accordion("References", open=False):
129
+ references_output = gr.JSON(label="References")
 
 
 
 
 
 
 
 
130
 
131
+ button_submit.click(fn=criticize_my_idea, inputs=[title_input, contribution_input], outputs=[contribution_output, references_output])
132
+ button_generate_idea.click(fn=generate_choices, inputs=thoughts_input, outputs=contribution_output)
133
  demo.queue(concurrency_count=1, max_size=5, api_open=False)
134
  demo.launch(show_error=True)
utils/gpt_interaction.py CHANGED
@@ -79,7 +79,7 @@ class GPTModel_API2D_SUPPORT:
79
 
80
 
81
  class GPTModel:
82
- def __init__(self, model="gpt-4", temperature=0.9, presence_penalty=0,
83
  frequency_penalty=0, max_attempts=1, delay=20):
84
  self.model = model
85
  self.temperature = temperature
 
79
 
80
 
81
  class GPTModel:
82
+ def __init__(self, model="gpt-3.5-turbo", temperature=0.9, presence_penalty=0,
83
  frequency_penalty=0, max_attempts=1, delay=20):
84
  self.model = model
85
  self.temperature = temperature