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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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Six Thinking Hats Simulator\n",
    "\n",
    "## Objective\n",
    "This notebook implements a simulator of the Six Thinking Hats technique to evaluate and improve technological solutions. The simulator will:\n",
    "\n",
    "1. Use an LLM to generate an initial technological solution idea for a specific daily task in a company.\n",
    "2. Apply the Six Thinking Hats methodology to analyze and improve the proposed solution.\n",
    "3. Provide a comprehensive evaluation from different perspectives.\n",
    "\n",
    "## About the Six Thinking Hats Technique\n",
    "\n",
    "The Six Thinking Hats is a powerful technique developed by Edward de Bono that helps people look at problems and decisions from different perspectives. Each \"hat\" represents a different thinking approach:\n",
    "\n",
    "- **White Hat (Facts):** Focuses on available information, facts, and data.\n",
    "- **Red Hat (Feelings):** Represents emotions, intuition, and gut feelings.\n",
    "- **Black Hat (Critical):** Identifies potential problems, risks, and negative aspects.\n",
    "- **Yellow Hat (Positive):** Looks for benefits, opportunities, and positive aspects.\n",
    "- **Green Hat (Creative):** Encourages new ideas, alternatives, and possibilities.\n",
    "- **Blue Hat (Process):** Manages the thinking process and ensures all perspectives are considered.\n",
    "\n",
    "In this simulator, we'll use these different perspectives to thoroughly evaluate and improve technological solutions proposed by an LLM."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import json\n",
    "from dotenv import load_dotenv\n",
    "from openai import OpenAI\n",
    "from anthropic import Anthropic\n",
    "from IPython.display import Markdown, display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv(override=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Print the key prefixes to help with any debugging\n",
    "\n",
    "openai_api_key = os.getenv('OPENAI_API_KEY')\n",
    "anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
    "google_api_key = os.getenv('GOOGLE_API_KEY')\n",
    "deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\n",
    "groq_api_key = os.getenv('GROQ_API_KEY')\n",
    "\n",
    "if openai_api_key:\n",
    "    print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",
    "else:\n",
    "    print(\"OpenAI API Key not set\")\n",
    "    \n",
    "if anthropic_api_key:\n",
    "    print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",
    "else:\n",
    "    print(\"Anthropic API Key not set\")\n",
    "\n",
    "if google_api_key:\n",
    "    print(f\"Google API Key exists and begins {google_api_key[:2]}\")\n",
    "else:\n",
    "    print(\"Google API Key not set\")\n",
    "\n",
    "if deepseek_api_key:\n",
    "    print(f\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\")\n",
    "else:\n",
    "    print(\"DeepSeek API Key not set\")\n",
    "\n",
    "if groq_api_key:\n",
    "    print(f\"Groq API Key exists and begins {groq_api_key[:4]}\")\n",
    "else:\n",
    "    print(\"Groq API Key not set\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "request = \"Generate a technological solution to solve a specific workplace challenge. Choose an employee role, in a specific industry, and identify a time-consuming or error-prone daily task they face. Then, create an innovative yet practical technological solution that addresses this challenge. Include what technologies it uses (AI, automation, etc.), how it integrates with existing systems, its key benefits, and basic implementation requirements. Keep your solution realistic with current technology. \"\n",
    "request += \"Answer only with the question, no explanation.\"\n",
    "messages = [{\"role\": \"user\", \"content\": request}]\n",
    "\n",
    "openai = OpenAI()\n",
    "response = openai.chat.completions.create(\n",
    "    model=\"gpt-4o-mini\",\n",
    "    messages=messages,\n",
    ")\n",
    "question = response.choices[0].message.content\n",
    "print(question)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "validation_prompt = f\"\"\"Validate and improve the following technological solution. For each iteration, check if the solution meets these criteria:\n",
    "\n",
    "1. Clarity:\n",
    "   - Is the problem clearly defined?\n",
    "   - Is the solution clearly explained?\n",
    "   - Are the technical components well-described?\n",
    "\n",
    "2. Specificity:\n",
    "   - Are there specific examples or use cases?\n",
    "   - Are the technologies and tools specifically named?\n",
    "   - Are the implementation steps detailed?\n",
    "\n",
    "3. Context:\n",
    "   - Is the industry/company context clear?\n",
    "   - Are the user roles and needs well-defined?\n",
    "   - Is the current workflow/problem well-described?\n",
    "\n",
    "4. Constraints:\n",
    "   - Are there clear technical limitations?\n",
    "   - Are there budget/time constraints mentioned?\n",
    "   - Are there integration requirements specified?\n",
    "\n",
    "If any of these criteria are not met, improve the solution by:\n",
    "1. Adding missing details\n",
    "2. Clarifying ambiguous points\n",
    "3. Providing more specific examples\n",
    "4. Including relevant constraints\n",
    "\n",
    "Here is the technological solution to validate and improve:\n",
    "{question} \n",
    "Provide an improved version that addresses any missing or unclear aspects. If this is the 5th iteration, return the final improved version without further changes.\n",
    "\n",
    "Response only with the Improved Solution:\n",
    "[Your improved solution here]\"\"\"\n",
    "\n",
    "messages = [{\"role\": \"user\", \"content\": validation_prompt}]\n",
    "\n",
    "response = openai.chat.completions.create(model=\"gpt-4o\", messages=messages)\n",
    "question = response.choices[0].message.content\n",
    "\n",
    "display(Markdown(question))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "In this section, we will ask each AI model to analyze a technological solution using the Six Thinking Hats methodology. Each model will:\n",
    "\n",
    "1. First generate a technological solution for a workplace challenge\n",
    "2. Then analyze that solution using each of the Six Thinking Hats\n",
    "\n",
    "Each model will provide:\n",
    "1. An initial technological solution\n",
    "2. A structured analysis using all six thinking hats\n",
    "3. A final recommendation based on the comprehensive analysis\n",
    "\n",
    "This approach will allow us to:\n",
    "- Compare how different models apply the Six Thinking Hats methodology\n",
    "- Identify patterns and differences in their analytical approaches\n",
    "- Gather diverse perspectives on the same solution\n",
    "- Create a rich, multi-faceted evaluation of each proposed technological solution\n",
    "\n",
    "The responses will be collected and displayed below, showing how each model applies the Six Thinking Hats methodology to evaluate and improve the proposed solutions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "models = []\n",
    "answers = []\n",
    "combined_question = f\" Analyze the technological solution prposed in {question} using the Six Thinking Hats methodology. For each hat, provide a detailed analysis. Finally, provide a comprehensive recommendation based on all the above analyses.\"\n",
    "messages = [{\"role\": \"user\", \"content\": combined_question}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# GPT thinking process\n",
    "\n",
    "model_name = \"gpt-4o\"\n",
    "\n",
    "\n",
    "response = openai.chat.completions.create(model=model_name, messages=messages)\n",
    "answer = response.choices[0].message.content\n",
    "\n",
    "display(Markdown(answer))\n",
    "models.append(model_name)\n",
    "answers.append(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Claude thinking process\n",
    "\n",
    "model_name = \"claude-3-7-sonnet-latest\"\n",
    "\n",
    "claude = Anthropic()\n",
    "response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\n",
    "answer = response.content[0].text\n",
    "\n",
    "display(Markdown(answer))\n",
    "models.append(model_name)\n",
    "answers.append(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Gemini thinking process\n",
    "\n",
    "gemini = OpenAI(api_key=google_api_key, base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\")\n",
    "model_name = \"gemini-2.0-flash\"\n",
    "\n",
    "response = gemini.chat.completions.create(model=model_name, messages=messages)\n",
    "answer = response.choices[0].message.content\n",
    "\n",
    "display(Markdown(answer))\n",
    "models.append(model_name)\n",
    "answers.append(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Deepseek thinking process\n",
    "\n",
    "deepseek = OpenAI(api_key=deepseek_api_key, base_url=\"https://api.deepseek.com/v1\")\n",
    "model_name = \"deepseek-chat\"\n",
    "\n",
    "response = deepseek.chat.completions.create(model=model_name, messages=messages)\n",
    "answer = response.choices[0].message.content\n",
    "\n",
    "display(Markdown(answer))\n",
    "models.append(model_name)\n",
    "answers.append(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Groq thinking process\n",
    "\n",
    "groq = OpenAI(api_key=groq_api_key, base_url=\"https://api.groq.com/openai/v1\")\n",
    "model_name = \"llama-3.3-70b-versatile\"\n",
    "\n",
    "response = groq.chat.completions.create(model=model_name, messages=messages)\n",
    "answer = response.choices[0].message.content\n",
    "\n",
    "display(Markdown(answer))\n",
    "models.append(model_name)\n",
    "answers.append(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!ollama pull llama3.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Ollama thinking process\n",
    "\n",
    "ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n",
    "model_name = \"llama3.2\"\n",
    "\n",
    "response = ollama.chat.completions.create(model=model_name, messages=messages)\n",
    "answer = response.choices[0].message.content\n",
    "\n",
    "display(Markdown(answer))\n",
    "models.append(model_name)\n",
    "answers.append(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for model, answer in zip(models, answers):\n",
    "    print(f\"Model: {model}\\n\\n{answer}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Next Step: Solution Synthesis and Enhancement\n",
    "\n",
    "**Best Recommendation Selection and Extended Solution Development**\n",
    "\n",
    "After applying the Six Thinking Hats analysis to evaluate the initial technological solution from multiple perspectives, the simulator will:\n",
    "\n",
    "1. **Synthesize Analysis Results**: Compile insights from all six thinking perspectives (White, Red, Black, Yellow, Green, and Blue hats) to identify the most compelling recommendations and improvements.\n",
    "\n",
    "2. **Select Optimal Recommendation**: Using a weighted evaluation system that considers feasibility, impact, and alignment with organizational goals, the simulator will identify and present the single best recommendation that emerged from the Six Thinking Hats analysis.\n",
    "\n",
    "3. **Generate Extended Solution**: Building upon the selected best recommendation, the simulator will create a comprehensive, enhanced version of the original technological solution that incorporates:\n",
    "  - Key insights from the critical analysis (Black Hat)\n",
    "  - Positive opportunities identified (Yellow Hat)\n",
    "  - Creative alternatives and innovations (Green Hat)\n",
    "  - Factual considerations and data requirements (White Hat)\n",
    "  - User experience and emotional factors (Red Hat)\n",
    "\n",
    "4. **Multi-Model Enhancement**: To further strengthen the solution, the simulator will leverage additional AI models or perspectives to provide supplementary recommendations that complement the Six Thinking Hats analysis, offering a more robust and well-rounded final technological solution.\n",
    "\n",
    "This step transforms the analytical insights into actionable improvements, delivering a refined solution that has been thoroughly evaluated and enhanced through structured critical thinking."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "together = \"\"\n",
    "for index, answer in enumerate(answers):\n",
    "    together += f\"# Response from model {index+1}\\n\\n\"\n",
    "    together += answer + \"\\n\\n\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Markdown, display\n",
    "import re\n",
    "\n",
    "print(f\"Each model has been given this technological solution to analyze: {question}\")\n",
    "\n",
    "# First, get the best individual response\n",
    "judge_prompt = f\"\"\"\n",
    "    You are judging the quality of {len(models)} responses.\n",
    "    Evaluate each response based on:\n",
    "    1. Clarity and coherence\n",
    "    2. Depth of analysis\n",
    "    3. Practicality of recommendations\n",
    "    4. Originality of insights\n",
    "    \n",
    "    Rank the responses from best to worst.\n",
    "    Respond with the model index of the best response, nothing else.\n",
    "    \n",
    "    Here are the responses:\n",
    "    {answers}\n",
    "    \"\"\"\n",
    "    \n",
    "# Get the best response\n",
    "judge_response = openai.chat.completions.create(\n",
    "    model=\"o3-mini\",\n",
    "    messages=[{\"role\": \"user\", \"content\": judge_prompt}]\n",
    ")\n",
    "best_response = judge_response.choices[0].message.content\n",
    "\n",
    "print(f\"Best Response's Model: {models[int(best_response)]}\")\n",
    "\n",
    "synthesis_prompt = f\"\"\"\n",
    "    Here is the best response's model index from the judge:\n",
    "\n",
    "    {best_response}\n",
    "\n",
    "    And here are the responses from all the models:\n",
    "\n",
    "    {together}\n",
    "\n",
    "    Synthesize the responses from the non-best models into one comprehensive answer that:\n",
    "    1. Captures the best insights from each response that could add value to the best response from the judge\n",
    "    2. Resolves any contradictions between responses before extending the best response\n",
    "    3. Presents a clear and coherent final answer that is a comprehensive extension of the best response from the judge\n",
    "    4. Maintains the same format as the original best response from the judge\n",
    "    5. Compiles all additional recommendations mentioned by all models\n",
    "\n",
    "    Show the best response {answers[int(best_response)]} and then your synthesized response specifying which are additional recommendations to the best response:\n",
    "    \"\"\"\n",
    "\n",
    "# Get the synthesized response\n",
    "synthesis_response = claude.messages.create(\n",
    "    model=\"claude-3-7-sonnet-latest\",\n",
    "    messages=[{\"role\": \"user\", \"content\": synthesis_prompt}],\n",
    "    max_tokens=10000\n",
    ")\n",
    "synthesized_answer = synthesis_response.content[0].text\n",
    "\n",
    "converted_answer = re.sub(r'\\\\[\\[\\]]', '$$', synthesized_answer)\n",
    "display(Markdown(converted_answer))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}