CoolFace
Apppublic

alpha-zero/career_conversation2

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
2_lab2.ipynb897 linesDownload Raw Back to root
1{2 "cells": [3  {4   "cell_type": "markdown",5   "metadata": {},6   "source": [7    "## Welcome to the Second Lab - Week 1, Day 3\n",8    "\n",9    "Today we will work with lots of models! This is a way to get comfortable with APIs."10   ]11  },12  {13   "cell_type": "markdown",14   "metadata": {},15   "source": [16    "<table style=\"margin: 0; text-align: left; width:100%\">\n",17    "    <tr>\n",18    "        <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",19    "            <img src=\"../assets/stop.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",20    "        </td>\n",21    "        <td>\n",22    "            <h2 style=\"color:#ff7800;\">Important point - please read</h2>\n",23    "            <span style=\"color:#ff7800;\">The way I collaborate with you may be different to other courses you've taken. I prefer not to type code while you watch. Rather, I execute Jupyter Labs, like this, and give you an intuition for what's going on. My suggestion is that you carefully execute this yourself, <b>after</b> watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.<br/><br/>If you have time, I'd love it if you submit a PR for changes in the community_contributions folder - instructions in the resources. Also, if you have a Github account, use this to showcase your variations. Not only is this essential practice, but it demonstrates your skills to others, including perhaps future clients or employers...\n",24    "            </span>\n",25    "        </td>\n",26    "    </tr>\n",27    "</table>"28   ]29  },30  {31   "cell_type": "code",32   "execution_count": 3,33   "metadata": {},34   "outputs": [],35   "source": [36    "# Start with imports - ask ChatGPT to explain any package that you don't know\n",37    "\n",38    "import os\n",39    "import json\n",40    "from dotenv import load_dotenv\n",41    "from openai import OpenAI\n",42    "from anthropic import Anthropic\n",43    "from IPython.display import Markdown, display"44   ]45  },46  {47   "cell_type": "code",48   "execution_count": 13,49   "metadata": {},50   "outputs": [51    {52     "data": {53      "text/plain": [54       "True"55      ]56     },57     "execution_count": 13,58     "metadata": {},59     "output_type": "execute_result"60    }61   ],62   "source": [63    "# Always remember to do this!\n",64    "load_dotenv('../.env', override=True)"65   ]66  },67  {68   "cell_type": "code",69   "execution_count": 14,70   "metadata": {},71   "outputs": [72    {73     "name": "stdout",74     "output_type": "stream",75     "text": [76      "OpenAI API Key exists and begins sk-proj-\n",77      "Anthropic API Key exists and begins sk-ant-\n",78      "Google API Key exists and begins AI\n",79      "DeepSeek API Key not set (and this is optional)\n",80      "Groq API Key not set (and this is optional)\n"81     ]82    }83   ],84   "source": [85    "# Print the key prefixes to help with any debugging\n",86    "\n",87    "openai_api_key = os.getenv('OPENAI_API_KEY')\n",88    "anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",89    "google_api_key = os.getenv('GOOGLE_API_KEY')\n",90    "deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\n",91    "groq_api_key = os.getenv('GROQ_API_KEY')\n",92    "\n",93    "if openai_api_key:\n",94    "    print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",95    "else:\n",96    "    print(\"OpenAI API Key not set\")\n",97    "    \n",98    "if anthropic_api_key:\n",99    "    print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",100    "else:\n",101    "    print(\"Anthropic API Key not set (and this is optional)\")\n",102    "\n",103    "if google_api_key:\n",104    "    print(f\"Google API Key exists and begins {google_api_key[:2]}\")\n",105    "else:\n",106    "    print(\"Google API Key not set (and this is optional)\")\n",107    "\n",108    "if deepseek_api_key:\n",109    "    print(f\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\")\n",110    "else:\n",111    "    print(\"DeepSeek API Key not set (and this is optional)\")\n",112    "\n",113    "if groq_api_key:\n",114    "    print(f\"Groq API Key exists and begins {groq_api_key[:4]}\")\n",115    "else:\n",116    "    print(\"Groq API Key not set (and this is optional)\")"117   ]118  },119  {120   "cell_type": "code",121   "execution_count": 6,122   "metadata": {},123   "outputs": [],124   "source": [125    "request = \"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \"\n",126    "request += \"Answer only with the question, no explanation.\"\n",127    "messages = [{\"role\": \"user\", \"content\": request}]"128   ]129  },130  {131   "cell_type": "code",132   "execution_count": 7,133   "metadata": {},134   "outputs": [135    {136     "data": {137      "text/plain": [138       "[{'role': 'user',\n",139       "  'content': 'Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. Answer only with the question, no explanation.'}]"140      ]141     },142     "execution_count": 7,143     "metadata": {},144     "output_type": "execute_result"145    }146   ],147   "source": [148    "messages"149   ]150  },151  {152   "cell_type": "code",153   "execution_count": 8,154   "metadata": {},155   "outputs": [156    {157     "name": "stdout",158     "output_type": "stream",159     "text": [160      "How would you approach solving a complex ethical dilemma where two equally important principles conflict, and what criteria would you use to determine which principle to prioritize?\n"161     ]162    }163   ],164   "source": [165    "openai = OpenAI()\n",166    "response = openai.chat.completions.create(\n",167    "    model=\"gpt-4o-mini\",\n",168    "    messages=messages,\n",169    ")\n",170    "question = response.choices[0].message.content\n",171    "print(question)\n"172   ]173  },174  {175   "cell_type": "code",176   "execution_count": 9,177   "metadata": {},178   "outputs": [],179   "source": [180    "competitors = []\n",181    "answers = []\n",182    "messages = [{\"role\": \"user\", \"content\": question}]"183   ]184  },185  {186   "cell_type": "code",187   "execution_count": 10,188   "metadata": {},189   "outputs": [190    {191     "data": {192      "text/markdown": [193       "Approaching a complex ethical dilemma where two equally important principles conflict requires a careful and systematic approach. Here’s a step-by-step framework to guide this process:\n",194       "\n",195       "1. **Clarify the Principles**: Identify and articulate the two conflicting principles clearly. Understand their significance, context, and implications. For instance, these could be principles like justice vs. mercy or autonomy vs. beneficence.\n",196       "\n",197       "2. **Gather Relevant Information**: Collect all relevant facts, including the context of the situation, stakeholders involved, and potential consequences of adhering to or violating each principle. Understanding the specifics can often illuminate the implications of each option.\n",198       "\n",199       "3. **Consider Stakeholder Perspectives**: Evaluate how each principle affects different stakeholders. Who will be impacted by the decision? What are their values, rights, and needs? Engaging with the perspectives of those affected can provide valuable insights.\n",200       "\n",201       "4. **Apply Ethical Frameworks**: Utilize established ethical theories and frameworks to examine the dilemma. For example:\n",202       "   - **Utilitarianism**: Focus on the consequences and seek to maximize overall happiness or reduce harm.\n",203       "   - **Deontological Ethics**: Consider duties and rules, emphasizing the moral obligation to uphold certain principles.\n",204       "   - **Virtue Ethics**: Reflect on the character traits that would be encouraged by each principle and what a virtuous person would choose.\n",205       "\n",206       "5. **Identify potential compromises or alternatives**: Explore if there are ways to honor both principles to some extent or find creative solutions that minimize the impact on either principle.\n",207       "\n",208       "6. **Evaluate Consequences**: Assess the potential short-term and long-term consequences of prioritizing one principle over the other. Consider the implications for trust, relationships, and ethical precedents.\n",209       "\n",210       "7. **Reflect on Intuition and Values**: Consider your own values and moral intuitions. While rational analysis is critical, ethical dilemmas often invoke strong personal feelings and beliefs.\n",211       "\n",212       "8. **Seek Input from Others**: Consult with trusted colleagues, mentors, or ethical boards. They may offer perspectives or insights you haven’t considered.\n",213       "\n",214       "9. **Make a Decision and Reflect**: After thorough deliberation, prioritize the principle that aligns best with your ethical reasoning and the information gathered. After making the decision, reflect on the outcome and be open to learning from the results.\n",215       "\n",216       "10. **Communicate Transparently**: Once a decision is reached, communicate it clearly and transparently to all stakeholders involved, explaining the reasoning behind the choice.\n",217       "\n",218       "Ultimately, the criteria for prioritizing one principle over another might involve weighing the potential outcomes, considering long-term implications, valuing stakeholder wellbeing, and reflecting on fundamental ethical commitments. Remember, ethical dilemmas often don’t have clear \"right\" answers; the goal is to make the most considered decision possible, acknowledging the complexities involved."219      ],220      "text/plain": [221       "<IPython.core.display.Markdown object>"222      ]223     },224     "metadata": {},225     "output_type": "display_data"226    }227   ],228   "source": [229    "# The API we know well\n",230    "\n",231    "model_name = \"gpt-4o-mini\"\n",232    "\n",233    "response = openai.chat.completions.create(model=model_name, messages=messages)\n",234    "answer = response.choices[0].message.content\n",235    "\n",236    "display(Markdown(answer))\n",237    "competitors.append(model_name)\n",238    "answers.append(answer)"239   ]240  },241  {242   "cell_type": "code",243   "execution_count": 11,244   "metadata": {},245   "outputs": [246    {247     "data": {248      "text/markdown": [249       "# Approaching Ethical Dilemmas with Conflicting Principles\n",250       "\n",251       "When facing an ethical dilemma with two conflicting but equally important principles, I would approach it through several steps:\n",252       "\n",253       "1. **Clarify the principles and stakes** - Precisely identify what principles are in tension and who is affected\n",254       "\n",255       "2. **Consider multiple ethical frameworks** - Examine the situation through different lenses:\n",256       "   - Consequentialist: What outcomes maximize wellbeing?\n",257       "   - Deontological: What duties or rights are inviolable?\n",258       "   - Virtue ethics: What would a person of good character do?\n",259       "\n",260       "3. **Explore compromise possibilities** - Can both principles be partially honored?\n",261       "\n",262       "For prioritization, I would consider:\n",263       "- The severity and distribution of potential harms\n",264       "- Whether one principle serves as a foundation for the other\n",265       "- Context-specific factors that might temporarily elevate one principle\n",266       "- Stakeholder perspectives, especially from those most vulnerable\n",267       "- Precedent and long-term implications of the decision\n",268       "\n",269       "This process recognizes that there's rarely a perfect solution to genuine ethical dilemmas, but a thoughtful approach can lead to more justified and defensible decisions."270      ],271      "text/plain": [272       "<IPython.core.display.Markdown object>"273      ]274     },275     "metadata": {},276     "output_type": "display_data"277    }278   ],279   "source": [280    "# Anthropic has a slightly different API, and Max Tokens is required\n",281    "\n",282    "model_name = \"claude-3-7-sonnet-latest\"\n",283    "\n",284    "claude = Anthropic()\n",285    "response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\n",286    "answer = response.content[0].text\n",287    "\n",288    "display(Markdown(answer))\n",289    "competitors.append(model_name)\n",290    "answers.append(answer)"291   ]292  },293  {294   "cell_type": "code",295   "execution_count": 15,296   "metadata": {},297   "outputs": [298    {299     "data": {300      "text/markdown": [301       "Solving a complex ethical dilemma involving conflicting principles requires a systematic and thoughtful approach. Here's a breakdown of how I would approach such a situation, including the criteria I'd use for prioritization:\n",302       "\n",303       "**1. Understanding the Dilemma:**\n",304       "\n",305       "*   **Identify the Stakeholders:** Who are all the individuals and groups affected by the situation? What are their perspectives, interests, and potential harms or benefits?\n",306       "*   **Clearly Define the Conflicting Principles:** What are the specific ethical principles that are in conflict? (e.g., Autonomy vs. Beneficence, Justice vs. Loyalty, Honesty vs. Compassion).  Make sure these principles are well-defined and understood.\n",307       "*   **Gather All Relevant Facts:** Collect as much information as possible about the situation.  Avoid making assumptions or relying on incomplete data.  Ensure the facts are accurate and unbiased.\n",308       "*   **Analyze the Potential Consequences:** Consider the possible outcomes of different courses of action.  How would each option impact the stakeholders?  Think about both short-term and long-term consequences.\n",309       "\n",310       "**2. Applying Ethical Frameworks and Theories:**\n",311       "\n",312       "*   **Utilitarianism:**  This focuses on maximizing overall happiness or well-being.  Which action will produce the greatest good for the greatest number of people?  Difficulties:  Can be hard to predict consequences accurately; can potentially justify harming a minority for the benefit of the majority.\n",313       "*   **Deontology (Kantian Ethics):**  This emphasizes duty and adherence to universal moral rules (e.g., always tell the truth, treat people as ends in themselves, not merely as means).  Which action is consistent with these duties?  Difficulties:  Can be inflexible and may lead to counterintuitive results in specific situations.\n",314       "*   **Virtue Ethics:**  This focuses on developing and acting in accordance with virtuous character traits (e.g., honesty, compassion, courage, justice). What would a virtuous person do in this situation?  Difficulties: Can be subjective and culturally dependent on what are considered virtues.\n",315       "*   **Care Ethics:** This emphasizes relationships, empathy, and the importance of caring for others, especially the vulnerable. Which action best supports the needs and well-being of those involved, particularly those who are most vulnerable? Difficulties: Can lead to bias towards close relationships and may not adequately address broader systemic issues.\n",316       "\n",317       "**3. Prioritization Criteria:**\n",318       "\n",319       "Given that the principles are considered \"equally important,\" prioritization requires careful judgment. Here are criteria I'd use to help make that judgment:\n",320       "\n",321       "*   **Hierarchy of Principles (if applicable):**  While the initial premise is that they are *generally* equal, are there *specific circumstances* where one principle might inherently take precedence? Some ethical frameworks may provide a hierarchical structure (e.g., avoiding harm might generally outweigh promoting good, although not always). This is context dependent.\n",322       "*   **Severity of Harm:**  Which principle, if violated, would cause the *most significant and irreversible harm* to stakeholders?  Minimizing harm is often a central consideration.\n",323       "*   **Vulnerability:** Which principle best protects the most vulnerable stakeholders?  Those who are least able to protect themselves deserve special consideration.\n",324       "*   **Reversibility of Consequences:**  Which action has consequences that are more easily reversed or mitigated if things go wrong?  Choosing options with more reversible outcomes can reduce risk.\n",325       "*   **Justice and Fairness:**  Does one principle promote a more just and equitable outcome for all stakeholders involved?  This may involve considering historical injustices or systemic inequalities.\n",326       "*   **Professional Codes and Legal Obligations:**  Are there any relevant professional codes of ethics or legal obligations that provide guidance? These should be considered as they might clarify obligations.\n",327       "*   **Transparency and Justifiability:** Which decision can be most easily explained and justified to all stakeholders, even those who disagree with it?  Transparency builds trust and accountability.\n",328       "*   **Long-Term vs. Short-Term Considerations:**  Is one principle more critical to uphold for the long-term well-being of the individuals, organization, or society involved?\n",329       "*   **Consistency with Values:** Which action is most consistent with the core values of the individual, the organization, and the broader community?\n",330       "\n",331       "**4. Deliberation and Consultation:**\n",332       "\n",333       "*   **Seek Input from Others:** Consult with trusted colleagues, mentors, ethicists, or other relevant experts.  Getting diverse perspectives can help identify blind spots and improve the quality of the decision.\n",334       "*   **Ethical Review Boards/Committees:** If available, present the dilemma to an ethical review board or committee for guidance and feedback.\n",335       "*   **Reflect on Personal Biases:** Be aware of your own biases and how they might be influencing your judgment.\n",336       "\n",337       "**5. Making a Decision and Taking Action:**\n",338       "\n",339       "*   **Document the Reasoning:**  Carefully document the entire decision-making process, including the principles considered, the facts gathered, the consultations conducted, and the rationale for the final decision.  This documentation is crucial for accountability and transparency.\n",340       "*   **Implement the Decision:**  Take action to implement the chosen course of action.\n",341       "*   **Monitor and Evaluate:**  Monitor the outcomes of the decision and be prepared to adjust course if necessary. Evaluate whether the decision achieved the desired results and whether any unintended consequences occurred.\n",342       "\n",343       "**Example Scenario (Autonomy vs. Beneficence in Healthcare):**\n",344       "\n",345       "An elderly patient with a terminal illness refuses a life-sustaining treatment that doctors believe could significantly extend their life.\n",346       "\n",347       "*   **Autonomy:** The patient has the right to make their own decisions about their medical care, even if those decisions are not in their best medical interest.\n",348       "*   **Beneficence:** Doctors have a duty to act in the best interests of their patients and to promote their well-being.\n",349       "\n",350       "In this case:\n",351       "\n",352       "1.  **Understand the Patient's Reasoning:**  Explore the patient's reasons for refusing treatment.  Are they based on informed understanding of the risks and benefits? Are there underlying fears or values driving their decision?\n",353       "2.  **Assess Capacity:** Is the patient mentally competent to make this decision?\n",354       "3.  **Consider Quality of Life:** What kind of life extension is being offered? Will it be a life filled with pain and suffering?  The patient's definition of \"quality of life\" is paramount.\n",355       "4.  **Apply Prioritization Criteria:**  While both principles are important, respecting the patient's autonomy is typically given greater weight, *assuming* the patient is competent and informed. The severity of imposing unwanted treatment is high.\n",356       "5.  **Outcome:** The doctor should respect the patient's decision, providing palliative care to ensure their comfort and dignity. If the patient's capacity is questionable, further evaluation is needed.\n",357       "\n",358       "**Key Considerations:**\n",359       "\n",360       "*   There is often no \"perfect\" solution in ethical dilemmas.  The goal is to make the best possible decision given the circumstances, based on a thorough and well-reasoned analysis.\n",361       "*   Flexibility is important.  Be prepared to re-evaluate your decision if new information emerges or if the situation changes.\n",362       "*   Learning from experience is crucial. Reflect on past ethical dilemmas to improve your decision-making abilities in the future.\n",363       "*   Ethical decision-making is a continuous process, not a one-time event.\n",364       "\n",365       "By following this structured approach, I would strive to make ethically sound decisions, even in the face of complex and conflicting principles.  The key is to be thoughtful, deliberate, and committed to acting in the best interests of all stakeholders involved, while respecting the inherent complexity and ambiguity of ethical decision-making.\n"366      ],367      "text/plain": [368       "<IPython.core.display.Markdown object>"369      ]370     },371     "metadata": {},372     "output_type": "display_data"373    }374   ],375   "source": [376    "gemini = OpenAI(api_key=google_api_key, base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\")\n",377    "model_name = \"gemini-2.0-flash\"\n",378    "\n",379    "response = gemini.chat.completions.create(model=model_name, messages=messages)\n",380    "answer = response.choices[0].message.content\n",381    "\n",382    "display(Markdown(answer))\n",383    "competitors.append(model_name)\n",384    "answers.append(answer)"385   ]386  },387  {388   "cell_type": "code",389   "execution_count": null,390   "metadata": {},391   "outputs": [],392   "source": [393    "deepseek = OpenAI(api_key=deepseek_api_key, base_url=\"https://api.deepseek.com/v1\")\n",394    "model_name = \"deepseek-chat\"\n",395    "\n",396    "response = deepseek.chat.completions.create(model=model_name, messages=messages)\n",397    "answer = response.choices[0].message.content\n",398    "\n",399    "display(Markdown(answer))\n",400    "competitors.append(model_name)\n",401    "answers.append(answer)"402   ]403  },404  {405   "cell_type": "code",406   "execution_count": null,407   "metadata": {},408   "outputs": [],409   "source": [410    "groq = OpenAI(api_key=groq_api_key, base_url=\"https://api.groq.com/openai/v1\")\n",411    "model_name = \"llama-3.3-70b-versatile\"\n",412    "\n",413    "response = groq.chat.completions.create(model=model_name, messages=messages)\n",414    "answer = response.choices[0].message.content\n",415    "\n",416    "display(Markdown(answer))\n",417    "competitors.append(model_name)\n",418    "answers.append(answer)\n"419   ]420  },421  {422   "cell_type": "markdown",423   "metadata": {},424   "source": [425    "## For the next cell, we will use Ollama\n",426    "\n",427    "Ollama runs a local web service that gives an OpenAI compatible endpoint,  \n",428    "and runs models locally using high performance C++ code.\n",429    "\n",430    "If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\n",431    "\n",432    "After it's installed, you should be able to visit here: http://localhost:11434 and see the message \"Ollama is running\"\n",433    "\n",434    "You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\`) and run `ollama serve`\n",435    "\n",436    "Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\n",437    "\n",438    "`ollama pull <model_name>` downloads a model locally  \n",439    "`ollama ls` lists all the models you've downloaded  \n",440    "`ollama rm <model_name>` deletes the specified model from your downloads"441   ]442  },443  {444   "cell_type": "markdown",445   "metadata": {},446   "source": [447    "<table style=\"margin: 0; text-align: left; width:100%\">\n",448    "    <tr>\n",449    "        <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",450    "            <img src=\"../assets/stop.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",451    "        </td>\n",452    "        <td>\n",453    "            <h2 style=\"color:#ff7800;\">Super important - ignore me at your peril!</h2>\n",454    "            <span style=\"color:#ff7800;\">The model called <b>llama3.3</b> is FAR too large for home computers - it's not intended for personal computing and will consume all your resources! Stick with the nicely sized <b>llama3.2</b> or <b>llama3.2:1b</b> and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the <A href=\"https://ollama.com/models\">the Ollama models page</a> for a full list of models and sizes.\n",455    "            </span>\n",456    "        </td>\n",457    "    </tr>\n",458    "</table>"459   ]460  },461  {462   "cell_type": "code",463   "execution_count": null,464   "metadata": {},465   "outputs": [],466   "source": [467    "!ollama pull llama3.2"468   ]469  },470  {471   "cell_type": "code",472   "execution_count": 16,473   "metadata": {},474   "outputs": [475    {476     "data": {477      "text/markdown": [478       "Approaching a complex ethical dilemma where two equally important principles conflict requires careful consideration, analysis, and evaluation of the situation. Here's a step-by-step framework to help guide decision-making:\n",479       "\n",480       "1. **Identify all relevant principles**: Clearly articulate both conflicting principles and identify their core values, interests, or stakeholders affected by each principle.\n",481       "2. **Understand the context**: Gather as much information as possible about the situation, including its historical background, current circumstances, potential consequences, and any relevant laws, regulations, or guidelines.\n",482       "3. **Analyze the conflict**: Examine how each principle interacts with the other, considering potential trade-offs, synergies, or mutually exclusive effects. Identify potential consequences of prioritizing one principle over the other.\n",483       "4. **Evaluate the principles' core values**: Consider the fundamental values, interests, or goals underlying each principle. Ask yourself:\n",484       "\t* What are the underlying motivations and interests driving each principle?\n",485       "\t* Are they aligned with organizational, societal, or individual values?\n",486       "5. **Consider mitigating factors**: Weigh any additional factors that may influence your decision, such as:\n",487       "\t* External pressures (e.g., regulatory requirements)\n",488       "\t* Internal dynamics (e.g., stakeholder concerns, team morale)\n",489       "\t* Historical precedents\n",490       "6. **Weight the principles' importance**: Attempt to assign a relative weight or priority to each principle based on its core values and interests. Consider using a scale of 1-10 or a more nuanced ranking system.\n",491       "7. **Consult decision-making frameworks**: Explore relevant ethical theories, such as consequentialism, deontology, or virtue ethics, which can provide guidance on resolving conflicts between principles.\n",492       "8. **Seek alternative solutions**: Brainstorm possible compromises or creative solutions that balance both conflicting principles. Consider seeking input from diverse stakeholders, experts, or mentors.\n",493       "9. **Justify your decision**: Clearly articulate the reasoning behind your chosen principle and prioritize approach. Be prepared to justify your decision in the face of potential criticisms.\n",494       "\n",495       "**Criteria for prioritizing principles**:\n",496       "\n",497       "1. **Consistency with organizational values**: Aligns with the organization's core mission, vision, and values.\n",498       "2. **Impact on stakeholders**: Consider the interests, well-being, and rights of all relevant parties affected by each principle.\n",499       "3. **Long-term consequences**: Prioritize principles that promote sustainability and long-term positive outcomes.\n",500       "4. **Fairness and justice**: Strive to uphold fairness, equity, and justice in your decision-making process.\n",501       "5. **Transparency and accountability**: Ensure clear explanations for your decision-making process and prioritize transparency.\n",502       "\n",503       "**Example application**:\n",504       "\n",505       "Suppose you are a manager at a tech company facing a dilemma where two conflicting principles come into play:\n",506       "\n",507       "1. **Profitability**: The company needs to meet quarterly profit targets to maintain its funding.\n",508       "2. **Environmental responsibility**: New research reveals a potential environmental impact of the company's manufacturing process if production is not scaled back.\n",509       "\n",510       "To resolve this conflict, you would:\n",511       "\n",512       "* Evaluate both principles' core values (profitability for the company vs. environmental responsibility).\n",513       "* Weigh the relative importance of each principle (assign a score: e.g., profitability 8/10 and environmental responsibility 9/10).\n",514       "* Consider mitigating factors, such as potential regulatory fines or reputational impact.\n",515       "* Seek alternative solutions, like exploring sustainable production methods or negotiating with suppliers.\n",516       "* Consult decision-making frameworks, such as consequentialism, to inform your prioritization.\n",517       "\n",518       "Ultimately, the chosen principle should prioritize fairness, justice, and long-term sustainability while maintaining consistency with organizational values."519      ],520      "text/plain": [521       "<IPython.core.display.Markdown object>"522      ]523     },524     "metadata": {},525     "output_type": "display_data"526    }527   ],528   "source": [529    "ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n",530    "model_name = \"llama3.2\"\n",531    "\n",532    "response = ollama.chat.completions.create(model=model_name, messages=messages)\n",533    "answer = response.choices[0].message.content\n",534    "\n",535    "display(Markdown(answer))\n",536    "competitors.append(model_name)\n",537    "answers.append(answer)"538   ]539  },540  {541   "cell_type": "code",542   "execution_count": 17,543   "metadata": {},544   "outputs": [545    {546     "name": "stdout",547     "output_type": "stream",548     "text": [549      "['gpt-4o-mini', 'claude-3-7-sonnet-latest', 'gemini-2.0-flash', 'llama3.2']\n",550      "['Approaching a complex ethical dilemma where two equally important principles conflict requires a careful and systematic approach. Here’s a step-by-step framework to guide this process:\\n\\n1. **Clarify the Principles**: Identify and articulate the two conflicting principles clearly. Understand their significance, context, and implications. For instance, these could be principles like justice vs. mercy or autonomy vs. beneficence.\\n\\n2. **Gather Relevant Information**: Collect all relevant facts, including the context of the situation, stakeholders involved, and potential consequences of adhering to or violating each principle. Understanding the specifics can often illuminate the implications of each option.\\n\\n3. **Consider Stakeholder Perspectives**: Evaluate how each principle affects different stakeholders. Who will be impacted by the decision? What are their values, rights, and needs? Engaging with the perspectives of those affected can provide valuable insights.\\n\\n4. **Apply Ethical Frameworks**: Utilize established ethical theories and frameworks to examine the dilemma. For example:\\n   - **Utilitarianism**: Focus on the consequences and seek to maximize overall happiness or reduce harm.\\n   - **Deontological Ethics**: Consider duties and rules, emphasizing the moral obligation to uphold certain principles.\\n   - **Virtue Ethics**: Reflect on the character traits that would be encouraged by each principle and what a virtuous person would choose.\\n\\n5. **Identify potential compromises or alternatives**: Explore if there are ways to honor both principles to some extent or find creative solutions that minimize the impact on either principle.\\n\\n6. **Evaluate Consequences**: Assess the potential short-term and long-term consequences of prioritizing one principle over the other. Consider the implications for trust, relationships, and ethical precedents.\\n\\n7. **Reflect on Intuition and Values**: Consider your own values and moral intuitions. While rational analysis is critical, ethical dilemmas often invoke strong personal feelings and beliefs.\\n\\n8. **Seek Input from Others**: Consult with trusted colleagues, mentors, or ethical boards. They may offer perspectives or insights you haven’t considered.\\n\\n9. **Make a Decision and Reflect**: After thorough deliberation, prioritize the principle that aligns best with your ethical reasoning and the information gathered. After making the decision, reflect on the outcome and be open to learning from the results.\\n\\n10. **Communicate Transparently**: Once a decision is reached, communicate it clearly and transparently to all stakeholders involved, explaining the reasoning behind the choice.\\n\\nUltimately, the criteria for prioritizing one principle over another might involve weighing the potential outcomes, considering long-term implications, valuing stakeholder wellbeing, and reflecting on fundamental ethical commitments. Remember, ethical dilemmas often don’t have clear \"right\" answers; the goal is to make the most considered decision possible, acknowledging the complexities involved.', \"# Approaching Ethical Dilemmas with Conflicting Principles\\n\\nWhen facing an ethical dilemma with two conflicting but equally important principles, I would approach it through several steps:\\n\\n1. **Clarify the principles and stakes** - Precisely identify what principles are in tension and who is affected\\n\\n2. **Consider multiple ethical frameworks** - Examine the situation through different lenses:\\n   - Consequentialist: What outcomes maximize wellbeing?\\n   - Deontological: What duties or rights are inviolable?\\n   - Virtue ethics: What would a person of good character do?\\n\\n3. **Explore compromise possibilities** - Can both principles be partially honored?\\n\\nFor prioritization, I would consider:\\n- The severity and distribution of potential harms\\n- Whether one principle serves as a foundation for the other\\n- Context-specific factors that might temporarily elevate one principle\\n- Stakeholder perspectives, especially from those most vulnerable\\n- Precedent and long-term implications of the decision\\n\\nThis process recognizes that there's rarely a perfect solution to genuine ethical dilemmas, but a thoughtful approach can lead to more justified and defensible decisions.\", 'Solving a complex ethical dilemma involving conflicting principles requires a systematic and thoughtful approach. Here\\'s a breakdown of how I would approach such a situation, including the criteria I\\'d use for prioritization:\\n\\n**1. Understanding the Dilemma:**\\n\\n*   **Identify the Stakeholders:** Who are all the individuals and groups affected by the situation? What are their perspectives, interests, and potential harms or benefits?\\n*   **Clearly Define the Conflicting Principles:** What are the specific ethical principles that are in conflict? (e.g., Autonomy vs. Beneficence, Justice vs. Loyalty, Honesty vs. Compassion).  Make sure these principles are well-defined and understood.\\n*   **Gather All Relevant Facts:** Collect as much information as possible about the situation.  Avoid making assumptions or relying on incomplete data.  Ensure the facts are accurate and unbiased.\\n*   **Analyze the Potential Consequences:** Consider the possible outcomes of different courses of action.  How would each option impact the stakeholders?  Think about both short-term and long-term consequences.\\n\\n**2. Applying Ethical Frameworks and Theories:**\\n\\n*   **Utilitarianism:**  This focuses on maximizing overall happiness or well-being.  Which action will produce the greatest good for the greatest number of people?  Difficulties:  Can be hard to predict consequences accurately; can potentially justify harming a minority for the benefit of the majority.\\n*   **Deontology (Kantian Ethics):**  This emphasizes duty and adherence to universal moral rules (e.g., always tell the truth, treat people as ends in themselves, not merely as means).  Which action is consistent with these duties?  Difficulties:  Can be inflexible and may lead to counterintuitive results in specific situations.\\n*   **Virtue Ethics:**  This focuses on developing and acting in accordance with virtuous character traits (e.g., honesty, compassion, courage, justice). What would a virtuous person do in this situation?  Difficulties: Can be subjective and culturally dependent on what are considered virtues.\\n*   **Care Ethics:** This emphasizes relationships, empathy, and the importance of caring for others, especially the vulnerable. Which action best supports the needs and well-being of those involved, particularly those who are most vulnerable? Difficulties: Can lead to bias towards close relationships and may not adequately address broader systemic issues.\\n\\n**3. Prioritization Criteria:**\\n\\nGiven that the principles are considered \"equally important,\" prioritization requires careful judgment. Here are criteria I\\'d use to help make that judgment:\\n\\n*   **Hierarchy of Principles (if applicable):**  While the initial premise is that they are *generally* equal, are there *specific circumstances* where one principle might inherently take precedence? Some ethical frameworks may provide a hierarchical structure (e.g., avoiding harm might generally outweigh promoting good, although not always). This is context dependent.\\n*   **Severity of Harm:**  Which principle, if violated, would cause the *most significant and irreversible harm* to stakeholders?  Minimizing harm is often a central consideration.\\n*   **Vulnerability:** Which principle best protects the most vulnerable stakeholders?  Those who are least able to protect themselves deserve special consideration.\\n*   **Reversibility of Consequences:**  Which action has consequences that are more easily reversed or mitigated if things go wrong?  Choosing options with more reversible outcomes can reduce risk.\\n*   **Justice and Fairness:**  Does one principle promote a more just and equitable outcome for all stakeholders involved?  This may involve considering historical injustices or systemic inequalities.\\n*   **Professional Codes and Legal Obligations:**  Are there any relevant professional codes of ethics or legal obligations that provide guidance? These should be considered as they might clarify obligations.\\n*   **Transparency and Justifiability:** Which decision can be most easily explained and justified to all stakeholders, even those who disagree with it?  Transparency builds trust and accountability.\\n*   **Long-Term vs. Short-Term Considerations:**  Is one principle more critical to uphold for the long-term well-being of the individuals, organization, or society involved?\\n*   **Consistency with Values:** Which action is most consistent with the core values of the individual, the organization, and the broader community?\\n\\n**4. Deliberation and Consultation:**\\n\\n*   **Seek Input from Others:** Consult with trusted colleagues, mentors, ethicists, or other relevant experts.  Getting diverse perspectives can help identify blind spots and improve the quality of the decision.\\n*   **Ethical Review Boards/Committees:** If available, present the dilemma to an ethical review board or committee for guidance and feedback.\\n*   **Reflect on Personal Biases:** Be aware of your own biases and how they might be influencing your judgment.\\n\\n**5. Making a Decision and Taking Action:**\\n\\n*   **Document the Reasoning:**  Carefully document the entire decision-making process, including the principles considered, the facts gathered, the consultations conducted, and the rationale for the final decision.  This documentation is crucial for accountability and transparency.\\n*   **Implement the Decision:**  Take action to implement the chosen course of action.\\n*   **Monitor and Evaluate:**  Monitor the outcomes of the decision and be prepared to adjust course if necessary. Evaluate whether the decision achieved the desired results and whether any unintended consequences occurred.\\n\\n**Example Scenario (Autonomy vs. Beneficence in Healthcare):**\\n\\nAn elderly patient with a terminal illness refuses a life-sustaining treatment that doctors believe could significantly extend their life.\\n\\n*   **Autonomy:** The patient has the right to make their own decisions about their medical care, even if those decisions are not in their best medical interest.\\n*   **Beneficence:** Doctors have a duty to act in the best interests of their patients and to promote their well-being.\\n\\nIn this case:\\n\\n1.  **Understand the Patient\\'s Reasoning:**  Explore the patient\\'s reasons for refusing treatment.  Are they based on informed understanding of the risks and benefits? Are there underlying fears or values driving their decision?\\n2.  **Assess Capacity:** Is the patient mentally competent to make this decision?\\n3.  **Consider Quality of Life:** What kind of life extension is being offered? Will it be a life filled with pain and suffering?  The patient\\'s definition of \"quality of life\" is paramount.\\n4.  **Apply Prioritization Criteria:**  While both principles are important, respecting the patient\\'s autonomy is typically given greater weight, *assuming* the patient is competent and informed. The severity of imposing unwanted treatment is high.\\n5.  **Outcome:** The doctor should respect the patient\\'s decision, providing palliative care to ensure their comfort and dignity. If the patient\\'s capacity is questionable, further evaluation is needed.\\n\\n**Key Considerations:**\\n\\n*   There is often no \"perfect\" solution in ethical dilemmas.  The goal is to make the best possible decision given the circumstances, based on a thorough and well-reasoned analysis.\\n*   Flexibility is important.  Be prepared to re-evaluate your decision if new information emerges or if the situation changes.\\n*   Learning from experience is crucial. Reflect on past ethical dilemmas to improve your decision-making abilities in the future.\\n*   Ethical decision-making is a continuous process, not a one-time event.\\n\\nBy following this structured approach, I would strive to make ethically sound decisions, even in the face of complex and conflicting principles.  The key is to be thoughtful, deliberate, and committed to acting in the best interests of all stakeholders involved, while respecting the inherent complexity and ambiguity of ethical decision-making.\\n', \"Approaching a complex ethical dilemma where two equally important principles conflict requires careful consideration, analysis, and evaluation of the situation. Here's a step-by-step framework to help guide decision-making:\\n\\n1. **Identify all relevant principles**: Clearly articulate both conflicting principles and identify their core values, interests, or stakeholders affected by each principle.\\n2. **Understand the context**: Gather as much information as possible about the situation, including its historical background, current circumstances, potential consequences, and any relevant laws, regulations, or guidelines.\\n3. **Analyze the conflict**: Examine how each principle interacts with the other, considering potential trade-offs, synergies, or mutually exclusive effects. Identify potential consequences of prioritizing one principle over the other.\\n4. **Evaluate the principles' core values**: Consider the fundamental values, interests, or goals underlying each principle. Ask yourself:\\n\\t* What are the underlying motivations and interests driving each principle?\\n\\t* Are they aligned with organizational, societal, or individual values?\\n5. **Consider mitigating factors**: Weigh any additional factors that may influence your decision, such as:\\n\\t* External pressures (e.g., regulatory requirements)\\n\\t* Internal dynamics (e.g., stakeholder concerns, team morale)\\n\\t* Historical precedents\\n6. **Weight the principles' importance**: Attempt to assign a relative weight or priority to each principle based on its core values and interests. Consider using a scale of 1-10 or a more nuanced ranking system.\\n7. **Consult decision-making frameworks**: Explore relevant ethical theories, such as consequentialism, deontology, or virtue ethics, which can provide guidance on resolving conflicts between principles.\\n8. **Seek alternative solutions**: Brainstorm possible compromises or creative solutions that balance both conflicting principles. Consider seeking input from diverse stakeholders, experts, or mentors.\\n9. **Justify your decision**: Clearly articulate the reasoning behind your chosen principle and prioritize approach. Be prepared to justify your decision in the face of potential criticisms.\\n\\n**Criteria for prioritizing principles**:\\n\\n1. **Consistency with organizational values**: Aligns with the organization's core mission, vision, and values.\\n2. **Impact on stakeholders**: Consider the interests, well-being, and rights of all relevant parties affected by each principle.\\n3. **Long-term consequences**: Prioritize principles that promote sustainability and long-term positive outcomes.\\n4. **Fairness and justice**: Strive to uphold fairness, equity, and justice in your decision-making process.\\n5. **Transparency and accountability**: Ensure clear explanations for your decision-making process and prioritize transparency.\\n\\n**Example application**:\\n\\nSuppose you are a manager at a tech company facing a dilemma where two conflicting principles come into play:\\n\\n1. **Profitability**: The company needs to meet quarterly profit targets to maintain its funding.\\n2. **Environmental responsibility**: New research reveals a potential environmental impact of the company's manufacturing process if production is not scaled back.\\n\\nTo resolve this conflict, you would:\\n\\n* Evaluate both principles' core values (profitability for the company vs. environmental responsibility).\\n* Weigh the relative importance of each principle (assign a score: e.g., profitability 8/10 and environmental responsibility 9/10).\\n* Consider mitigating factors, such as potential regulatory fines or reputational impact.\\n* Seek alternative solutions, like exploring sustainable production methods or negotiating with suppliers.\\n* Consult decision-making frameworks, such as consequentialism, to inform your prioritization.\\n\\nUltimately, the chosen principle should prioritize fairness, justice, and long-term sustainability while maintaining consistency with organizational values.\"]\n"551     ]552    }553   ],554   "source": [555    "# So where are we?\n",556    "\n",557    "print(competitors)\n",558    "print(answers)\n"559   ]560  },561  {562   "cell_type": "code",563   "execution_count": 18,564   "metadata": {},565   "outputs": [566    {567     "name": "stdout",568     "output_type": "stream",569     "text": [570      "Competitor: gpt-4o-mini\n",571      "\n",572      "Approaching a complex ethical dilemma where two equally important principles conflict requires a careful and systematic approach. Here’s a step-by-step framework to guide this process:\n",573      "\n",574      "1. **Clarify the Principles**: Identify and articulate the two conflicting principles clearly. Understand their significance, context, and implications. For instance, these could be principles like justice vs. mercy or autonomy vs. beneficence.\n",575      "\n",576      "2. **Gather Relevant Information**: Collect all relevant facts, including the context of the situation, stakeholders involved, and potential consequences of adhering to or violating each principle. Understanding the specifics can often illuminate the implications of each option.\n",577      "\n",578      "3. **Consider Stakeholder Perspectives**: Evaluate how each principle affects different stakeholders. Who will be impacted by the decision? What are their values, rights, and needs? Engaging with the perspectives of those affected can provide valuable insights.\n",579      "\n",580      "4. **Apply Ethical Frameworks**: Utilize established ethical theories and frameworks to examine the dilemma. For example:\n",581      "   - **Utilitarianism**: Focus on the consequences and seek to maximize overall happiness or reduce harm.\n",582      "   - **Deontological Ethics**: Consider duties and rules, emphasizing the moral obligation to uphold certain principles.\n",583      "   - **Virtue Ethics**: Reflect on the character traits that would be encouraged by each principle and what a virtuous person would choose.\n",584      "\n",585      "5. **Identify potential compromises or alternatives**: Explore if there are ways to honor both principles to some extent or find creative solutions that minimize the impact on either principle.\n",586      "\n",587      "6. **Evaluate Consequences**: Assess the potential short-term and long-term consequences of prioritizing one principle over the other. Consider the implications for trust, relationships, and ethical precedents.\n",588      "\n",589      "7. **Reflect on Intuition and Values**: Consider your own values and moral intuitions. While rational analysis is critical, ethical dilemmas often invoke strong personal feelings and beliefs.\n",590      "\n",591      "8. **Seek Input from Others**: Consult with trusted colleagues, mentors, or ethical boards. They may offer perspectives or insights you haven’t considered.\n",592      "\n",593      "9. **Make a Decision and Reflect**: After thorough deliberation, prioritize the principle that aligns best with your ethical reasoning and the information gathered. After making the decision, reflect on the outcome and be open to learning from the results.\n",594      "\n",595      "10. **Communicate Transparently**: Once a decision is reached, communicate it clearly and transparently to all stakeholders involved, explaining the reasoning behind the choice.\n",596      "\n",597      "Ultimately, the criteria for prioritizing one principle over another might involve weighing the potential outcomes, considering long-term implications, valuing stakeholder wellbeing, and reflecting on fundamental ethical commitments. Remember, ethical dilemmas often don’t have clear \"right\" answers; the goal is to make the most considered decision possible, acknowledging the complexities involved.\n",598      "Competitor: claude-3-7-sonnet-latest\n",599      "\n",600      "# Approaching Ethical Dilemmas with Conflicting Principles\n",601      "\n",602      "When facing an ethical dilemma with two conflicting but equally important principles, I would approach it through several steps:\n",603      "\n",604      "1. **Clarify the principles and stakes** - Precisely identify what principles are in tension and who is affected\n",605      "\n",606      "2. **Consider multiple ethical frameworks** - Examine the situation through different lenses:\n",607      "   - Consequentialist: What outcomes maximize wellbeing?\n",608      "   - Deontological: What duties or rights are inviolable?\n",609      "   - Virtue ethics: What would a person of good character do?\n",610      "\n",611      "3. **Explore compromise possibilities** - Can both principles be partially honored?\n",612      "\n",613      "For prioritization, I would consider:\n",614      "- The severity and distribution of potential harms\n",615      "- Whether one principle serves as a foundation for the other\n",616      "- Context-specific factors that might temporarily elevate one principle\n",617      "- Stakeholder perspectives, especially from those most vulnerable\n",618      "- Precedent and long-term implications of the decision\n",619      "\n",620      "This process recognizes that there's rarely a perfect solution to genuine ethical dilemmas, but a thoughtful approach can lead to more justified and defensible decisions.\n",621      "Competitor: gemini-2.0-flash\n",622      "\n",623      "Solving a complex ethical dilemma involving conflicting principles requires a systematic and thoughtful approach. Here's a breakdown of how I would approach such a situation, including the criteria I'd use for prioritization:\n",624      "\n",625      "**1. Understanding the Dilemma:**\n",626      "\n",627      "*   **Identify the Stakeholders:** Who are all the individuals and groups affected by the situation? What are their perspectives, interests, and potential harms or benefits?\n",628      "*   **Clearly Define the Conflicting Principles:** What are the specific ethical principles that are in conflict? (e.g., Autonomy vs. Beneficence, Justice vs. Loyalty, Honesty vs. Compassion).  Make sure these principles are well-defined and understood.\n",629      "*   **Gather All Relevant Facts:** Collect as much information as possible about the situation.  Avoid making assumptions or relying on incomplete data.  Ensure the facts are accurate and unbiased.\n",630      "*   **Analyze the Potential Consequences:** Consider the possible outcomes of different courses of action.  How would each option impact the stakeholders?  Think about both short-term and long-term consequences.\n",631      "\n",632      "**2. Applying Ethical Frameworks and Theories:**\n",633      "\n",634      "*   **Utilitarianism:**  This focuses on maximizing overall happiness or well-being.  Which action will produce the greatest good for the greatest number of people?  Difficulties:  Can be hard to predict consequences accurately; can potentially justify harming a minority for the benefit of the majority.\n",635      "*   **Deontology (Kantian Ethics):**  This emphasizes duty and adherence to universal moral rules (e.g., always tell the truth, treat people as ends in themselves, not merely as means).  Which action is consistent with these duties?  Difficulties:  Can be inflexible and may lead to counterintuitive results in specific situations.\n",636      "*   **Virtue Ethics:**  This focuses on developing and acting in accordance with virtuous character traits (e.g., honesty, compassion, courage, justice). What would a virtuous person do in this situation?  Difficulties: Can be subjective and culturally dependent on what are considered virtues.\n",637      "*   **Care Ethics:** This emphasizes relationships, empathy, and the importance of caring for others, especially the vulnerable. Which action best supports the needs and well-being of those involved, particularly those who are most vulnerable? Difficulties: Can lead to bias towards close relationships and may not adequately address broader systemic issues.\n",638      "\n",639      "**3. Prioritization Criteria:**\n",640      "\n",641      "Given that the principles are considered \"equally important,\" prioritization requires careful judgment. Here are criteria I'd use to help make that judgment:\n",642      "\n",643      "*   **Hierarchy of Principles (if applicable):**  While the initial premise is that they are *generally* equal, are there *specific circumstances* where one principle might inherently take precedence? Some ethical frameworks may provide a hierarchical structure (e.g., avoiding harm might generally outweigh promoting good, although not always). This is context dependent.\n",644      "*   **Severity of Harm:**  Which principle, if violated, would cause the *most significant and irreversible harm* to stakeholders?  Minimizing harm is often a central consideration.\n",645      "*   **Vulnerability:** Which principle best protects the most vulnerable stakeholders?  Those who are least able to protect themselves deserve special consideration.\n",646      "*   **Reversibility of Consequences:**  Which action has consequences that are more easily reversed or mitigated if things go wrong?  Choosing options with more reversible outcomes can reduce risk.\n",647      "*   **Justice and Fairness:**  Does one principle promote a more just and equitable outcome for all stakeholders involved?  This may involve considering historical injustices or systemic inequalities.\n",648      "*   **Professional Codes and Legal Obligations:**  Are there any relevant professional codes of ethics or legal obligations that provide guidance? These should be considered as they might clarify obligations.\n",649      "*   **Transparency and Justifiability:** Which decision can be most easily explained and justified to all stakeholders, even those who disagree with it?  Transparency builds trust and accountability.\n",650      "*   **Long-Term vs. Short-Term Considerations:**  Is one principle more critical to uphold for the long-term well-being of the individuals, organization, or society involved?\n",651      "*   **Consistency with Values:** Which action is most consistent with the core values of the individual, the organization, and the broader community?\n",652      "\n",653      "**4. Deliberation and Consultation:**\n",654      "\n",655      "*   **Seek Input from Others:** Consult with trusted colleagues, mentors, ethicists, or other relevant experts.  Getting diverse perspectives can help identify blind spots and improve the quality of the decision.\n",656      "*   **Ethical Review Boards/Committees:** If available, present the dilemma to an ethical review board or committee for guidance and feedback.\n",657      "*   **Reflect on Personal Biases:** Be aware of your own biases and how they might be influencing your judgment.\n",658      "\n",659      "**5. Making a Decision and Taking Action:**\n",660      "\n",661      "*   **Document the Reasoning:**  Carefully document the entire decision-making process, including the principles considered, the facts gathered, the consultations conducted, and the rationale for the final decision.  This documentation is crucial for accountability and transparency.\n",662      "*   **Implement the Decision:**  Take action to implement the chosen course of action.\n",663      "*   **Monitor and Evaluate:**  Monitor the outcomes of the decision and be prepared to adjust course if necessary. Evaluate whether the decision achieved the desired results and whether any unintended consequences occurred.\n",664      "\n",665      "**Example Scenario (Autonomy vs. Beneficence in Healthcare):**\n",666      "\n",667      "An elderly patient with a terminal illness refuses a life-sustaining treatment that doctors believe could significantly extend their life.\n",668      "\n",669      "*   **Autonomy:** The patient has the right to make their own decisions about their medical care, even if those decisions are not in their best medical interest.\n",670      "*   **Beneficence:** Doctors have a duty to act in the best interests of their patients and to promote their well-being.\n",671      "\n",672      "In this case:\n",673      "\n",674      "1.  **Understand the Patient's Reasoning:**  Explore the patient's reasons for refusing treatment.  Are they based on informed understanding of the risks and benefits? Are there underlying fears or values driving their decision?\n",675      "2.  **Assess Capacity:** Is the patient mentally competent to make this decision?\n",676      "3.  **Consider Quality of Life:** What kind of life extension is being offered? Will it be a life filled with pain and suffering?  The patient's definition of \"quality of life\" is paramount.\n",677      "4.  **Apply Prioritization Criteria:**  While both principles are important, respecting the patient's autonomy is typically given greater weight, *assuming* the patient is competent and informed. The severity of imposing unwanted treatment is high.\n",678      "5.  **Outcome:** The doctor should respect the patient's decision, providing palliative care to ensure their comfort and dignity. If the patient's capacity is questionable, further evaluation is needed.\n",679      "\n",680      "**Key Considerations:**\n",681      "\n",682      "*   There is often no \"perfect\" solution in ethical dilemmas.  The goal is to make the best possible decision given the circumstances, based on a thorough and well-reasoned analysis.\n",683      "*   Flexibility is important.  Be prepared to re-evaluate your decision if new information emerges or if the situation changes.\n",684      "*   Learning from experience is crucial. Reflect on past ethical dilemmas to improve your decision-making abilities in the future.\n",685      "*   Ethical decision-making is a continuous process, not a one-time event.\n",686      "\n",687      "By following this structured approach, I would strive to make ethically sound decisions, even in the face of complex and conflicting principles.  The key is to be thoughtful, deliberate, and committed to acting in the best interests of all stakeholders involved, while respecting the inherent complexity and ambiguity of ethical decision-making.\n",688      "\n",689      "Competitor: llama3.2\n",690      "\n",691      "Approaching a complex ethical dilemma where two equally important principles conflict requires careful consideration, analysis, and evaluation of the situation. Here's a step-by-step framework to help guide decision-making:\n",692      "\n",693      "1. **Identify all relevant principles**: Clearly articulate both conflicting principles and identify their core values, interests, or stakeholders affected by each principle.\n",694      "2. **Understand the context**: Gather as much information as possible about the situation, including its historical background, current circumstances, potential consequences, and any relevant laws, regulations, or guidelines.\n",695      "3. **Analyze the conflict**: Examine how each principle interacts with the other, considering potential trade-offs, synergies, or mutually exclusive effects. Identify potential consequences of prioritizing one principle over the other.\n",696      "4. **Evaluate the principles' core values**: Consider the fundamental values, interests, or goals underlying each principle. Ask yourself:\n",697      "\t* What are the underlying motivations and interests driving each principle?\n",698      "\t* Are they aligned with organizational, societal, or individual values?\n",699      "5. **Consider mitigating factors**: Weigh any additional factors that may influence your decision, such as:\n",700      "\t* External pressures (e.g., regulatory requirements)\n",701      "\t* Internal dynamics (e.g., stakeholder concerns, team morale)\n",702      "\t* Historical precedents\n",703      "6. **Weight the principles' importance**: Attempt to assign a relative weight or priority to each principle based on its core values and interests. Consider using a scale of 1-10 or a more nuanced ranking system.\n",704      "7. **Consult decision-making frameworks**: Explore relevant ethical theories, such as consequentialism, deontology, or virtue ethics, which can provide guidance on resolving conflicts between principles.\n",705      "8. **Seek alternative solutions**: Brainstorm possible compromises or creative solutions that balance both conflicting principles. Consider seeking input from diverse stakeholders, experts, or mentors.\n",706      "9. **Justify your decision**: Clearly articulate the reasoning behind your chosen principle and prioritize approach. Be prepared to justify your decision in the face of potential criticisms.\n",707      "\n",708      "**Criteria for prioritizing principles**:\n",709      "\n",710      "1. **Consistency with organizational values**: Aligns with the organization's core mission, vision, and values.\n",711      "2. **Impact on stakeholders**: Consider the interests, well-being, and rights of all relevant parties affected by each principle.\n",712      "3. **Long-term consequences**: Prioritize principles that promote sustainability and long-term positive outcomes.\n",713      "4. **Fairness and justice**: Strive to uphold fairness, equity, and justice in your decision-making process.\n",714      "5. **Transparency and accountability**: Ensure clear explanations for your decision-making process and prioritize transparency.\n",715      "\n",716      "**Example application**:\n",717      "\n",718      "Suppose you are a manager at a tech company facing a dilemma where two conflicting principles come into play:\n",719      "\n",720      "1. **Profitability**: The company needs to meet quarterly profit targets to maintain its funding.\n",721      "2. **Environmental responsibility**: New research reveals a potential environmental impact of the company's manufacturing process if production is not scaled back.\n",722      "\n",723      "To resolve this conflict, you would:\n",724      "\n",725      "* Evaluate both principles' core values (profitability for the company vs. environmental responsibility).\n",726      "* Weigh the relative importance of each principle (assign a score: e.g., profitability 8/10 and environmental responsibility 9/10).\n",727      "* Consider mitigating factors, such as potential regulatory fines or reputational impact.\n",728      "* Seek alternative solutions, like exploring sustainable production methods or negotiating with suppliers.\n",729      "* Consult decision-making frameworks, such as consequentialism, to inform your prioritization.\n",730      "\n",731      "Ultimately, the chosen principle should prioritize fairness, justice, and long-term sustainability while maintaining consistency with organizational values.\n"732     ]733    }734   ],735   "source": [736    "# It's nice to know how to use \"zip\"\n",737    "for competitor, answer in zip(competitors, answers):\n",738    "    print(f\"Competitor: {competitor}\\n\\n{answer}\")\n"739   ]740  },741  {742   "cell_type": "code",743   "execution_count": 20,744   "metadata": {},745   "outputs": [],746   "source": [747    "# Let's bring this together - note the use of \"enumerate\"\n",748    "\n",749    "together = \"\"\n",750    "for index, answer in enumerate(answers):\n",751    "    together += f\"# Response from competitor {index+1}\\n\\n\"\n",752    "    together += answer + \"\\n\\n\""753   ]754  },755  {756   "cell_type": "code",757   "execution_count": null,758   "metadata": {},759   "outputs": [],760   "source": [761    "print(together)"762   ]763  },764  {765   "cell_type": "code",766   "execution_count": 22,767   "metadata": {},768   "outputs": [],769   "source": [770    "judge = f\"\"\"You are judging a competition between {len(competitors)} competitors.\n",771    "Each model has been given this question:\n",772    "\n",773    "{question}\n",774    "\n",775    "Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\n",776    "Respond with JSON, and only JSON, with the following format:\n",777    "{{\"results\": [\"best competitor number\", \"second best competitor number\", \"third best competitor number\", ...]}}\n",778    "\n",779    "Here are the responses from each competitor:\n",780    "\n",781    "{together}\n",782    "\n",783    "Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\"\"\"\n"784   ]785  },786  {787   "cell_type": "code",788   "execution_count": null,789   "metadata": {},790   "outputs": [],791   "source": [792    "print(judge)"793   ]794  },795  {796   "cell_type": "code",797   "execution_count": 29,798   "metadata": {},799   "outputs": [],800   "source": [801    "judge_messages = [{\"role\": \"user\", \"content\": judge}]"802   ]803  },804  {805   "cell_type": "code",806   "execution_count": null,807   "metadata": {},808   "outputs": [],809   "source": [810    "# Judgement time!\n",811    "\n",812    "openai = OpenAI()\n",813    "response = openai.chat.completions.create(\n",814    "    model=\"o3-mini\",\n",815    "    messages=judge_messages,\n",816    ")\n",817    "results = response.choices[0].message.content\n",818    "print(results)\n"819   ]820  },821  {822   "cell_type": "code",823   "execution_count": null,824   "metadata": {},825   "outputs": [],826   "source": [827    "# OK let's turn this into results!\n",828    "\n",829    "results_dict = json.loads(results)\n",830    "ranks = results_dict[\"results\"]\n",831    "for index, result in enumerate(ranks):\n",832    "    competitor = competitors[int(result)-1]\n",833    "    print(f\"Rank {index+1}: {competitor}\")"834   ]835  },836  {837   "cell_type": "markdown",838   "metadata": {},839   "source": [840    "<table style=\"margin: 0; text-align: left; width:100%\">\n",841    "    <tr>\n",842    "        <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",843    "            <img src=\"../assets/exercise.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",844    "        </td>\n",845    "        <td>\n",846    "            <h2 style=\"color:#ff7800;\">Exercise</h2>\n",847    "            <span style=\"color:#ff7800;\">Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\n",848    "            </span>\n",849    "        </td>\n",850    "    </tr>\n",851    "</table>"852   ]853  },854  {855   "cell_type": "markdown",856   "metadata": {},857   "source": [858    "<table style=\"margin: 0; text-align: left; width:100%\">\n",859    "    <tr>\n",860    "        <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",861    "            <img src=\"../assets/business.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",862    "        </td>\n",863    "        <td>\n",864    "            <h2 style=\"color:#00bfff;\">Commercial implications</h2>\n",865    "            <span style=\"color:#00bfff;\">These kinds of patterns - to send a task to multiple models, and evaluate results,\n",866    "            are common where you need to improve the quality of your LLM response. This approach can be universally applied\n",867    "            to business projects where accuracy is critical.\n",868    "            </span>\n",869    "        </td>\n",870    "    </tr>\n",871    "</table>"872   ]873  }874 ],875 "metadata": {876  "kernelspec": {877   "display_name": "agents",878   "language": "python",879   "name": "python3"880  },881  "language_info": {882   "codemirror_mode": {883    "name": "ipython",884    "version": 3885   },886   "file_extension": ".py",887   "mimetype": "text/x-python",888   "name": "python",889   "nbconvert_exporter": "python",890   "pygments_lexer": "ipython3",891   "version": "3.12.11"892  }893 },894 "nbformat": 4,895 "nbformat_minor": 2896}897