floydchow7 commited on
Commit
677973e
·
1 Parent(s): a9a266f

Use gpt4o and apply CoT in prompting

Browse files
Files changed (2) hide show
  1. constants.py +3 -3
  2. utils.py +82 -28
constants.py CHANGED
@@ -20,7 +20,7 @@ SDG_DETAILS = """
20
 
21
 
22
  GPT_PROMPT_parallel="""
23
- For AI generated/modified parts, our base model is GPT-3.5-turbo.
24
 
25
  For direct generation, we use instructions like following:
26
  "Given the task as: [task_description], provide an answer: "
@@ -33,7 +33,7 @@ Merge the two answers into one in a coherent way: "
33
  """
34
 
35
  GPT_PROMPT_sequential="""
36
- For AI generated/modified parts, our base model is GPT-3.5-turbo.
37
 
38
  For the modification, we use instructions like following:
39
  "Given the task as :[task_description, the human answer is: [human_text]
@@ -41,7 +41,7 @@ Provide an answer of your own but make sure it is coherent and should be based o
41
  """
42
 
43
  GPT_PROMPT_reverse_sequential="""
44
- For AI generated/modified parts, our base model is GPT-3.5-turbo.
45
 
46
  For direct generation, we use instructions like following:
47
  "Given the task as: [task_description], provide an answer: "
 
20
 
21
 
22
  GPT_PROMPT_parallel="""
23
+ For AI generated/modified parts, our base model is GPT-4o.
24
 
25
  For direct generation, we use instructions like following:
26
  "Given the task as: [task_description], provide an answer: "
 
33
  """
34
 
35
  GPT_PROMPT_sequential="""
36
+ For AI generated/modified parts, our base model is GPT-4o.
37
 
38
  For the modification, we use instructions like following:
39
  "Given the task as :[task_description, the human answer is: [human_text]
 
41
  """
42
 
43
  GPT_PROMPT_reverse_sequential="""
44
+ For AI generated/modified parts, our base model is GPT-4o.
45
 
46
  For direct generation, we use instructions like following:
47
  "Given the task as: [task_description], provide an answer: "
utils.py CHANGED
@@ -31,15 +31,23 @@ def describe_task():
31
  return task_description
32
 
33
  def generate_text_with_gpt(prompts, api_key = None):
34
- """Generate text using the GPT-3 model."""
35
  if api_key:
36
  openai.api_key = api_key
37
 
38
  try:
39
  response = openai.ChatCompletion.create(
40
- model="gpt-3.5-turbo",
41
  messages=[
42
- {"role": "system", "content": "Please assist."},
 
 
 
 
 
 
 
 
43
  {"role": "user", "content": prompts}
44
  ]
45
  )
@@ -54,41 +62,87 @@ def generate_ai_initial_answer(task_description, api_key=None):
54
  return generate_text_with_gpt(prompt, api_key)
55
 
56
  def merge_texts_parallel(task_description, human_text, ai_text, api_key = None):
57
- prompt = f"Given the task: {task_description}, there are two answers provided:\n" + \
58
- f"The first answer: {human_text}\nThe second answer: {ai_text}\n" + \
59
- f"Merge the two answers into one in a coherent way: "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  return generate_text_with_gpt(prompt, api_key)
61
 
62
  def merge_texts_sequential(task_description, human_text, api_key = None):
63
- prompt = f"Given the task:{task_description}, here is the answer provided by the human: {human_text}\n" + \
64
- f"Refine this response and ensure the final answer aligns with the human's intent:"
 
 
 
 
 
 
 
 
 
 
 
65
  return generate_text_with_gpt(prompt, api_key)
66
 
67
  def modify_with_suggestion(task_description, text, suggestions, api_key = None):
68
- prompt = f"Given the task:{task_description}, the answer provided is: {text}\n" + \
69
- f"Modify the answer based on the following suggestions: {suggestions}"
 
 
 
 
 
 
 
 
 
 
 
 
70
  return generate_text_with_gpt(prompt, api_key)
71
 
72
  def get_evaluation_with_gpt(task_description, text, api_key=None):
73
  prompt = (
74
- f"Given the task: {task_description}, the provided answer is: {text}\n"
75
- f"Evaluate the answer using a scale from 0 to 10. Scores should reflect how well the ideas fit each specific evaluation criteria:\n"
76
- f"0-2: Poor fit; the idea demonstrates minimal relevance to the criteria.\n"
77
- f"3-5: Partial fit; the idea shows some relevance but contains significant shortcomings.\n"
78
- f"6-8: Good fit; the idea aligns well with the criteria, showing clear relevance and thoughtfulness.\n"
79
- f"9-10: Excellent fit; the idea fully aligns with the criteria, demonstrating exceptional insight.\n\n"
80
- f"When evaluating, use the entire scoring range (0-10) and avoid defaulting to mid-range scores. If the provided answer is vague or off-topic, assign scores between 0-5.\n\n"
81
- f"Evaluate based on the following criteria:\n"
82
- f"Novelty: The uniqueness and innovation of the ideas.\n"
83
- f"Implementability: The practicality of suggested actions.\n"
84
- f"Inimitability: The difficulty for competitors to replicate the ideas.\n"
85
- f"Alignment: The degree to which the ideas align with Airbnb’s goals and 17 SDGs.\n\n"
86
- f"Please format the output exactly as follows:\n"
87
- f"Novelty: [Score]\n"
88
- f"Implementability: [Score]\n"
89
- f"Inimitability: [Score]\n"
90
- f"Alignment: [Score]\n"
91
- )
 
 
 
 
 
 
 
 
 
92
  return generate_text_with_gpt(prompt, api_key)
93
 
94
  def display_merged_output(session_index, session_manager):
 
31
  return task_description
32
 
33
  def generate_text_with_gpt(prompts, api_key = None):
34
+ """Generate text using the GPT-4o model."""
35
  if api_key:
36
  openai.api_key = api_key
37
 
38
  try:
39
  response = openai.ChatCompletion.create(
40
+ model="gpt-4o",
41
  messages=[
42
+ {"role": "system", "content": """
43
+ You are a sustainability expert with an extensive background in SDG17
44
+ (Partnerships for the Goals) and the United Nations Sustainable Development Goals (SDGs).
45
+ Your role is to critically analyze and evaluate the sustainability of business models,
46
+ using a highly rigorous and evidence-based approach.
47
+ You must maintain strict scoring criteria with clear justification for each score,
48
+ ensuring a wide distribution of scores to reflect meaningful differentiation in compliance and impact levels.
49
+ Avoid overly lenient assessments.
50
+ """},
51
  {"role": "user", "content": prompts}
52
  ]
53
  )
 
62
  return generate_text_with_gpt(prompt, api_key)
63
 
64
  def merge_texts_parallel(task_description, human_text, ai_text, api_key = None):
65
+ prompt = (
66
+ "You are tasked with merging two answers into a single, coherent, and logically structured response. "
67
+ "Your response should synthesize the strengths of both answers, eliminate redundancy, and ensure a logical flow. "
68
+ "Follow this structured chain of thought to guide your process:\n\n"
69
+ "1. **Understand the Task:** Start by carefully analyzing the task description to ensure your final response aligns fully with the objective.\n"
70
+ "2. **Extract Key Points:** Review both answers and identify the key ideas and arguments they present.\n"
71
+ "3. **Resolve Redundancies and Conflicts:** Compare the two answers to eliminate repetitive content and resolve any contradictions.\n"
72
+ "4. **Integrate Seamlessly:** Combine the extracted points into a single, unified response, ensuring a logical and coherent structure.\n"
73
+ "5. **Refine for Clarity:** Polish the final response for clarity, conciseness, and alignment with the task requirements.\n\n"
74
+ "Task Description:\n"
75
+ f"{task_description}\n\n"
76
+ "Answer 1:\n"
77
+ f"{human_text}\n\n"
78
+ "Answer 2:\n"
79
+ f"{ai_text}\n\n"
80
+ "Provide the unified and refined response below, marked clearly as the final version."
81
+ )
82
  return generate_text_with_gpt(prompt, api_key)
83
 
84
  def merge_texts_sequential(task_description, human_text, api_key = None):
85
+ prompt = (
86
+ f"Given the task: {task_description}, here is the response provided by the human:\n"
87
+ f"{human_text}\n\n"
88
+ "Your task is to refine the human's response while ensuring that the final answer fully aligns with their intent. "
89
+ "Follow this logical chain of thought:\n"
90
+ "1. **Understand the Intent:** Analyze the human's response to identify their key points and intended message.\n"
91
+ "2. **Evaluate Clarity:** Check for any ambiguities, gaps, or unclear phrasing in the response.\n"
92
+ "3. **Improve Coherence:** Ensure the response flows logically and connects ideas seamlessly.\n"
93
+ "4. **Enhance Precision:** Refine wording to be concise and impactful while preserving the human's original intent.\n"
94
+ "5. **Check Alignment:** Confirm that the final response accurately represents and strengthens the human's input without introducing unintended changes.\n\n"
95
+ "Provide the refined response below, clearly marked as the final version."
96
+ )
97
+
98
  return generate_text_with_gpt(prompt, api_key)
99
 
100
  def modify_with_suggestion(task_description, text, suggestions, api_key = None):
101
+ prompt = (
102
+ f"Given the task: {task_description}, the provided answer is:\n"
103
+ f"{text}\n\n"
104
+ f"The following suggestions have been made for improvement:\n"
105
+ f"{suggestions}\n\n"
106
+ "Your task is to modify the provided answer by systematically incorporating the suggestions while maintaining clarity, coherence, and alignment with the original task. "
107
+ "Follow this logical chain of thought:\n"
108
+ "1. **Understand the Task:** Reassess the original task description to ensure the modified answer remains aligned with the requirements.\n"
109
+ "2. **Analyze the Suggestions:** Break down each suggestion to understand its purpose and how it improves the original answer.\n"
110
+ "3. **Apply Improvements:** Integrate the suggestions into the answer thoughtfully, ensuring each one is addressed adequately.\n"
111
+ "4. **Ensure Coherence:** Verify that the modified answer flows logically and maintains a clear structure.\n"
112
+ "5. **Preserve Integrity:** Ensure the modified answer stays true to the original content while enhancing it as per the suggestions.\n\n"
113
+ "Provide the improved answer below, clearly marked as the revised version."
114
+ )
115
  return generate_text_with_gpt(prompt, api_key)
116
 
117
  def get_evaluation_with_gpt(task_description, text, api_key=None):
118
  prompt = (
119
+ f"Given the task: {task_description}, the provided answer is:\n{text}\n\n"
120
+ "You are tasked with evaluating the answer using a scale from 0 to 10 based on specific criteria. "
121
+ "Follow a structured chain-of-thought approach for your evaluation to ensure thoroughness and objectivity:\n\n"
122
+ "1. **Understand the Criteria:** Carefully review each evaluation criterion to ensure you fully grasp what is being assessed:\n"
123
+ " - Novelty: The uniqueness and innovation of the ideas.\n"
124
+ " - Implementability: The practicality of suggested actions.\n"
125
+ " - Inimitability: The difficulty for competitors to replicate the ideas.\n"
126
+ " - Alignment: The degree to which the ideas align with Airbnb’s goals and the 17 SDGs.\n\n"
127
+ "2. **Analyze the Answer:** Break down the answer into its key components and assess how well it meets each criterion.\n"
128
+ " - Identify strengths, weaknesses, and any gaps in the ideas provided.\n"
129
+ " - Consider the context of the task and whether the ideas are realistic and relevant.\n\n"
130
+ "3. **Assign Scores:** Use the following scale to score each criterion:\n"
131
+ " - 0-2: Poor fit; the idea demonstrates minimal relevance to the criteria.\n"
132
+ " - 3-5: Partial fit; the idea shows some relevance but contains significant shortcomings.\n"
133
+ " - 6-8: Good fit; the idea aligns well with the criteria, showing clear relevance and thoughtfulness.\n"
134
+ " - 9-10: Excellent fit; the idea fully aligns with the criteria, demonstrating exceptional insight.\n"
135
+ " - Note: Use the entire scoring range (0-10) and avoid defaulting to mid-range scores. If the provided answer is vague or off-topic, assign scores between 0-5.\n\n"
136
+ "4. **Justify Each Score:** Provide a brief explanation for each score, highlighting specific aspects of the answer that influenced your evaluation.\n\n"
137
+ "5. **Summarize:** Conclude with an overall assessment, summarizing the strengths and weaknesses of the answer.\n\n"
138
+ "Format your output exactly as follows:\n"
139
+ "Novelty: [Score] - [Justification]\n"
140
+ "Implementability: [Score] - [Justification]\n"
141
+ "Inimitability: [Score] - [Justification]\n"
142
+ "Alignment: [Score] - [Justification]\n\n"
143
+ "Begin your evaluation below:"
144
+ )
145
+
146
  return generate_text_with_gpt(prompt, api_key)
147
 
148
  def display_merged_output(session_index, session_manager):