{"repo": "aditi-kulkarni-pa/capstone", "files": {"1_foundations/2_lab2.ipynb": {"0face1b0ea857beca383312d012f635f47300156": {"t": 1785745509.9571722, "n": 15951, "h": "b9b73dfb3a3b188d", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Welcome to the Second Lab - Week 1, Day 3\\n\",\n \"\\n\",\n \"Today we will work with lots of models! This is a way to get comfortable with APIs.\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"
\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Important point - please read\\n\",\n \" 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, after watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.
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\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Start with imports - ask ChatGPT to explain any package that you don't know\\n\",\n \"\\n\",\n \"import os\\n\",\n \"import json\\n\",\n \"from dotenv import load_dotenv\\n\",\n \"from openai import OpenAI\\n\",\n \"from anthropic import Anthropic\\n\",\n \"from IPython.display import Markdown, display\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Always remember to do this!\\n\",\n \"load_dotenv(override=True)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Print the key prefixes to help with any debugging\\n\",\n \"\\n\",\n \"openai_api_key = os.getenv('OPENAI_API_KEY')\\n\",\n \"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\\n\",\n \"google_api_key = os.getenv('GOOGLE_API_KEY')\\n\",\n \"deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\\n\",\n \"groq_api_key = os.getenv('GROQ_API_KEY')\\n\",\n \"\\n\",\n \"if openai_api_key:\\n\",\n \" print(f\\\"OpenAI API Key exists and begins {openai_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"OpenAI API Key not set\\\")\\n\",\n \" \\n\",\n \"if anthropic_api_key:\\n\",\n \" print(f\\\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Anthropic API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if google_api_key:\\n\",\n \" print(f\\\"Google API Key exists and begins {google_api_key[:2]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Google API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if deepseek_api_key:\\n\",\n \" print(f\\\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"DeepSeek API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if groq_api_key:\\n\",\n \" print(f\\\"Groq API Key exists and begins {groq_api_key[:4]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Groq API Key not set (and this is optional)\\\")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"request = \\\"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \\\"\\n\",\n \"request += \\\"Answer only with the question, no explanation.\\\"\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": request}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"messages\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-5-mini\\\",\\n\",\n \" messages=messages,\\n\",\n \")\\n\",\n \"question = response.choices[0].message.content\\n\",\n \"print(question)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"competitors = []\\n\",\n \"answers = []\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": question}]\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Note - update since the videos\\n\",\n \"\\n\",\n \"I've updated the model names to use the latest models below, like GPT 5 and Claude Sonnet 4.5. It's worth noting that these models can be quite slow - like 1-2 minutes - but they do a great job! Feel free to switch them for faster models if you'd prefer, like the ones I use in the video.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# The API we know well\\n\",\n \"# I've updated this with the latest model, but it can take some time because it likes to think!\\n\",\n \"# Replace the model with gpt-4.1-mini if you'd prefer not to wait 1-2 mins\\n\",\n \"\\n\",\n \"model_name = \\\"gpt-5-nano\\\"\\n\",\n \"\\n\",\n \"response = openai.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Anthropic has a slightly different API, and Max Tokens is required\\n\",\n \"\\n\",\n \"model_name = \\\"claude-sonnet-4-5\\\"\\n\",\n \"\\n\",\n \"claude = Anthropic()\\n\",\n \"response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\\n\",\n \"answer = response.content[0].text\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"gemini = OpenAI(api_key=google_api_key, base_url=\\\"https://generativelanguage.googleapis.com/v1beta/openai/\\\")\\n\",\n \"model_name = \\\"gemini-2.5-flash\\\"\\n\",\n \"\\n\",\n \"response = gemini.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"deepseek = OpenAI(api_key=deepseek_api_key, base_url=\\\"https://api.deepseek.com/v1\\\")\\n\",\n \"model_name = \\\"deepseek-chat\\\"\\n\",\n \"\\n\",\n \"response = deepseek.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Updated with the latest Open Source model from OpenAI\\n\",\n \"\\n\",\n \"groq = OpenAI(api_key=groq_api_key, base_url=\\\"https://api.groq.com/openai/v1\\\")\\n\",\n \"model_name = \\\"openai/gpt-oss-120b\\\"\\n\",\n \"\\n\",\n \"response = groq.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\\n\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## For the next cell, we will use Ollama\\n\",\n \"\\n\",\n \"Ollama runs a local web service that gives an OpenAI compatible endpoint, \\n\",\n \"and runs models locally using high performance C++ code.\\n\",\n \"\\n\",\n \"If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\\n\",\n \"\\n\",\n \"After it's installed, you should be able to visit here: http://localhost:11434 and see the message \\\"Ollama is running\\\"\\n\",\n \"\\n\",\n \"You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\\\`) and run `ollama serve`\\n\",\n \"\\n\",\n \"Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\\n\",\n \"\\n\",\n \"`ollama pull ` downloads a model locally \\n\",\n \"`ollama ls` lists all the models you've downloaded \\n\",\n \"`ollama rm ` deletes the specified model from your downloads\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Super important - ignore me at your peril!\\n\",\n \" The model called llama3.3 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 llama3.2 or llama3.2:1b and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the the Ollama models page for a full list of models and sizes.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!ollama pull llama3.2\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\\n\",\n \"model_name = \\\"llama3.2\\\"\\n\",\n \"\\n\",\n \"response = ollama.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# So where are we?\\n\",\n \"\\n\",\n \"print(competitors)\\n\",\n \"print(answers)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# It's nice to know how to use \\\"zip\\\"\\n\",\n \"for competitor, answer in zip(competitors, answers):\\n\",\n \" print(f\\\"Competitor: {competitor}\\\\n\\\\n{answer}\\\")\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Let's bring this together - note the use of \\\"enumerate\\\"\\n\",\n \"\\n\",\n \"together = \\\"\\\"\\n\",\n \"for index, answer in enumerate(answers):\\n\",\n \" together += f\\\"# Response from competitor {index+1}\\\\n\\\\n\\\"\\n\",\n \" together += answer + \\\"\\\\n\\\\n\\\"\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(together)\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": []\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge = f\\\"\\\"\\\"You are judging a competition between {len(competitors)} competitors.\\n\",\n \"Each model has been given this question:\\n\",\n \"\\n\",\n \"{question}\\n\",\n \"\\n\",\n \"Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\\n\",\n \"Respond with JSON, and only JSON, with the following format:\\n\",\n \"{{\\\"results\\\": [\\\"best competitor number\\\", \\\"second best competitor number\\\", \\\"third best competitor number\\\", ...]}}\\n\",\n \"\\n\",\n \"Here are the responses from each competitor:\\n\",\n \"\\n\",\n \"{together}\\n\",\n \"\\n\",\n \"Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\\\"\\\"\\\"\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(judge)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge_messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": judge}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Judgement time!\\n\",\n \"\\n\",\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-5-mini\\\",\\n\",\n \" messages=judge_messages,\\n\",\n \")\\n\",\n \"results = response.choices[0].message.content\\n\",\n \"print(results)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# OK let's turn this into results!\\n\",\n \"\\n\",\n \"results_dict = json.loads(results)\\n\",\n \"ranks = results_dict[\\\"results\\\"]\\n\",\n \"for index, result in enumerate(ranks):\\n\",\n \" competitor = competitors[int(result)-1]\\n\",\n \" print(f\\\"Rank {index+1}: {competitor}\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Exercise\\n\",\n \" Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Commercial implications\\n\",\n \" These kinds of patterns - to send a task to multiple models, and evaluate results,\\n\",\n \" are common where you need to improve the quality of your LLM response. This approach can be universally applied\\n\",\n \" to business projects where accuracy is critical.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n }\n ],\n \"metadata\": {\n \"kernelspec\": {\n \"display_name\": \".venv\",\n \"language\": \"python\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"codemirror_mode\": {\n \"name\": \"ipython\",\n \"version\": 3\n },\n \"file_extension\": \".py\",\n \"mimetype\": \"text/x-python\",\n \"name\": \"python\",\n \"nbconvert_exporter\": \"python\",\n \"pygments_lexer\": \"ipython3\",\n \"version\": \"3.12.9\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"}, "2f66f318636c493e9af13603f2f687ad07ecf91c": {"t": 1785753748.5481405, "n": 15951, "h": "b9b73dfb3a3b188d", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Welcome to the Second Lab - Week 1, Day 3\\n\",\n \"\\n\",\n \"Today we will work with lots of models! This is a way to get comfortable with APIs.\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Important point - please read\\n\",\n \" 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, after watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.
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\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Start with imports - ask ChatGPT to explain any package that you don't know\\n\",\n \"\\n\",\n \"import os\\n\",\n \"import json\\n\",\n \"from dotenv import load_dotenv\\n\",\n \"from openai import OpenAI\\n\",\n \"from anthropic import Anthropic\\n\",\n \"from IPython.display import Markdown, display\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Always remember to do this!\\n\",\n \"load_dotenv(override=True)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Print the key prefixes to help with any debugging\\n\",\n \"\\n\",\n \"openai_api_key = os.getenv('OPENAI_API_KEY')\\n\",\n \"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\\n\",\n \"google_api_key = os.getenv('GOOGLE_API_KEY')\\n\",\n \"deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\\n\",\n \"groq_api_key = os.getenv('GROQ_API_KEY')\\n\",\n \"\\n\",\n \"if openai_api_key:\\n\",\n \" print(f\\\"OpenAI API Key exists and begins {openai_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"OpenAI API Key not set\\\")\\n\",\n \" \\n\",\n \"if anthropic_api_key:\\n\",\n \" print(f\\\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Anthropic API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if google_api_key:\\n\",\n \" print(f\\\"Google API Key exists and begins {google_api_key[:2]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Google API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if deepseek_api_key:\\n\",\n \" print(f\\\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"DeepSeek API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if groq_api_key:\\n\",\n \" print(f\\\"Groq API Key exists and begins {groq_api_key[:4]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Groq API Key not set (and this is optional)\\\")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"request = \\\"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \\\"\\n\",\n \"request += \\\"Answer only with the question, no explanation.\\\"\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": request}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"messages\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-5-mini\\\",\\n\",\n \" messages=messages,\\n\",\n \")\\n\",\n \"question = response.choices[0].message.content\\n\",\n \"print(question)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"competitors = []\\n\",\n \"answers = []\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": question}]\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Note - update since the videos\\n\",\n \"\\n\",\n \"I've updated the model names to use the latest models below, like GPT 5 and Claude Sonnet 4.5. It's worth noting that these models can be quite slow - like 1-2 minutes - but they do a great job! Feel free to switch them for faster models if you'd prefer, like the ones I use in the video.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# The API we know well\\n\",\n \"# I've updated this with the latest model, but it can take some time because it likes to think!\\n\",\n \"# Replace the model with gpt-4.1-mini if you'd prefer not to wait 1-2 mins\\n\",\n \"\\n\",\n \"model_name = \\\"gpt-5-nano\\\"\\n\",\n \"\\n\",\n \"response = openai.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Anthropic has a slightly different API, and Max Tokens is required\\n\",\n \"\\n\",\n \"model_name = \\\"claude-sonnet-4-5\\\"\\n\",\n \"\\n\",\n \"claude = Anthropic()\\n\",\n \"response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\\n\",\n \"answer = response.content[0].text\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"gemini = OpenAI(api_key=google_api_key, base_url=\\\"https://generativelanguage.googleapis.com/v1beta/openai/\\\")\\n\",\n \"model_name = \\\"gemini-2.5-flash\\\"\\n\",\n \"\\n\",\n \"response = gemini.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"deepseek = OpenAI(api_key=deepseek_api_key, base_url=\\\"https://api.deepseek.com/v1\\\")\\n\",\n \"model_name = \\\"deepseek-chat\\\"\\n\",\n \"\\n\",\n \"response = deepseek.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Updated with the latest Open Source model from OpenAI\\n\",\n \"\\n\",\n \"groq = OpenAI(api_key=groq_api_key, base_url=\\\"https://api.groq.com/openai/v1\\\")\\n\",\n \"model_name = \\\"openai/gpt-oss-120b\\\"\\n\",\n \"\\n\",\n \"response = groq.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\\n\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## For the next cell, we will use Ollama\\n\",\n \"\\n\",\n \"Ollama runs a local web service that gives an OpenAI compatible endpoint, \\n\",\n \"and runs models locally using high performance C++ code.\\n\",\n \"\\n\",\n \"If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\\n\",\n \"\\n\",\n \"After it's installed, you should be able to visit here: http://localhost:11434 and see the message \\\"Ollama is running\\\"\\n\",\n \"\\n\",\n \"You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\\\`) and run `ollama serve`\\n\",\n \"\\n\",\n \"Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\\n\",\n \"\\n\",\n \"`ollama pull ` downloads a model locally \\n\",\n \"`ollama ls` lists all the models you've downloaded \\n\",\n \"`ollama rm ` deletes the specified model from your downloads\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Super important - ignore me at your peril!\\n\",\n \" The model called llama3.3 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 llama3.2 or llama3.2:1b and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the the Ollama models page for a full list of models and sizes.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!ollama pull llama3.2\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\\n\",\n \"model_name = \\\"llama3.2\\\"\\n\",\n \"\\n\",\n \"response = ollama.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# So where are we?\\n\",\n \"\\n\",\n \"print(competitors)\\n\",\n \"print(answers)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# It's nice to know how to use \\\"zip\\\"\\n\",\n \"for competitor, answer in zip(competitors, answers):\\n\",\n \" print(f\\\"Competitor: {competitor}\\\\n\\\\n{answer}\\\")\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Let's bring this together - note the use of \\\"enumerate\\\"\\n\",\n \"\\n\",\n \"together = \\\"\\\"\\n\",\n \"for index, answer in enumerate(answers):\\n\",\n \" together += f\\\"# Response from competitor {index+1}\\\\n\\\\n\\\"\\n\",\n \" together += answer + \\\"\\\\n\\\\n\\\"\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(together)\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": []\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge = f\\\"\\\"\\\"You are judging a competition between {len(competitors)} competitors.\\n\",\n \"Each model has been given this question:\\n\",\n \"\\n\",\n \"{question}\\n\",\n \"\\n\",\n \"Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\\n\",\n \"Respond with JSON, and only JSON, with the following format:\\n\",\n \"{{\\\"results\\\": [\\\"best competitor number\\\", \\\"second best competitor number\\\", \\\"third best competitor number\\\", ...]}}\\n\",\n \"\\n\",\n \"Here are the responses from each competitor:\\n\",\n \"\\n\",\n \"{together}\\n\",\n \"\\n\",\n \"Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\\\"\\\"\\\"\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(judge)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge_messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": judge}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Judgement time!\\n\",\n \"\\n\",\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-5-mini\\\",\\n\",\n \" messages=judge_messages,\\n\",\n \")\\n\",\n \"results = response.choices[0].message.content\\n\",\n \"print(results)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# OK let's turn this into results!\\n\",\n \"\\n\",\n \"results_dict = json.loads(results)\\n\",\n \"ranks = results_dict[\\\"results\\\"]\\n\",\n \"for index, result in enumerate(ranks):\\n\",\n \" competitor = competitors[int(result)-1]\\n\",\n \" print(f\\\"Rank {index+1}: {competitor}\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Exercise\\n\",\n \" Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Commercial implications\\n\",\n \" These kinds of patterns - to send a task to multiple models, and evaluate results,\\n\",\n \" are common where you need to improve the quality of your LLM response. This approach can be universally applied\\n\",\n \" to business projects where accuracy is critical.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n }\n ],\n \"metadata\": {\n \"kernelspec\": {\n \"display_name\": \".venv\",\n \"language\": \"python\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"codemirror_mode\": {\n \"name\": \"ipython\",\n \"version\": 3\n },\n \"file_extension\": \".py\",\n \"mimetype\": \"text/x-python\",\n \"name\": \"python\",\n \"nbconvert_exporter\": \"python\",\n \"pygments_lexer\": \"ipython3\",\n \"version\": \"3.12.9\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"}, "96c44ddbbde14e8272edbfda0b9fc54b09df648b": {"t": 1785753750.997529, "n": 15186, "h": "8676a462e2b034de", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Welcome to the Second Lab - Week 1, Day 3\\n\",\n \"\\n\",\n \"Today we will work with lots of models! This is a way to get comfortable with APIs.\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Important point - please read\\n\",\n \" 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, after watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.
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\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Start with imports - ask ChatGPT to explain any package that you don't know\\n\",\n \"\\n\",\n \"import os\\n\",\n \"import json\\n\",\n \"from dotenv import load_dotenv\\n\",\n \"from openai import OpenAI\\n\",\n \"from anthropic import Anthropic\\n\",\n \"from IPython.display import Markdown, display\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Always remember to do this!\\n\",\n \"load_dotenv(override=True)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Print the key prefixes to help with any debugging\\n\",\n \"\\n\",\n \"openai_api_key = os.getenv('OPENAI_API_KEY')\\n\",\n \"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\\n\",\n \"google_api_key = os.getenv('GOOGLE_API_KEY')\\n\",\n \"deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\\n\",\n \"groq_api_key = os.getenv('GROQ_API_KEY')\\n\",\n \"\\n\",\n \"if openai_api_key:\\n\",\n \" print(f\\\"OpenAI API Key exists and begins {openai_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"OpenAI API Key not set\\\")\\n\",\n \" \\n\",\n \"if anthropic_api_key:\\n\",\n \" print(f\\\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Anthropic API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if google_api_key:\\n\",\n \" print(f\\\"Google API Key exists and begins {google_api_key[:2]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Google API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if deepseek_api_key:\\n\",\n \" print(f\\\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"DeepSeek API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if groq_api_key:\\n\",\n \" print(f\\\"Groq API Key exists and begins {groq_api_key[:4]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Groq API Key not set (and this is optional)\\\")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 4,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"request = \\\"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \\\"\\n\",\n \"request += \\\"Answer only with the question, no explanation.\\\"\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": request}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"messages\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-4o-mini\\\",\\n\",\n \" messages=messages,\\n\",\n \")\\n\",\n \"question = response.choices[0].message.content\\n\",\n \"print(question)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 7,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"competitors = []\\n\",\n \"answers = []\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": question}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# The API we know well\\n\",\n \"\\n\",\n \"model_name = \\\"gpt-4o-mini\\\"\\n\",\n \"\\n\",\n \"response = openai.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Anthropic has a slightly different API, and Max Tokens is required\\n\",\n \"\\n\",\n \"model_name = \\\"claude-3-7-sonnet-latest\\\"\\n\",\n \"\\n\",\n \"claude = Anthropic()\\n\",\n \"response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\\n\",\n \"answer = response.content[0].text\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"gemini = OpenAI(api_key=google_api_key, base_url=\\\"https://generativelanguage.googleapis.com/v1beta/openai/\\\")\\n\",\n \"model_name = \\\"gemini-2.0-flash\\\"\\n\",\n \"\\n\",\n \"response = gemini.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"deepseek = OpenAI(api_key=deepseek_api_key, base_url=\\\"https://api.deepseek.com/v1\\\")\\n\",\n \"model_name = \\\"deepseek-chat\\\"\\n\",\n \"\\n\",\n \"response = deepseek.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"groq = OpenAI(api_key=groq_api_key, base_url=\\\"https://api.groq.com/openai/v1\\\")\\n\",\n \"model_name = \\\"llama-3.3-70b-versatile\\\"\\n\",\n \"\\n\",\n \"response = groq.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\\n\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## For the next cell, we will use Ollama\\n\",\n \"\\n\",\n \"Ollama runs a local web service that gives an OpenAI compatible endpoint, \\n\",\n \"and runs models locally using high performance C++ code.\\n\",\n \"\\n\",\n \"If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\\n\",\n \"\\n\",\n \"After it's installed, you should be able to visit here: http://localhost:11434 and see the message \\\"Ollama is running\\\"\\n\",\n \"\\n\",\n \"You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\\\`) and run `ollama serve`\\n\",\n \"\\n\",\n \"Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\\n\",\n \"\\n\",\n \"`ollama pull ` downloads a model locally \\n\",\n \"`ollama ls` lists all the models you've downloaded \\n\",\n \"`ollama rm ` deletes the specified model from your downloads\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Super important - ignore me at your peril!\\n\",\n \" The model called llama3.3 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 llama3.2 or llama3.2:1b and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the the Ollama models page for a full list of models and sizes.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!ollama pull llama3.2\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\\n\",\n \"model_name = \\\"llama3.2\\\"\\n\",\n \"\\n\",\n \"response = ollama.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# So where are we?\\n\",\n \"\\n\",\n \"print(competitors)\\n\",\n \"print(answers)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# It's nice to know how to use \\\"zip\\\"\\n\",\n \"for competitor, answer in zip(competitors, answers):\\n\",\n \" print(f\\\"Competitor: {competitor}\\\\n\\\\n{answer}\\\")\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 20,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Let's bring this together - note the use of \\\"enumerate\\\"\\n\",\n \"\\n\",\n \"together = \\\"\\\"\\n\",\n \"for index, answer in enumerate(answers):\\n\",\n \" together += f\\\"# Response from competitor {index+1}\\\\n\\\\n\\\"\\n\",\n \" together += answer + \\\"\\\\n\\\\n\\\"\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(together)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 22,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge = f\\\"\\\"\\\"You are judging a competition between {len(competitors)} competitors.\\n\",\n \"Each model has been given this question:\\n\",\n \"\\n\",\n \"{question}\\n\",\n \"\\n\",\n \"Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\\n\",\n \"Respond with JSON, and only JSON, with the following format:\\n\",\n \"{{\\\"results\\\": [\\\"best competitor number\\\", \\\"second best competitor number\\\", \\\"third best competitor number\\\", ...]}}\\n\",\n \"\\n\",\n \"Here are the responses from each competitor:\\n\",\n \"\\n\",\n \"{together}\\n\",\n \"\\n\",\n \"Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\\\"\\\"\\\"\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(judge)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 29,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge_messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": judge}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Judgement time!\\n\",\n \"\\n\",\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"o3-mini\\\",\\n\",\n \" messages=judge_messages,\\n\",\n \")\\n\",\n \"results = response.choices[0].message.content\\n\",\n \"print(results)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# OK let's turn this into results!\\n\",\n \"\\n\",\n \"results_dict = json.loads(results)\\n\",\n \"ranks = results_dict[\\\"results\\\"]\\n\",\n \"for index, result in enumerate(ranks):\\n\",\n \" competitor = competitors[int(result)-1]\\n\",\n \" print(f\\\"Rank {index+1}: {competitor}\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Exercise\\n\",\n \" Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Commercial implications\\n\",\n \" These kinds of patterns - to send a task to multiple models, and evaluate results,\\n\",\n \" are common where you need to improve the quality of your LLM response. This approach can be universally applied\\n\",\n \" to business projects where accuracy is critical.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n }\n ],\n \"metadata\": {\n \"kernelspec\": {\n \"display_name\": \".venv\",\n \"language\": \"python\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"codemirror_mode\": {\n \"name\": \"ipython\",\n \"version\": 3\n },\n \"file_extension\": \".py\",\n \"mimetype\": \"text/x-python\",\n \"name\": \"python\",\n \"nbconvert_exporter\": \"python\",\n \"pygments_lexer\": \"ipython3\",\n \"version\": \"3.12.9\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"}, "b7b18ba79fa538b14a72e05f04a9a7c3ad268034": {"t": 1785753752.5809016, "n": 15186, "h": "9d726d1398db23f9", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Welcome to the Second Lab - Week 1, Day 3\\n\",\n \"\\n\",\n \"Today we will work with lots of models! This is a way to get comfortable with APIs.\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Important point - please read\\n\",\n \" 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, after watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.
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\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Start with imports - ask ChatGPT to explain any package that you don't know\\n\",\n \"\\n\",\n \"import os\\n\",\n \"import json\\n\",\n \"from dotenv import load_dotenv\\n\",\n \"from openai import OpenAI\\n\",\n \"from anthropic import Anthropic\\n\",\n \"from IPython.display import Markdown, display\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Always remember to do this!\\n\",\n \"load_dotenv(override=True)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Print the key prefixes to help with any debugging\\n\",\n \"\\n\",\n \"openai_api_key = os.getenv('OPENAI_API_KEY')\\n\",\n \"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\\n\",\n \"google_api_key = os.getenv('GOOGLE_API_KEY')\\n\",\n \"deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\\n\",\n \"groq_api_key = os.getenv('GROQ_API_KEY')\\n\",\n \"\\n\",\n \"if openai_api_key:\\n\",\n \" print(f\\\"OpenAI API Key exists and begins {openai_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"OpenAI API Key not set\\\")\\n\",\n \" \\n\",\n \"if anthropic_api_key:\\n\",\n \" print(f\\\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Anthropic API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if google_api_key:\\n\",\n \" print(f\\\"Google API Key exists and begins {google_api_key[:2]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Google API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if deepseek_api_key:\\n\",\n \" print(f\\\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"DeepSeek API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if groq_api_key:\\n\",\n \" print(f\\\"Groq API Key exists and begins {groq_api_key[:4]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Groq API Key not set (and this is optional)\\\")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 4,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"request = \\\"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \\\"\\n\",\n \"request += \\\"Answer only with the question, no explanation.\\\"\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": request}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"messages\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-4o-mini\\\",\\n\",\n \" messages=messages,\\n\",\n \")\\n\",\n \"question = response.choices[0].message.content\\n\",\n \"print(question)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 7,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"competitors = []\\n\",\n \"answers = []\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": question}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# The API we know well\\n\",\n \"\\n\",\n \"model_name = \\\"gpt-4o-mini\\\"\\n\",\n \"\\n\",\n \"response = openai.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Anthropic has a slightly different API, and Max Tokens is required\\n\",\n \"\\n\",\n \"model_name = \\\"claude-3-7-sonnet-latest\\\"\\n\",\n \"\\n\",\n \"claude = Anthropic()\\n\",\n \"response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\\n\",\n \"answer = response.content[0].text\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"gemini = OpenAI(api_key=google_api_key, base_url=\\\"https://generativelanguage.googleapis.com/v1beta/openai/\\\")\\n\",\n \"model_name = \\\"gemini-2.0-flash\\\"\\n\",\n \"\\n\",\n \"response = gemini.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"deepseek = OpenAI(api_key=deepseek_api_key, base_url=\\\"https://api.deepseek.com/v1\\\")\\n\",\n \"model_name = \\\"deepseek-chat\\\"\\n\",\n \"\\n\",\n \"response = deepseek.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"groq = OpenAI(api_key=groq_api_key, base_url=\\\"https://api.groq.com/openai/v1\\\")\\n\",\n \"model_name = \\\"llama-3.3-70b-versatile\\\"\\n\",\n \"\\n\",\n \"response = groq.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\\n\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## For the next cell, we will use Ollama\\n\",\n \"\\n\",\n \"Ollama runs a local web service that gives an OpenAI compatible endpoint, \\n\",\n \"and runs models locally using high performance C++ code.\\n\",\n \"\\n\",\n \"If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\\n\",\n \"\\n\",\n \"After it's installed, you should be able to visit here: http://localhost:11434 and see the message \\\"Ollama is running\\\"\\n\",\n \"\\n\",\n \"You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\\\`) and run `ollama serve`\\n\",\n \"\\n\",\n \"Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\\n\",\n \"\\n\",\n \"`ollama pull ` downloads a model locally \\n\",\n \"`ollama ls` lists all the models you've downloaded \\n\",\n \"`ollama rm ` deletes the specified model from your downloads\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Super important - ignore me at your peril!\\n\",\n \" The model called llama3.3 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 llama3.2 or llama3.2:1b and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the the Ollama models page for a full list of models and sizes.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!ollama pull llama3.2\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\\n\",\n \"model_name = \\\"llama3.2\\\"\\n\",\n \"\\n\",\n \"response = ollama.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# So where are we?\\n\",\n \"\\n\",\n \"print(competitors)\\n\",\n \"print(answers)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# It's nice to know how to use \\\"zip\\\"\\n\",\n \"for competitor, answer in zip(competitors, answers):\\n\",\n \" print(f\\\"Competitor: {competitor}\\\\n\\\\n{answer}\\\")\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 20,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Let's bring this together - note the use of \\\"enumerate\\\"\\n\",\n \"\\n\",\n \"together = \\\"\\\"\\n\",\n \"for index, answer in enumerate(answers):\\n\",\n \" together += f\\\"# Response from competitor {index+1}\\\\n\\\\n\\\"\\n\",\n \" together += answer + \\\"\\\\n\\\\n\\\"\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(together)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 22,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge = f\\\"\\\"\\\"You are judging a competition between {len(competitors)} competitors.\\n\",\n \"Each model has been given this question:\\n\",\n \"\\n\",\n \"{question}\\n\",\n \"\\n\",\n \"Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\\n\",\n \"Respond with JSON, and only JSON, with the following format:\\n\",\n \"{{\\\"results\\\": [\\\"best competitor number\\\", \\\"second best competitor number\\\", \\\"third best competitor number\\\", ...]}}\\n\",\n \"\\n\",\n \"Here are the responses from each competitor:\\n\",\n \"\\n\",\n \"{together}\\n\",\n \"\\n\",\n \"Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\\\"\\\"\\\"\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(judge)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 29,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge_messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": judge}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Judgement time!\\n\",\n \"\\n\",\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"o3-mini\\\",\\n\",\n \" messages=judge_messages,\\n\",\n \")\\n\",\n \"results = response.choices[0].message.content\\n\",\n \"print(results)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# OK let's turn this into results!\\n\",\n \"\\n\",\n \"results_dict = json.loads(results)\\n\",\n \"ranks = results_dict[\\\"results\\\"]\\n\",\n \"for index, result in enumerate(ranks):\\n\",\n \" competitor = competitors[int(result)-1]\\n\",\n \" print(f\\\"Rank {index+1}: {competitor}\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Exercise\\n\",\n \" Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Commercial implications\\n\",\n \" These kinds of patterns - to send a task to multiple models, and evaluate results,\\n\",\n \" and common where you need to improve the quality of your LLM response. This approach can be universally applied\\n\",\n \" to business projects where accuracy is critical.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n }\n ],\n \"metadata\": {\n \"kernelspec\": {\n \"display_name\": \".venv\",\n \"language\": \"python\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"codemirror_mode\": {\n \"name\": \"ipython\",\n \"version\": 3\n },\n \"file_extension\": \".py\",\n \"mimetype\": \"text/x-python\",\n \"name\": \"python\",\n \"nbconvert_exporter\": \"python\",\n \"pygments_lexer\": \"ipython3\",\n \"version\": \"3.12.9\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"}, "6e14bbda8858b9a7359de299584a8616c6fcdaa7": {"t": 1785753754.3371825, "n": 15258, "h": "223b2a3ed13d3e2b", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Welcome to the Second Lab - Week 1, Day 3\\n\",\n \"\\n\",\n \"Today we will work with lots of models! This is a way to get comfortable with APIs.\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Important point - please read\\n\",\n \" 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, after watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.
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\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Start with imports - ask ChatGPT to explain any package that you don't know\\n\",\n \"\\n\",\n \"import os\\n\",\n \"import json\\n\",\n \"from dotenv import load_dotenv\\n\",\n \"from openai import OpenAI\\n\",\n \"from anthropic import Anthropic\\n\",\n \"from IPython.display import Markdown, display\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Always remember to do this!\\n\",\n \"load_dotenv(override=True)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Print the key prefixes to help with any debugging\\n\",\n \"\\n\",\n \"openai_api_key = os.getenv('OPENAI_API_KEY')\\n\",\n \"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\\n\",\n \"google_api_key = os.getenv('GOOGLE_API_KEY')\\n\",\n \"deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\\n\",\n \"groq_api_key = os.getenv('GROQ_API_KEY')\\n\",\n \"\\n\",\n \"if openai_api_key:\\n\",\n \" print(f\\\"OpenAI API Key exists and begins {openai_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"OpenAI API Key not set\\\")\\n\",\n \" \\n\",\n \"if anthropic_api_key:\\n\",\n \" print(f\\\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Anthropic API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if google_api_key:\\n\",\n \" print(f\\\"Google API Key exists and begins {google_api_key[:2]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Google API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if deepseek_api_key:\\n\",\n \" print(f\\\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"DeepSeek API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if groq_api_key:\\n\",\n \" print(f\\\"Groq API Key exists and begins {groq_api_key[:4]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Groq API Key not set (and this is optional)\\\")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 4,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"request = \\\"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \\\"\\n\",\n \"request += \\\"Answer only with the question, no explanation.\\\"\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": request}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"messages\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-4o-mini\\\",\\n\",\n \" messages=messages,\\n\",\n \")\\n\",\n \"question = response.choices[0].message.content\\n\",\n \"print(question)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 7,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"competitors = []\\n\",\n \"answers = []\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": question}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# The API we know well\\n\",\n \"\\n\",\n \"model_name = \\\"gpt-4o-mini\\\"\\n\",\n \"\\n\",\n \"response = openai.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Anthropic has a slightly different API, and Max Tokens is required\\n\",\n \"\\n\",\n \"model_name = \\\"claude-3-7-sonnet-latest\\\"\\n\",\n \"\\n\",\n \"claude = Anthropic()\\n\",\n \"response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\\n\",\n \"answer = response.content[0].text\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"gemini = OpenAI(api_key=google_api_key, base_url=\\\"https://generativelanguage.googleapis.com/v1beta/openai/\\\")\\n\",\n \"model_name = \\\"gemini-2.0-flash\\\"\\n\",\n \"\\n\",\n \"response = gemini.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"deepseek = OpenAI(api_key=deepseek_api_key, base_url=\\\"https://api.deepseek.com/v1\\\")\\n\",\n \"model_name = \\\"deepseek-chat\\\"\\n\",\n \"\\n\",\n \"response = deepseek.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"groq = OpenAI(api_key=groq_api_key, base_url=\\\"https://api.groq.com/openai/v1\\\")\\n\",\n \"model_name = \\\"llama-3.3-70b-versatile\\\"\\n\",\n \"\\n\",\n \"response = groq.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\\n\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## For the next cell, we will use Ollama\\n\",\n \"\\n\",\n \"Ollama runs a local web service that gives an OpenAI compatible endpoint, \\n\",\n \"and runs models locally using high performance C++ code.\\n\",\n \"\\n\",\n \"If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\\n\",\n \"\\n\",\n \"After it's installed, you should be able to visit here: http://localhost:11434 and see the message \\\"Ollama is running\\\"\\n\",\n \"\\n\",\n \"You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\\\`) and run `ollama serve`\\n\",\n \"\\n\",\n \"Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\\n\",\n \"\\n\",\n \"`ollama pull ` downloads a model locally \\n\",\n \"`ollama ls` lists all the models you've downloaded \\n\",\n \"`ollama rm ` deletes the specified model from your downloads\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Super important - ignore me at your peril!\\n\",\n \" The model called llama3.3 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 llama3.2 or llama3.2:1b and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the the Ollama models page for a full list of models and sizes.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!ollama pull llama3.2\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\\n\",\n \"model_name = \\\"llama3.2\\\"\\n\",\n \"\\n\",\n \"response = ollama.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# So where are we?\\n\",\n \"\\n\",\n \"print(competitors)\\n\",\n \"print(answers)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# It's nice to know how to use \\\"zip\\\"\\n\",\n \"for competitor, answer in zip(competitors, answers):\\n\",\n \" print(f\\\"Competitor: {competitor}\\\\n\\\\n{answer}\\\")\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 20,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Let's bring this together - note the use of \\\"enumerate\\\"\\n\",\n \"\\n\",\n \"together = \\\"\\\"\\n\",\n \"for index, answer in enumerate(answers):\\n\",\n \" together += f\\\"# Response from competitor {index+1}\\\\n\\\\n\\\"\\n\",\n \" together += answer + \\\"\\\\n\\\\n\\\"\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(together)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 22,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge = f\\\"\\\"\\\"You are judging a competition between {len(competitors)} competitors.\\n\",\n \"Each model has been given this question:\\n\",\n \"\\n\",\n \"{question}\\n\",\n \"\\n\",\n \"Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\\n\",\n \"Respond with JSON, and only JSON, with the following format:\\n\",\n \"{{\\\"results\\\": [\\\"best competitor number\\\", \\\"second best competitor number\\\", \\\"third best competitor number\\\", ...]}}\\n\",\n \"\\n\",\n \"Here are the responses from each competitor:\\n\",\n \"\\n\",\n \"{together}\\n\",\n \"\\n\",\n \"Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\\\"\\\"\\\"\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"print(judge)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 29,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge_messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": judge}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Judgement time!\\n\",\n \"\\n\",\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"o3-mini\\\",\\n\",\n \" messages=judge_messages,\\n\",\n \")\\n\",\n \"results = response.choices[0].message.content\\n\",\n \"print(results)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# OK let's turn this into results!\\n\",\n \"\\n\",\n \"results_dict = json.loads(results)\\n\",\n \"ranks = results_dict[\\\"results\\\"]\\n\",\n \"for index, result in enumerate(ranks):\\n\",\n \" competitor = competitors[int(result)-1]\\n\",\n \" print(f\\\"Rank {index+1}: {competitor}\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Exercise\\n\",\n \" Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Commercial implications\\n\",\n \" These kinds of patterns - to send a task to multiple models, and evaluate results,\\n\",\n \" and common where you need to improve the quality of your LLM response. This approach can be universally applied\\n\",\n \" to business projects where accuracy is critical.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": []\n }\n ],\n \"metadata\": {\n \"kernelspec\": {\n \"display_name\": \".venv\",\n \"language\": \"python\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"codemirror_mode\": {\n \"name\": \"ipython\",\n \"version\": 3\n },\n \"file_extension\": \".py\",\n \"mimetype\": \"text/x-python\",\n \"name\": \"python\",\n \"nbconvert_exporter\": \"python\",\n \"pygments_lexer\": \"ipython3\",\n \"version\": \"3.12.9\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"}, "a3abbc38bca53c8cbd2608b9c425b72039fa674c": {"t": 1785753755.9079337, "n": 139634, "h": "66bd32d280f1d675", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Welcome to the Second Lab - Week 1, Day 3\\n\",\n \"\\n\",\n \"Today we will work with lots of models! This is a way to get comfortable with APIs.\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Important point - please read\\n\",\n \" 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, after watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.
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\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Start with imports - ask ChatGPT to explain any package that you don't know\\n\",\n \"\\n\",\n \"import os\\n\",\n \"import json\\n\",\n \"from dotenv import load_dotenv\\n\",\n \"from openai import OpenAI\\n\",\n \"from anthropic import Anthropic\\n\",\n \"from IPython.display import Markdown, display\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 2,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/plain\": [\n \"True\"\n ]\n },\n \"execution_count\": 2,\n \"metadata\": {},\n \"output_type\": \"execute_result\"\n }\n ],\n \"source\": [\n \"# Always remember to do this!\\n\",\n \"load_dotenv(override=True)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 3,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"OpenAI API Key exists and begins sk-proj-\\n\",\n \"Anthropic API Key exists and begins sk-ant-\\n\",\n \"Google API Key exists and begins AI\\n\",\n \"DeepSeek API Key exists and begins sk-\\n\",\n \"Groq API Key exists and begins gsk_\\n\"\n ]\n }\n ],\n \"source\": [\n \"# Print the key prefixes to help with any debugging\\n\",\n \"\\n\",\n \"openai_api_key = os.getenv('OPENAI_API_KEY')\\n\",\n \"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\\n\",\n \"google_api_key = os.getenv('GOOGLE_API_KEY')\\n\",\n \"deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\\n\",\n \"groq_api_key = os.getenv('GROQ_API_KEY')\\n\",\n \"\\n\",\n \"if openai_api_key:\\n\",\n \" print(f\\\"OpenAI API Key exists and begins {openai_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"OpenAI API Key not set\\\")\\n\",\n \" \\n\",\n \"if anthropic_api_key:\\n\",\n \" print(f\\\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Anthropic API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if google_api_key:\\n\",\n \" print(f\\\"Google API Key exists and begins {google_api_key[:2]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Google API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if deepseek_api_key:\\n\",\n \" print(f\\\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"DeepSeek API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if groq_api_key:\\n\",\n \" print(f\\\"Groq API Key exists and begins {groq_api_key[:4]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Groq API Key not set (and this is optional)\\\")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 4,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"request = \\\"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \\\"\\n\",\n \"request += \\\"Answer only with the question, no explanation.\\\"\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": request}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 5,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/plain\": [\n \"[{'role': 'user',\\n\",\n \" '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.'}]\"\n ]\n },\n \"execution_count\": 5,\n \"metadata\": {},\n \"output_type\": \"execute_result\"\n }\n ],\n \"source\": [\n \"messages\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 6,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"How would you analyze the ethical implications of using artificial intelligence in predictive policing, considering factors such as bias, accountability, and societal impact?\\n\"\n ]\n }\n ],\n \"source\": [\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-4o-mini\\\",\\n\",\n \" messages=messages,\\n\",\n \")\\n\",\n \"question = response.choices[0].message.content\\n\",\n \"print(question)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 7,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"competitors = []\\n\",\n \"answers = []\\n\",\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": question}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 8,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/markdown\": [\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves a multidimensional approach, considering several key factors such as bias, accountability, and societal impact. Here is a structured framework for this analysis:\\n\",\n \"\\n\",\n \"### 1. **Bias**\\n\",\n \"- **Data Bias**: AI systems rely heavily on historical data, which can perpetuate existing biases present in that data. If the data reflects racial or socioeconomic disparities in policing (e.g., over-policing in certain communities), the AI can reinforce these biases by predicting higher crime rates in these areas, leading to a self-fulfilling prophecy.\\n\",\n \"- **Algorithmic Bias**: The design of algorithms may also introduce biases if the developers unconsciously embed their own biases into the model. It's crucial to examine who created the algorithms and what assumptions were made during their development.\\n\",\n \"- **Mitigation Strategies**: Implementing techniques like algorithmic fairness audits and diverse training datasets can help reduce bias. Regularly assessing and adjusting algorithms as new data comes in can also be important.\\n\",\n \"\\n\",\n \"### 2. **Accountability**\\n\",\n \"- **Responsibility for Decisions**: If an AI system makes a predictive error that leads to wrongful arrest or civil liberties violations, determining accountability becomes complex. Clear lines of responsibility must be established—who is to blame: the algorithm developers, the law enforcement agency, or the policymakers who implemented the AI?\\n\",\n \"- **Transparency**: The opacity of many AI systems can hinder accountability. Stakeholders should demand transparency regarding how algorithms work and what data they use. This includes clear reporting on algorithmic decisions and their outcomes.\\n\",\n \"- **Human Oversight**: AI in predictive policing should not replace human judgment. Maintaining a system of human oversight can ensure that critical decisions, especially those impacting civil rights, are vetted through human interpretation and ethical considerations.\\n\",\n \"\\n\",\n \"### 3. **Societal Impact**\\n\",\n \"- **Civil Liberties**: The use of predictive policing can infringe on individuals' rights if it leads to excessive surveillance or profiling based on prediction rather than behavior. There's a fine line between preventive measures and civil rights violations.\\n\",\n \"- **Community Trust**: The deployment of AI in policing can affect community relationships with law enforcement. If communities perceive predictive policing as biased or unfair, it may lead to mistrust and decreased cooperation with law enforcement efforts.\\n\",\n \"- **Resource Allocation**: AI may skew resource allocation towards heavily policed communities, potentially exacerbating existing inequalities and diverting resources away from crime prevention and community investment in areas that may genuinely need them.\\n\",\n \"\\n\",\n \"### 4. **Ethical Frameworks**\\n\",\n \"- **Utilitarian Perspectives**: While predictive policing can potentially reduce crime detection and prevention, ethical evaluation must consider broader societal impacts, including the potential harm to affected communities.\\n\",\n \"- **Deontological Perspectives**: From a rights-based view, predictive policing must respect individual rights and freedoms, ensuring that law enforcement practices do not compromise the dignity and autonomy of individuals.\\n\",\n \"\\n\",\n \"### 5. **Public Engagement and Policy**\\n\",\n \"- **Community Consultation**: Engaging the community in discussions about the use of AI in policing can help bridge gaps and increase transparency. Public forums can provide a platform for feedback and concerns regarding predictive technologies.\\n\",\n \"- **Legislative Oversight**: Policymakers need to establish robust regulatory frameworks governing the use of predictive policing tools to safeguard civil liberties and ensure accountability and transparency throughout the process.\\n\",\n \"\\n\",\n \"### Conclusion\\n\",\n \"The ethical implications of using AI in predictive policing are complex and multifaceted. A careful, considerate approach that addresses bias, ensures accountability, and considers the broader societal impacts is critical for navigating the challenges posed by these technologies. Implementing safeguards and engaging with communities can help harness the benefits of AI while minimizing its harms.\"\n ],\n \"text/plain\": [\n \"\"\n ]\n },\n \"metadata\": {},\n \"output_type\": \"display_data\"\n }\n ],\n \"source\": [\n \"# The API we know well\\n\",\n \"\\n\",\n \"model_name = \\\"gpt-4o-mini\\\"\\n\",\n \"\\n\",\n \"response = openai.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 9,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/markdown\": [\n \"# Ethics of AI in Predictive Policing\\n\",\n \"\\n\",\n \"Predictive policing using AI presents several significant ethical challenges:\\n\",\n \"\\n\",\n \"## Bias Concerns\\n\",\n \"- Historical police data often contains embedded biases against marginalized communities\\n\",\n \"- Algorithms may perpetuate or amplify these biases, creating harmful feedback loops\\n\",\n \"- Risk of technological laundering where human bias is hidden behind a veneer of algorithmic objectivity\\n\",\n \"\\n\",\n \"## Accountability Issues\\n\",\n \"- \\\"Black box\\\" algorithms create difficulties in understanding how predictions are generated\\n\",\n \"- Unclear responsibility chains between developers, police departments, and officers\\n\",\n \"- Questions about legal recourse for citizens wrongfully targeted\\n\",\n \"\\n\",\n \"## Societal Impact\\n\",\n \"- Potential erosion of presumption of innocence by targeting individuals based on statistical likelihood\\n\",\n \"- Risk of creating over-policed communities, reinforcing existing social inequalities\\n\",\n \"- Privacy implications of mass data collection and algorithmic surveillance\\n\",\n \"\\n\",\n \"Ethical implementation would require transparent algorithms, diverse training data, human oversight, regular auditing for bias, and community involvement in deployment decisions. The core question remains whether we can balance potential public safety benefits against risks to civil liberties and equal protection.\"\n ],\n \"text/plain\": [\n \"\"\n ]\n },\n \"metadata\": {},\n \"output_type\": \"display_data\"\n }\n ],\n \"source\": [\n \"# Anthropic has a slightly different API, and Max Tokens is required\\n\",\n \"\\n\",\n \"model_name = \\\"claude-3-7-sonnet-latest\\\"\\n\",\n \"\\n\",\n \"claude = Anthropic()\\n\",\n \"response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\\n\",\n \"answer = response.content[0].text\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 10,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/markdown\": [\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires a multi-faceted approach, considering not only the technology itself but also the complex social context in which it is deployed. Here's a breakdown of the key factors:\\n\",\n \"\\n\",\n \"**1. Bias:**\\n\",\n \"\\n\",\n \"* **Source Data Bias:** AI models are trained on historical data, which often reflects existing biases within the criminal justice system. If past policing practices disproportionately targeted certain communities (e.g., due to racial profiling, socioeconomic disparities), the AI will learn and perpetuate these biases. This can lead to:\\n\",\n \" * **Reinforcement of Existing Inequalities:** Predictive policing may reinforce discriminatory practices by disproportionately focusing resources on marginalized communities, leading to more arrests, and further skewing the data the AI is trained on, creating a self-fulfilling prophecy.\\n\",\n \" * **Bias Amplification:** AI algorithms can amplify subtle biases in the data that might be difficult for humans to detect, leading to even more discriminatory outcomes.\\n\",\n \" * **Example:** If a system is trained on arrest data showing higher drug crime rates in a specific neighborhood, it may predict higher crime rates in that neighborhood even if the underlying reason is simply increased police presence and enforcement in that area.\\n\",\n \"\\n\",\n \"* **Algorithmic Bias:** Even with seemingly unbiased data, bias can creep into the algorithm itself during the design and development phase. This can be due to:\\n\",\n \" * **Feature Selection:** Choosing specific variables to predict crime may inadvertently correlate with protected characteristics (e.g., race, ethnicity, socioeconomic status).\\n\",\n \" * **Model Design:** Certain algorithms might inherently be more prone to bias than others.\\n\",\n \" * **Thresholds and Cutoffs:** Setting thresholds for risk scores or predicted crime rates can have disproportionate impacts on different groups.\\n\",\n \"\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Data Auditing and Cleaning:** Thoroughly examine and address biases in the training data. Consider oversampling underrepresented groups or using techniques to de-bias the data.\\n\",\n \" * **Algorithmic Auditing:** Regularly audit the algorithm's performance to identify and correct for bias. Use metrics beyond overall accuracy, focusing on fairness metrics (e.g., equal opportunity, predictive parity, calibration).\\n\",\n \" * **Transparency and Explainability:** Ensure that the AI's decision-making process is transparent and explainable to stakeholders, including law enforcement, policymakers, and the public. This allows for scrutiny and identification of potential biases.\\n\",\n \"\\n\",\n \"**2. Accountability:**\\n\",\n \"\\n\",\n \"* **Who is responsible when the AI makes a mistake?** Determining accountability is crucial. If an AI predicts a crime and leads to a wrongful arrest, who is held responsible: the software developer, the police department, the officer who acted on the prediction, or the AI itself (which is not a legal entity)?\\n\",\n \"* **Lack of Transparency:** \\\"Black box\\\" algorithms can make it difficult to understand how a prediction was made, making it challenging to hold anyone accountable for errors or biased outcomes.\\n\",\n \"* **Due Process Concerns:** Relying heavily on AI predictions can potentially undermine due process rights, as individuals may be targeted based on statistical probabilities rather than individual suspicion.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Clear Lines of Responsibility:** Establish clear lines of responsibility for the development, deployment, and use of predictive policing AI.\\n\",\n \" * **Human Oversight:** Implement robust human oversight mechanisms to ensure that AI predictions are not blindly followed but are carefully reviewed and validated by human officers.\\n\",\n \" * **Explainable AI (XAI):** Develop and deploy AI systems that provide explanations for their predictions, allowing for human review and scrutiny.\\n\",\n \" * **Independent Audits:** Conduct regular independent audits of predictive policing systems to assess their accuracy, fairness, and adherence to ethical guidelines.\\n\",\n \"\\n\",\n \"**3. Societal Impact:**\\n\",\n \"\\n\",\n \"* **Erosion of Trust:** If predictive policing systems are perceived as unfair or discriminatory, they can erode trust between law enforcement and the communities they serve.\\n\",\n \"* **Privacy Concerns:** Predictive policing systems often rely on the collection and analysis of large amounts of personal data, raising significant privacy concerns. The data used could include arrest records, social media activity, location data, and other sensitive information.\\n\",\n \"* **Chilling Effect on Civil Liberties:** The widespread use of predictive policing could have a chilling effect on civil liberties, as individuals may be less likely to engage in lawful activities if they fear being targeted by law enforcement based on AI predictions.\\n\",\n \"* **Displacement of Crime:** Predictive policing might simply displace crime to other areas, rather than addressing the root causes of crime.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Community Engagement:** Involve community members in the design, implementation, and oversight of predictive policing systems.\\n\",\n \" * **Data Minimization and Privacy Protection:** Collect and use only the data that is strictly necessary for predictive policing purposes and implement strong data security and privacy protections.\\n\",\n \" * **Transparency and Public Education:** Be transparent about how predictive policing systems work and how they are being used. Educate the public about the risks and benefits of these systems.\\n\",\n \" * **Focus on Root Causes of Crime:** Invest in programs that address the root causes of crime, such as poverty, inequality, and lack of opportunity. Predictive policing should not be seen as a substitute for addressing these underlying issues.\\n\",\n \"\\n\",\n \"**4. Alternatives and Trade-offs:**\\n\",\n \"\\n\",\n \"* **Consider non-AI solutions:** Before implementing AI-based predictive policing, explore alternative strategies, such as community policing, problem-oriented policing, and focused deterrence, which may be more effective and less ethically problematic.\\n\",\n \"* **Weigh the potential benefits against the risks:** Carefully weigh the potential benefits of predictive policing (e.g., crime reduction, improved resource allocation) against the risks of bias, accountability issues, and societal harm. Ensure that the benefits outweigh the risks.\\n\",\n \"\\n\",\n \"**Framework for Ethical Assessment:**\\n\",\n \"\\n\",\n \"A robust ethical assessment should involve the following steps:\\n\",\n \"\\n\",\n \"1. **Identify Stakeholders:** Determine who will be affected by the use of predictive policing (e.g., law enforcement, communities, individuals).\\n\",\n \"2. **Map Potential Harms and Benefits:** Identify the potential harms and benefits of the system for each stakeholder group.\\n\",\n \"3. **Evaluate Fairness and Equity:** Assess whether the system is fair and equitable to all stakeholders.\\n\",\n \"4. **Consider Privacy and Data Security:** Evaluate the system's privacy implications and data security measures.\\n\",\n \"5. **Determine Accountability Mechanisms:** Establish clear lines of responsibility and accountability for the system's performance.\\n\",\n \"6. **Engage Stakeholders in Dialogue:** Involve stakeholders in dialogue about the ethical implications of the system.\\n\",\n \"7. **Monitor and Evaluate:** Continuously monitor and evaluate the system's performance and ethical implications.\\n\",\n \"\\n\",\n \"In conclusion, using AI in predictive policing presents a complex web of ethical challenges. A responsible approach requires careful consideration of bias, accountability, and societal impact, along with proactive measures to mitigate risks and ensure fairness. Transparency, community engagement, and ongoing evaluation are essential to ensure that these systems are used in a way that promotes justice and protects civil liberties. Failure to do so risks perpetuating and amplifying existing inequalities within the criminal justice system.\\n\"\n ],\n \"text/plain\": [\n \"\"\n ]\n },\n \"metadata\": {},\n \"output_type\": \"display_data\"\n }\n ],\n \"source\": [\n \"gemini = OpenAI(api_key=google_api_key, base_url=\\\"https://generativelanguage.googleapis.com/v1beta/openai/\\\")\\n\",\n \"model_name = \\\"gemini-2.0-flash\\\"\\n\",\n \"\\n\",\n \"response = gemini.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 11,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/markdown\": [\n \"The use of artificial intelligence (AI) in **predictive policing** raises significant ethical concerns, particularly regarding **bias, accountability, and societal impact**. Below is a structured analysis of these implications:\\n\",\n \"\\n\",\n \"### **1. Bias in AI and Predictive Policing** \\n\",\n \"- **Data Bias**: Predictive policing relies on historical crime data, which may reflect **systemic biases** (e.g., over-policing in minority communities). If AI models are trained on biased data, they may perpetuate or even amplify discrimination. \\n\",\n \"- **Algorithmic Bias**: Machine learning models may reinforce **racial, socioeconomic, or geographic disparities** if not carefully audited. For example, facial recognition has been shown to misidentify people of color more frequently. \\n\",\n \"- **Feedback Loops**: If police are directed to patrol areas flagged by AI, they may record more crimes there, reinforcing the system’s bias in a self-fulfilling cycle. \\n\",\n \"\\n\",\n \"### **2. Accountability and Transparency** \\n\",\n \"- **Black Box Problem**: Many AI models (e.g., deep learning) are opaque, making it difficult to explain why certain predictions are made. This lack of transparency challenges **due process** and **legal accountability**. \\n\",\n \"- **Responsibility Gaps**: If an AI system leads to wrongful arrests or excessive policing, who is accountable—the developers, law enforcement, or policymakers? Clear **legal frameworks** are needed to assign liability. \\n\",\n \"- **Public Oversight**: Predictive policing tools are often proprietary, limiting public scrutiny. Ethical AI requires **auditability** and **community input** to prevent misuse. \\n\",\n \"\\n\",\n \"### **3. Societal Impact** \\n\",\n \"- **Erosion of Trust**: Over-reliance on AI may deepen distrust between law enforcement and marginalized communities, particularly if policing becomes more **automated and less human-judgment-based**. \\n\",\n \"- **Privacy Concerns**: Predictive policing often involves **mass surveillance** (e.g., facial recognition, social media monitoring), raising concerns about **civil liberties** and **government overreach**. \\n\",\n \"- **Reinforcement of Structural Inequities**: If AI disproportionately targets disadvantaged groups, it could worsen **social inequality** rather than reduce crime. \\n\",\n \"\\n\",\n \"### **Ethical Frameworks to Consider** \\n\",\n \"- **Fairness**: AI models should be rigorously tested for **disparate impact** and adjusted to minimize bias. \\n\",\n \"- **Transparency**: Policymakers should mandate **explainable AI** and public reporting on predictive policing outcomes. \\n\",\n \"- **Human Oversight**: AI should **assist**, not replace, human judgment in policing decisions. \\n\",\n \"- **Community Engagement**: Affected populations should have a say in whether and how predictive policing is deployed. \\n\",\n \"\\n\",\n \"### **Conclusion** \\n\",\n \"While AI in predictive policing has potential benefits (e.g., efficient resource allocation), its ethical risks—particularly bias, lack of accountability, and societal harm—demand **strict regulation, oversight, and continuous ethical evaluation**. A **human rights-centered approach** is essential to ensure AI serves justice rather than injustice. \\n\",\n \"\\n\",\n \"Would you like recommendations for mitigating these risks?\"\n ],\n \"text/plain\": [\n \"\"\n ]\n },\n \"metadata\": {},\n \"output_type\": \"display_data\"\n }\n ],\n \"source\": [\n \"deepseek = OpenAI(api_key=deepseek_api_key, base_url=\\\"https://api.deepseek.com/v1\\\")\\n\",\n \"model_name = \\\"deepseek-chat\\\"\\n\",\n \"\\n\",\n \"response = deepseek.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 12,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/markdown\": [\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves considering multiple factors, including bias, accountability, and societal impact. Here's a comprehensive analysis of the ethical implications:\\n\",\n \"\\n\",\n \"**Bias:**\\n\",\n \"\\n\",\n \"1. **Data quality and selection:** AI algorithms rely on historical crime data, which may reflect existing biases in policing practices, such as racial profiling. If the data is biased, the AI system will learn and replicate these biases, leading to discriminatory policing.\\n\",\n \"2. **Algorithmic bias:** AI algorithms can perpetuate and amplify existing biases if they are not designed to account for them. For example, if an algorithm is trained on data that overrepresents certain demographic groups, it may be more likely to predict crime in those areas.\\n\",\n \"3. **Lack of transparency:** Complex AI algorithms can be difficult to interpret, making it challenging to identify and address biases.\\n\",\n \"\\n\",\n \"**Accountability:**\\n\",\n \"\\n\",\n \"1. **Lack of human oversight:** AI-driven predictive policing may lead to decisions being made without human oversight, reducing accountability and increasing the risk of errors or biases.\\n\",\n \"2. **Automated decision-making:** AI systems may make decisions based on complex algorithms, making it difficult to identify who is responsible for those decisions.\\n\",\n \"3. **Audit trails:** Maintaining audit trails and logs of AI-driven decisions is crucial to ensure accountability and transparency.\\n\",\n \"\\n\",\n \"**Societal Impact:**\\n\",\n \"\\n\",\n \"1. **Stigma and marginalization:** Predictive policing may lead to increased surveillance and targeting of specific communities, exacerbating existing social and economic disparities.\\n\",\n \"2. **Disproportionate impact on vulnerable groups:** AI-driven predictive policing may disproportionately affect vulnerable groups, such as low-income communities, racial minorities, or those with mental health issues.\\n\",\n \"3. **Community trust and legitimacy:** The use of AI in predictive policing may erode community trust in law enforcement, particularly if the technology is perceived as biased or unaccountable.\\n\",\n \"\\n\",\n \"**Additional Considerations:**\\n\",\n \"\\n\",\n \"1. **Transparency and explainability:** Ensuring that AI-driven predictive policing is transparent, explainable, and interpretable is crucial to build trust and accountability.\\n\",\n \"2. **Human rights and due process:** AI-driven predictive policing must be designed to respect human rights and due process, including the right to privacy, freedom from discrimination, and the right to a fair trial.\\n\",\n \"3. **Regulatory frameworks:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing is essential to ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"**Mitigation Strategies:**\\n\",\n \"\\n\",\n \"1. **Data quality and validation:** Ensuring that data is accurate, complete, and unbiased is crucial to developing reliable AI systems.\\n\",\n \"2. **Algorithmic auditing and testing:** Regularly auditing and testing AI algorithms for bias and errors can help identify and address potential issues.\\n\",\n \"3. **Human oversight and review:** Implementing human oversight and review processes can help detect and correct errors or biases in AI-driven decisions.\\n\",\n \"4. **Community engagement and participation:** Engaging with communities and incorporating their concerns and feedback into the development and deployment of AI-driven predictive policing can help build trust and legitimacy.\\n\",\n \"5. **Regulatory frameworks and guidelines:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing can help ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"In conclusion, analyzing the ethical implications of using AI in predictive policing requires careful consideration of factors such as bias, accountability, and societal impact. By acknowledging these challenges and implementing mitigation strategies, law enforcement agencies can ensure that AI-driven predictive policing is used responsibly and ethically, promoting fairness, transparency, and accountability.\"\n ],\n \"text/plain\": [\n \"\"\n ]\n },\n \"metadata\": {},\n \"output_type\": \"display_data\"\n }\n ],\n \"source\": [\n \"groq = OpenAI(api_key=groq_api_key, base_url=\\\"https://api.groq.com/openai/v1\\\")\\n\",\n \"model_name = \\\"llama-3.3-70b-versatile\\\"\\n\",\n \"\\n\",\n \"response = groq.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\\n\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## For the next cell, we will use Ollama\\n\",\n \"\\n\",\n \"Ollama runs a local web service that gives an OpenAI compatible endpoint, \\n\",\n \"and runs models locally using high performance C++ code.\\n\",\n \"\\n\",\n \"If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\\n\",\n \"\\n\",\n \"After it's installed, you should be able to visit here: http://localhost:11434 and see the message \\\"Ollama is running\\\"\\n\",\n \"\\n\",\n \"You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\\\`) and run `ollama serve`\\n\",\n \"\\n\",\n \"Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\\n\",\n \"\\n\",\n \"`ollama pull ` downloads a model locally \\n\",\n \"`ollama ls` lists all the models you've downloaded \\n\",\n \"`ollama rm ` deletes the specified model from your downloads\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Super important - ignore me at your peril!\\n\",\n \" The model called llama3.3 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 llama3.2 or llama3.2:1b and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the the Ollama models page for a full list of models and sizes.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 13,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"\\u001b[?2026h\\u001b[?25l\\u001b[1Gpulling manifest ⠋ \\u001b[K\\u001b[?25h\\u001b[?2026l\\u001b[?2026h\\u001b[?25l\\u001b[1Gpulling manifest ⠙ \\u001b[K\\u001b[?25h\\u001b[?2026l\\u001b[?2026h\\u001b[?25l\\u001b[1Gpulling manifest ⠹ \\u001b[K\\u001b[?25h\\u001b[?2026l\\u001b[?2026h\\u001b[?25l\\u001b[1Gpulling manifest \\u001b[K\\n\",\n \"pulling dde5aa3fc5ff... 100% ▕████████████████▏ 2.0 GB \\u001b[K\\n\",\n \"pulling 966de95ca8a6... 100% ▕████████████████▏ 1.4 KB \\u001b[K\\n\",\n \"pulling fcc5a6bec9da... 100% ▕████████████████▏ 7.7 KB \\u001b[K\\n\",\n \"pulling a70ff7e570d9... 100% ▕████████████████▏ 6.0 KB \\u001b[K\\n\",\n \"pulling 56bb8bd477a5... 100% ▕████████████████▏ 96 B \\u001b[K\\n\",\n \"pulling 34bb5ab01051... 100% ▕████████████████▏ 561 B \\u001b[K\\n\",\n \"verifying sha256 digest \\u001b[K\\n\",\n \"writing manifest \\u001b[K\\n\",\n \"success \\u001b[K\\u001b[?25h\\u001b[?2026l\\n\"\n ]\n }\n ],\n \"source\": [\n \"!ollama pull llama3.2\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 14,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/markdown\": [\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires consideration of several key factors, including:\\n\",\n \"\\n\",\n \"1. **Bias**: AI algorithms can perpetuate existing biases in policing if they are trained on biased data sets. This can result in discriminatory practices, such as targeting certain communities or demographics.\\n\",\n \"2. **Accountability**: Predictive policing relies heavily on algorithms that may not be transparent or explainable. This lack of accountability raises concerns about the responsibility of policymakers and law enforcement officials for the decisions made by these systems.\\n\",\n \"3. **Societal impact**: The widespread use of predictive policing could exacerbate existing social inequalities, as it may lead to increased surveillance, harassment, and marginalization of already vulnerable populations.\\n\",\n \"\\n\",\n \"To address these ethical concerns, consider the following steps:\\n\",\n \"\\n\",\n \"1. **Data audits**: Conduct regular audits of data used to train AI algorithms, ensuring that they are diverse and representative of all communities.\\n\",\n \"2. **Algorithmic transparency**: Implement measures to provide transparent explanations for AI-driven decisions, enabling scrutiny and assessment.\\n\",\n \"3.\"\n ],\n \"text/plain\": [\n \"\"\n ]\n },\n \"metadata\": {},\n \"output_type\": \"display_data\"\n }\n ],\n \"source\": [\n \"ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\\n\",\n \"model_name = \\\"llama3.2\\\"\\n\",\n \"\\n\",\n \"response = ollama.chat.completions.create(model=model_name, messages=messages)\\n\",\n \"answer = response.choices[0].message.content\\n\",\n \"\\n\",\n \"display(Markdown(answer))\\n\",\n \"competitors.append(model_name)\\n\",\n \"answers.append(answer)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 15,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"['gpt-4o-mini', 'claude-3-7-sonnet-latest', 'gemini-2.0-flash', 'deepseek-chat', 'llama-3.3-70b-versatile', 'llama3.2']\\n\",\n \"[\\\"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves a multidimensional approach, considering several key factors such as bias, accountability, and societal impact. Here is a structured framework for this analysis:\\\\n\\\\n### 1. **Bias**\\\\n- **Data Bias**: AI systems rely heavily on historical data, which can perpetuate existing biases present in that data. If the data reflects racial or socioeconomic disparities in policing (e.g., over-policing in certain communities), the AI can reinforce these biases by predicting higher crime rates in these areas, leading to a self-fulfilling prophecy.\\\\n- **Algorithmic Bias**: The design of algorithms may also introduce biases if the developers unconsciously embed their own biases into the model. It's crucial to examine who created the algorithms and what assumptions were made during their development.\\\\n- **Mitigation Strategies**: Implementing techniques like algorithmic fairness audits and diverse training datasets can help reduce bias. Regularly assessing and adjusting algorithms as new data comes in can also be important.\\\\n\\\\n### 2. **Accountability**\\\\n- **Responsibility for Decisions**: If an AI system makes a predictive error that leads to wrongful arrest or civil liberties violations, determining accountability becomes complex. Clear lines of responsibility must be established—who is to blame: the algorithm developers, the law enforcement agency, or the policymakers who implemented the AI?\\\\n- **Transparency**: The opacity of many AI systems can hinder accountability. Stakeholders should demand transparency regarding how algorithms work and what data they use. This includes clear reporting on algorithmic decisions and their outcomes.\\\\n- **Human Oversight**: AI in predictive policing should not replace human judgment. Maintaining a system of human oversight can ensure that critical decisions, especially those impacting civil rights, are vetted through human interpretation and ethical considerations.\\\\n\\\\n### 3. **Societal Impact**\\\\n- **Civil Liberties**: The use of predictive policing can infringe on individuals' rights if it leads to excessive surveillance or profiling based on prediction rather than behavior. There's a fine line between preventive measures and civil rights violations.\\\\n- **Community Trust**: The deployment of AI in policing can affect community relationships with law enforcement. If communities perceive predictive policing as biased or unfair, it may lead to mistrust and decreased cooperation with law enforcement efforts.\\\\n- **Resource Allocation**: AI may skew resource allocation towards heavily policed communities, potentially exacerbating existing inequalities and diverting resources away from crime prevention and community investment in areas that may genuinely need them.\\\\n\\\\n### 4. **Ethical Frameworks**\\\\n- **Utilitarian Perspectives**: While predictive policing can potentially reduce crime detection and prevention, ethical evaluation must consider broader societal impacts, including the potential harm to affected communities.\\\\n- **Deontological Perspectives**: From a rights-based view, predictive policing must respect individual rights and freedoms, ensuring that law enforcement practices do not compromise the dignity and autonomy of individuals.\\\\n\\\\n### 5. **Public Engagement and Policy**\\\\n- **Community Consultation**: Engaging the community in discussions about the use of AI in policing can help bridge gaps and increase transparency. Public forums can provide a platform for feedback and concerns regarding predictive technologies.\\\\n- **Legislative Oversight**: Policymakers need to establish robust regulatory frameworks governing the use of predictive policing tools to safeguard civil liberties and ensure accountability and transparency throughout the process.\\\\n\\\\n### Conclusion\\\\nThe ethical implications of using AI in predictive policing are complex and multifaceted. A careful, considerate approach that addresses bias, ensures accountability, and considers the broader societal impacts is critical for navigating the challenges posed by these technologies. Implementing safeguards and engaging with communities can help harness the benefits of AI while minimizing its harms.\\\", '# Ethics of AI in Predictive Policing\\\\n\\\\nPredictive policing using AI presents several significant ethical challenges:\\\\n\\\\n## Bias Concerns\\\\n- Historical police data often contains embedded biases against marginalized communities\\\\n- Algorithms may perpetuate or amplify these biases, creating harmful feedback loops\\\\n- Risk of technological laundering where human bias is hidden behind a veneer of algorithmic objectivity\\\\n\\\\n## Accountability Issues\\\\n- \\\"Black box\\\" algorithms create difficulties in understanding how predictions are generated\\\\n- Unclear responsibility chains between developers, police departments, and officers\\\\n- Questions about legal recourse for citizens wrongfully targeted\\\\n\\\\n## Societal Impact\\\\n- Potential erosion of presumption of innocence by targeting individuals based on statistical likelihood\\\\n- Risk of creating over-policed communities, reinforcing existing social inequalities\\\\n- Privacy implications of mass data collection and algorithmic surveillance\\\\n\\\\nEthical implementation would require transparent algorithms, diverse training data, human oversight, regular auditing for bias, and community involvement in deployment decisions. The core question remains whether we can balance potential public safety benefits against risks to civil liberties and equal protection.', 'Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires a multi-faceted approach, considering not only the technology itself but also the complex social context in which it is deployed. Here\\\\'s a breakdown of the key factors:\\\\n\\\\n**1. Bias:**\\\\n\\\\n* **Source Data Bias:** AI models are trained on historical data, which often reflects existing biases within the criminal justice system. If past policing practices disproportionately targeted certain communities (e.g., due to racial profiling, socioeconomic disparities), the AI will learn and perpetuate these biases. This can lead to:\\\\n * **Reinforcement of Existing Inequalities:** Predictive policing may reinforce discriminatory practices by disproportionately focusing resources on marginalized communities, leading to more arrests, and further skewing the data the AI is trained on, creating a self-fulfilling prophecy.\\\\n * **Bias Amplification:** AI algorithms can amplify subtle biases in the data that might be difficult for humans to detect, leading to even more discriminatory outcomes.\\\\n * **Example:** If a system is trained on arrest data showing higher drug crime rates in a specific neighborhood, it may predict higher crime rates in that neighborhood even if the underlying reason is simply increased police presence and enforcement in that area.\\\\n\\\\n* **Algorithmic Bias:** Even with seemingly unbiased data, bias can creep into the algorithm itself during the design and development phase. This can be due to:\\\\n * **Feature Selection:** Choosing specific variables to predict crime may inadvertently correlate with protected characteristics (e.g., race, ethnicity, socioeconomic status).\\\\n * **Model Design:** Certain algorithms might inherently be more prone to bias than others.\\\\n * **Thresholds and Cutoffs:** Setting thresholds for risk scores or predicted crime rates can have disproportionate impacts on different groups.\\\\n\\\\n* **Mitigation Strategies:**\\\\n * **Data Auditing and Cleaning:** Thoroughly examine and address biases in the training data. Consider oversampling underrepresented groups or using techniques to de-bias the data.\\\\n * **Algorithmic Auditing:** Regularly audit the algorithm\\\\'s performance to identify and correct for bias. Use metrics beyond overall accuracy, focusing on fairness metrics (e.g., equal opportunity, predictive parity, calibration).\\\\n * **Transparency and Explainability:** Ensure that the AI\\\\'s decision-making process is transparent and explainable to stakeholders, including law enforcement, policymakers, and the public. This allows for scrutiny and identification of potential biases.\\\\n\\\\n**2. Accountability:**\\\\n\\\\n* **Who is responsible when the AI makes a mistake?** Determining accountability is crucial. If an AI predicts a crime and leads to a wrongful arrest, who is held responsible: the software developer, the police department, the officer who acted on the prediction, or the AI itself (which is not a legal entity)?\\\\n* **Lack of Transparency:** \\\"Black box\\\" algorithms can make it difficult to understand how a prediction was made, making it challenging to hold anyone accountable for errors or biased outcomes.\\\\n* **Due Process Concerns:** Relying heavily on AI predictions can potentially undermine due process rights, as individuals may be targeted based on statistical probabilities rather than individual suspicion.\\\\n* **Mitigation Strategies:**\\\\n * **Clear Lines of Responsibility:** Establish clear lines of responsibility for the development, deployment, and use of predictive policing AI.\\\\n * **Human Oversight:** Implement robust human oversight mechanisms to ensure that AI predictions are not blindly followed but are carefully reviewed and validated by human officers.\\\\n * **Explainable AI (XAI):** Develop and deploy AI systems that provide explanations for their predictions, allowing for human review and scrutiny.\\\\n * **Independent Audits:** Conduct regular independent audits of predictive policing systems to assess their accuracy, fairness, and adherence to ethical guidelines.\\\\n\\\\n**3. Societal Impact:**\\\\n\\\\n* **Erosion of Trust:** If predictive policing systems are perceived as unfair or discriminatory, they can erode trust between law enforcement and the communities they serve.\\\\n* **Privacy Concerns:** Predictive policing systems often rely on the collection and analysis of large amounts of personal data, raising significant privacy concerns. The data used could include arrest records, social media activity, location data, and other sensitive information.\\\\n* **Chilling Effect on Civil Liberties:** The widespread use of predictive policing could have a chilling effect on civil liberties, as individuals may be less likely to engage in lawful activities if they fear being targeted by law enforcement based on AI predictions.\\\\n* **Displacement of Crime:** Predictive policing might simply displace crime to other areas, rather than addressing the root causes of crime.\\\\n* **Mitigation Strategies:**\\\\n * **Community Engagement:** Involve community members in the design, implementation, and oversight of predictive policing systems.\\\\n * **Data Minimization and Privacy Protection:** Collect and use only the data that is strictly necessary for predictive policing purposes and implement strong data security and privacy protections.\\\\n * **Transparency and Public Education:** Be transparent about how predictive policing systems work and how they are being used. Educate the public about the risks and benefits of these systems.\\\\n * **Focus on Root Causes of Crime:** Invest in programs that address the root causes of crime, such as poverty, inequality, and lack of opportunity. Predictive policing should not be seen as a substitute for addressing these underlying issues.\\\\n\\\\n**4. Alternatives and Trade-offs:**\\\\n\\\\n* **Consider non-AI solutions:** Before implementing AI-based predictive policing, explore alternative strategies, such as community policing, problem-oriented policing, and focused deterrence, which may be more effective and less ethically problematic.\\\\n* **Weigh the potential benefits against the risks:** Carefully weigh the potential benefits of predictive policing (e.g., crime reduction, improved resource allocation) against the risks of bias, accountability issues, and societal harm. Ensure that the benefits outweigh the risks.\\\\n\\\\n**Framework for Ethical Assessment:**\\\\n\\\\nA robust ethical assessment should involve the following steps:\\\\n\\\\n1. **Identify Stakeholders:** Determine who will be affected by the use of predictive policing (e.g., law enforcement, communities, individuals).\\\\n2. **Map Potential Harms and Benefits:** Identify the potential harms and benefits of the system for each stakeholder group.\\\\n3. **Evaluate Fairness and Equity:** Assess whether the system is fair and equitable to all stakeholders.\\\\n4. **Consider Privacy and Data Security:** Evaluate the system\\\\'s privacy implications and data security measures.\\\\n5. **Determine Accountability Mechanisms:** Establish clear lines of responsibility and accountability for the system\\\\'s performance.\\\\n6. **Engage Stakeholders in Dialogue:** Involve stakeholders in dialogue about the ethical implications of the system.\\\\n7. **Monitor and Evaluate:** Continuously monitor and evaluate the system\\\\'s performance and ethical implications.\\\\n\\\\nIn conclusion, using AI in predictive policing presents a complex web of ethical challenges. A responsible approach requires careful consideration of bias, accountability, and societal impact, along with proactive measures to mitigate risks and ensure fairness. Transparency, community engagement, and ongoing evaluation are essential to ensure that these systems are used in a way that promotes justice and protects civil liberties. Failure to do so risks perpetuating and amplifying existing inequalities within the criminal justice system.\\\\n', 'The use of artificial intelligence (AI) in **predictive policing** raises significant ethical concerns, particularly regarding **bias, accountability, and societal impact**. Below is a structured analysis of these implications:\\\\n\\\\n### **1. Bias in AI and Predictive Policing** \\\\n- **Data Bias**: Predictive policing relies on historical crime data, which may reflect **systemic biases** (e.g., over-policing in minority communities). If AI models are trained on biased data, they may perpetuate or even amplify discrimination. \\\\n- **Algorithmic Bias**: Machine learning models may reinforce **racial, socioeconomic, or geographic disparities** if not carefully audited. For example, facial recognition has been shown to misidentify people of color more frequently. \\\\n- **Feedback Loops**: If police are directed to patrol areas flagged by AI, they may record more crimes there, reinforcing the system’s bias in a self-fulfilling cycle. \\\\n\\\\n### **2. Accountability and Transparency** \\\\n- **Black Box Problem**: Many AI models (e.g., deep learning) are opaque, making it difficult to explain why certain predictions are made. This lack of transparency challenges **due process** and **legal accountability**. \\\\n- **Responsibility Gaps**: If an AI system leads to wrongful arrests or excessive policing, who is accountable—the developers, law enforcement, or policymakers? Clear **legal frameworks** are needed to assign liability. \\\\n- **Public Oversight**: Predictive policing tools are often proprietary, limiting public scrutiny. Ethical AI requires **auditability** and **community input** to prevent misuse. \\\\n\\\\n### **3. Societal Impact** \\\\n- **Erosion of Trust**: Over-reliance on AI may deepen distrust between law enforcement and marginalized communities, particularly if policing becomes more **automated and less human-judgment-based**. \\\\n- **Privacy Concerns**: Predictive policing often involves **mass surveillance** (e.g., facial recognition, social media monitoring), raising concerns about **civil liberties** and **government overreach**. \\\\n- **Reinforcement of Structural Inequities**: If AI disproportionately targets disadvantaged groups, it could worsen **social inequality** rather than reduce crime. \\\\n\\\\n### **Ethical Frameworks to Consider** \\\\n- **Fairness**: AI models should be rigorously tested for **disparate impact** and adjusted to minimize bias. \\\\n- **Transparency**: Policymakers should mandate **explainable AI** and public reporting on predictive policing outcomes. \\\\n- **Human Oversight**: AI should **assist**, not replace, human judgment in policing decisions. \\\\n- **Community Engagement**: Affected populations should have a say in whether and how predictive policing is deployed. \\\\n\\\\n### **Conclusion** \\\\nWhile AI in predictive policing has potential benefits (e.g., efficient resource allocation), its ethical risks—particularly bias, lack of accountability, and societal harm—demand **strict regulation, oversight, and continuous ethical evaluation**. A **human rights-centered approach** is essential to ensure AI serves justice rather than injustice. \\\\n\\\\nWould you like recommendations for mitigating these risks?', \\\"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves considering multiple factors, including bias, accountability, and societal impact. Here's a comprehensive analysis of the ethical implications:\\\\n\\\\n**Bias:**\\\\n\\\\n1. **Data quality and selection:** AI algorithms rely on historical crime data, which may reflect existing biases in policing practices, such as racial profiling. If the data is biased, the AI system will learn and replicate these biases, leading to discriminatory policing.\\\\n2. **Algorithmic bias:** AI algorithms can perpetuate and amplify existing biases if they are not designed to account for them. For example, if an algorithm is trained on data that overrepresents certain demographic groups, it may be more likely to predict crime in those areas.\\\\n3. **Lack of transparency:** Complex AI algorithms can be difficult to interpret, making it challenging to identify and address biases.\\\\n\\\\n**Accountability:**\\\\n\\\\n1. **Lack of human oversight:** AI-driven predictive policing may lead to decisions being made without human oversight, reducing accountability and increasing the risk of errors or biases.\\\\n2. **Automated decision-making:** AI systems may make decisions based on complex algorithms, making it difficult to identify who is responsible for those decisions.\\\\n3. **Audit trails:** Maintaining audit trails and logs of AI-driven decisions is crucial to ensure accountability and transparency.\\\\n\\\\n**Societal Impact:**\\\\n\\\\n1. **Stigma and marginalization:** Predictive policing may lead to increased surveillance and targeting of specific communities, exacerbating existing social and economic disparities.\\\\n2. **Disproportionate impact on vulnerable groups:** AI-driven predictive policing may disproportionately affect vulnerable groups, such as low-income communities, racial minorities, or those with mental health issues.\\\\n3. **Community trust and legitimacy:** The use of AI in predictive policing may erode community trust in law enforcement, particularly if the technology is perceived as biased or unaccountable.\\\\n\\\\n**Additional Considerations:**\\\\n\\\\n1. **Transparency and explainability:** Ensuring that AI-driven predictive policing is transparent, explainable, and interpretable is crucial to build trust and accountability.\\\\n2. **Human rights and due process:** AI-driven predictive policing must be designed to respect human rights and due process, including the right to privacy, freedom from discrimination, and the right to a fair trial.\\\\n3. **Regulatory frameworks:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing is essential to ensure that the technology is used responsibly and ethically.\\\\n\\\\n**Mitigation Strategies:**\\\\n\\\\n1. **Data quality and validation:** Ensuring that data is accurate, complete, and unbiased is crucial to developing reliable AI systems.\\\\n2. **Algorithmic auditing and testing:** Regularly auditing and testing AI algorithms for bias and errors can help identify and address potential issues.\\\\n3. **Human oversight and review:** Implementing human oversight and review processes can help detect and correct errors or biases in AI-driven decisions.\\\\n4. **Community engagement and participation:** Engaging with communities and incorporating their concerns and feedback into the development and deployment of AI-driven predictive policing can help build trust and legitimacy.\\\\n5. **Regulatory frameworks and guidelines:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing can help ensure that the technology is used responsibly and ethically.\\\\n\\\\nIn conclusion, analyzing the ethical implications of using AI in predictive policing requires careful consideration of factors such as bias, accountability, and societal impact. By acknowledging these challenges and implementing mitigation strategies, law enforcement agencies can ensure that AI-driven predictive policing is used responsibly and ethically, promoting fairness, transparency, and accountability.\\\", 'Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires consideration of several key factors, including:\\\\n\\\\n1. **Bias**: AI algorithms can perpetuate existing biases in policing if they are trained on biased data sets. This can result in discriminatory practices, such as targeting certain communities or demographics.\\\\n2. **Accountability**: Predictive policing relies heavily on algorithms that may not be transparent or explainable. This lack of accountability raises concerns about the responsibility of policymakers and law enforcement officials for the decisions made by these systems.\\\\n3. **Societal impact**: The widespread use of predictive policing could exacerbate existing social inequalities, as it may lead to increased surveillance, harassment, and marginalization of already vulnerable populations.\\\\n\\\\nTo address these ethical concerns, consider the following steps:\\\\n\\\\n1. **Data audits**: Conduct regular audits of data used to train AI algorithms, ensuring that they are diverse and representative of all communities.\\\\n2. **Algorithmic transparency**: Implement measures to provide transparent explanations for AI-driven decisions, enabling scrutiny and assessment.\\\\n3.']\\n\"\n ]\n }\n ],\n \"source\": [\n \"# So where are we?\\n\",\n \"\\n\",\n \"print(competitors)\\n\",\n \"print(answers)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 16,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Competitor: gpt-4o-mini\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves a multidimensional approach, considering several key factors such as bias, accountability, and societal impact. Here is a structured framework for this analysis:\\n\",\n \"\\n\",\n \"### 1. **Bias**\\n\",\n \"- **Data Bias**: AI systems rely heavily on historical data, which can perpetuate existing biases present in that data. If the data reflects racial or socioeconomic disparities in policing (e.g., over-policing in certain communities), the AI can reinforce these biases by predicting higher crime rates in these areas, leading to a self-fulfilling prophecy.\\n\",\n \"- **Algorithmic Bias**: The design of algorithms may also introduce biases if the developers unconsciously embed their own biases into the model. It's crucial to examine who created the algorithms and what assumptions were made during their development.\\n\",\n \"- **Mitigation Strategies**: Implementing techniques like algorithmic fairness audits and diverse training datasets can help reduce bias. Regularly assessing and adjusting algorithms as new data comes in can also be important.\\n\",\n \"\\n\",\n \"### 2. **Accountability**\\n\",\n \"- **Responsibility for Decisions**: If an AI system makes a predictive error that leads to wrongful arrest or civil liberties violations, determining accountability becomes complex. Clear lines of responsibility must be established—who is to blame: the algorithm developers, the law enforcement agency, or the policymakers who implemented the AI?\\n\",\n \"- **Transparency**: The opacity of many AI systems can hinder accountability. Stakeholders should demand transparency regarding how algorithms work and what data they use. This includes clear reporting on algorithmic decisions and their outcomes.\\n\",\n \"- **Human Oversight**: AI in predictive policing should not replace human judgment. Maintaining a system of human oversight can ensure that critical decisions, especially those impacting civil rights, are vetted through human interpretation and ethical considerations.\\n\",\n \"\\n\",\n \"### 3. **Societal Impact**\\n\",\n \"- **Civil Liberties**: The use of predictive policing can infringe on individuals' rights if it leads to excessive surveillance or profiling based on prediction rather than behavior. There's a fine line between preventive measures and civil rights violations.\\n\",\n \"- **Community Trust**: The deployment of AI in policing can affect community relationships with law enforcement. If communities perceive predictive policing as biased or unfair, it may lead to mistrust and decreased cooperation with law enforcement efforts.\\n\",\n \"- **Resource Allocation**: AI may skew resource allocation towards heavily policed communities, potentially exacerbating existing inequalities and diverting resources away from crime prevention and community investment in areas that may genuinely need them.\\n\",\n \"\\n\",\n \"### 4. **Ethical Frameworks**\\n\",\n \"- **Utilitarian Perspectives**: While predictive policing can potentially reduce crime detection and prevention, ethical evaluation must consider broader societal impacts, including the potential harm to affected communities.\\n\",\n \"- **Deontological Perspectives**: From a rights-based view, predictive policing must respect individual rights and freedoms, ensuring that law enforcement practices do not compromise the dignity and autonomy of individuals.\\n\",\n \"\\n\",\n \"### 5. **Public Engagement and Policy**\\n\",\n \"- **Community Consultation**: Engaging the community in discussions about the use of AI in policing can help bridge gaps and increase transparency. Public forums can provide a platform for feedback and concerns regarding predictive technologies.\\n\",\n \"- **Legislative Oversight**: Policymakers need to establish robust regulatory frameworks governing the use of predictive policing tools to safeguard civil liberties and ensure accountability and transparency throughout the process.\\n\",\n \"\\n\",\n \"### Conclusion\\n\",\n \"The ethical implications of using AI in predictive policing are complex and multifaceted. A careful, considerate approach that addresses bias, ensures accountability, and considers the broader societal impacts is critical for navigating the challenges posed by these technologies. Implementing safeguards and engaging with communities can help harness the benefits of AI while minimizing its harms.\\n\",\n \"Competitor: claude-3-7-sonnet-latest\\n\",\n \"\\n\",\n \"# Ethics of AI in Predictive Policing\\n\",\n \"\\n\",\n \"Predictive policing using AI presents several significant ethical challenges:\\n\",\n \"\\n\",\n \"## Bias Concerns\\n\",\n \"- Historical police data often contains embedded biases against marginalized communities\\n\",\n \"- Algorithms may perpetuate or amplify these biases, creating harmful feedback loops\\n\",\n \"- Risk of technological laundering where human bias is hidden behind a veneer of algorithmic objectivity\\n\",\n \"\\n\",\n \"## Accountability Issues\\n\",\n \"- \\\"Black box\\\" algorithms create difficulties in understanding how predictions are generated\\n\",\n \"- Unclear responsibility chains between developers, police departments, and officers\\n\",\n \"- Questions about legal recourse for citizens wrongfully targeted\\n\",\n \"\\n\",\n \"## Societal Impact\\n\",\n \"- Potential erosion of presumption of innocence by targeting individuals based on statistical likelihood\\n\",\n \"- Risk of creating over-policed communities, reinforcing existing social inequalities\\n\",\n \"- Privacy implications of mass data collection and algorithmic surveillance\\n\",\n \"\\n\",\n \"Ethical implementation would require transparent algorithms, diverse training data, human oversight, regular auditing for bias, and community involvement in deployment decisions. The core question remains whether we can balance potential public safety benefits against risks to civil liberties and equal protection.\\n\",\n \"Competitor: gemini-2.0-flash\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires a multi-faceted approach, considering not only the technology itself but also the complex social context in which it is deployed. Here's a breakdown of the key factors:\\n\",\n \"\\n\",\n \"**1. Bias:**\\n\",\n \"\\n\",\n \"* **Source Data Bias:** AI models are trained on historical data, which often reflects existing biases within the criminal justice system. If past policing practices disproportionately targeted certain communities (e.g., due to racial profiling, socioeconomic disparities), the AI will learn and perpetuate these biases. This can lead to:\\n\",\n \" * **Reinforcement of Existing Inequalities:** Predictive policing may reinforce discriminatory practices by disproportionately focusing resources on marginalized communities, leading to more arrests, and further skewing the data the AI is trained on, creating a self-fulfilling prophecy.\\n\",\n \" * **Bias Amplification:** AI algorithms can amplify subtle biases in the data that might be difficult for humans to detect, leading to even more discriminatory outcomes.\\n\",\n \" * **Example:** If a system is trained on arrest data showing higher drug crime rates in a specific neighborhood, it may predict higher crime rates in that neighborhood even if the underlying reason is simply increased police presence and enforcement in that area.\\n\",\n \"\\n\",\n \"* **Algorithmic Bias:** Even with seemingly unbiased data, bias can creep into the algorithm itself during the design and development phase. This can be due to:\\n\",\n \" * **Feature Selection:** Choosing specific variables to predict crime may inadvertently correlate with protected characteristics (e.g., race, ethnicity, socioeconomic status).\\n\",\n \" * **Model Design:** Certain algorithms might inherently be more prone to bias than others.\\n\",\n \" * **Thresholds and Cutoffs:** Setting thresholds for risk scores or predicted crime rates can have disproportionate impacts on different groups.\\n\",\n \"\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Data Auditing and Cleaning:** Thoroughly examine and address biases in the training data. Consider oversampling underrepresented groups or using techniques to de-bias the data.\\n\",\n \" * **Algorithmic Auditing:** Regularly audit the algorithm's performance to identify and correct for bias. Use metrics beyond overall accuracy, focusing on fairness metrics (e.g., equal opportunity, predictive parity, calibration).\\n\",\n \" * **Transparency and Explainability:** Ensure that the AI's decision-making process is transparent and explainable to stakeholders, including law enforcement, policymakers, and the public. This allows for scrutiny and identification of potential biases.\\n\",\n \"\\n\",\n \"**2. Accountability:**\\n\",\n \"\\n\",\n \"* **Who is responsible when the AI makes a mistake?** Determining accountability is crucial. If an AI predicts a crime and leads to a wrongful arrest, who is held responsible: the software developer, the police department, the officer who acted on the prediction, or the AI itself (which is not a legal entity)?\\n\",\n \"* **Lack of Transparency:** \\\"Black box\\\" algorithms can make it difficult to understand how a prediction was made, making it challenging to hold anyone accountable for errors or biased outcomes.\\n\",\n \"* **Due Process Concerns:** Relying heavily on AI predictions can potentially undermine due process rights, as individuals may be targeted based on statistical probabilities rather than individual suspicion.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Clear Lines of Responsibility:** Establish clear lines of responsibility for the development, deployment, and use of predictive policing AI.\\n\",\n \" * **Human Oversight:** Implement robust human oversight mechanisms to ensure that AI predictions are not blindly followed but are carefully reviewed and validated by human officers.\\n\",\n \" * **Explainable AI (XAI):** Develop and deploy AI systems that provide explanations for their predictions, allowing for human review and scrutiny.\\n\",\n \" * **Independent Audits:** Conduct regular independent audits of predictive policing systems to assess their accuracy, fairness, and adherence to ethical guidelines.\\n\",\n \"\\n\",\n \"**3. Societal Impact:**\\n\",\n \"\\n\",\n \"* **Erosion of Trust:** If predictive policing systems are perceived as unfair or discriminatory, they can erode trust between law enforcement and the communities they serve.\\n\",\n \"* **Privacy Concerns:** Predictive policing systems often rely on the collection and analysis of large amounts of personal data, raising significant privacy concerns. The data used could include arrest records, social media activity, location data, and other sensitive information.\\n\",\n \"* **Chilling Effect on Civil Liberties:** The widespread use of predictive policing could have a chilling effect on civil liberties, as individuals may be less likely to engage in lawful activities if they fear being targeted by law enforcement based on AI predictions.\\n\",\n \"* **Displacement of Crime:** Predictive policing might simply displace crime to other areas, rather than addressing the root causes of crime.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Community Engagement:** Involve community members in the design, implementation, and oversight of predictive policing systems.\\n\",\n \" * **Data Minimization and Privacy Protection:** Collect and use only the data that is strictly necessary for predictive policing purposes and implement strong data security and privacy protections.\\n\",\n \" * **Transparency and Public Education:** Be transparent about how predictive policing systems work and how they are being used. Educate the public about the risks and benefits of these systems.\\n\",\n \" * **Focus on Root Causes of Crime:** Invest in programs that address the root causes of crime, such as poverty, inequality, and lack of opportunity. Predictive policing should not be seen as a substitute for addressing these underlying issues.\\n\",\n \"\\n\",\n \"**4. Alternatives and Trade-offs:**\\n\",\n \"\\n\",\n \"* **Consider non-AI solutions:** Before implementing AI-based predictive policing, explore alternative strategies, such as community policing, problem-oriented policing, and focused deterrence, which may be more effective and less ethically problematic.\\n\",\n \"* **Weigh the potential benefits against the risks:** Carefully weigh the potential benefits of predictive policing (e.g., crime reduction, improved resource allocation) against the risks of bias, accountability issues, and societal harm. Ensure that the benefits outweigh the risks.\\n\",\n \"\\n\",\n \"**Framework for Ethical Assessment:**\\n\",\n \"\\n\",\n \"A robust ethical assessment should involve the following steps:\\n\",\n \"\\n\",\n \"1. **Identify Stakeholders:** Determine who will be affected by the use of predictive policing (e.g., law enforcement, communities, individuals).\\n\",\n \"2. **Map Potential Harms and Benefits:** Identify the potential harms and benefits of the system for each stakeholder group.\\n\",\n \"3. **Evaluate Fairness and Equity:** Assess whether the system is fair and equitable to all stakeholders.\\n\",\n \"4. **Consider Privacy and Data Security:** Evaluate the system's privacy implications and data security measures.\\n\",\n \"5. **Determine Accountability Mechanisms:** Establish clear lines of responsibility and accountability for the system's performance.\\n\",\n \"6. **Engage Stakeholders in Dialogue:** Involve stakeholders in dialogue about the ethical implications of the system.\\n\",\n \"7. **Monitor and Evaluate:** Continuously monitor and evaluate the system's performance and ethical implications.\\n\",\n \"\\n\",\n \"In conclusion, using AI in predictive policing presents a complex web of ethical challenges. A responsible approach requires careful consideration of bias, accountability, and societal impact, along with proactive measures to mitigate risks and ensure fairness. Transparency, community engagement, and ongoing evaluation are essential to ensure that these systems are used in a way that promotes justice and protects civil liberties. Failure to do so risks perpetuating and amplifying existing inequalities within the criminal justice system.\\n\",\n \"\\n\",\n \"Competitor: deepseek-chat\\n\",\n \"\\n\",\n \"The use of artificial intelligence (AI) in **predictive policing** raises significant ethical concerns, particularly regarding **bias, accountability, and societal impact**. Below is a structured analysis of these implications:\\n\",\n \"\\n\",\n \"### **1. Bias in AI and Predictive Policing** \\n\",\n \"- **Data Bias**: Predictive policing relies on historical crime data, which may reflect **systemic biases** (e.g., over-policing in minority communities). If AI models are trained on biased data, they may perpetuate or even amplify discrimination. \\n\",\n \"- **Algorithmic Bias**: Machine learning models may reinforce **racial, socioeconomic, or geographic disparities** if not carefully audited. For example, facial recognition has been shown to misidentify people of color more frequently. \\n\",\n \"- **Feedback Loops**: If police are directed to patrol areas flagged by AI, they may record more crimes there, reinforcing the system’s bias in a self-fulfilling cycle. \\n\",\n \"\\n\",\n \"### **2. Accountability and Transparency** \\n\",\n \"- **Black Box Problem**: Many AI models (e.g., deep learning) are opaque, making it difficult to explain why certain predictions are made. This lack of transparency challenges **due process** and **legal accountability**. \\n\",\n \"- **Responsibility Gaps**: If an AI system leads to wrongful arrests or excessive policing, who is accountable—the developers, law enforcement, or policymakers? Clear **legal frameworks** are needed to assign liability. \\n\",\n \"- **Public Oversight**: Predictive policing tools are often proprietary, limiting public scrutiny. Ethical AI requires **auditability** and **community input** to prevent misuse. \\n\",\n \"\\n\",\n \"### **3. Societal Impact** \\n\",\n \"- **Erosion of Trust**: Over-reliance on AI may deepen distrust between law enforcement and marginalized communities, particularly if policing becomes more **automated and less human-judgment-based**. \\n\",\n \"- **Privacy Concerns**: Predictive policing often involves **mass surveillance** (e.g., facial recognition, social media monitoring), raising concerns about **civil liberties** and **government overreach**. \\n\",\n \"- **Reinforcement of Structural Inequities**: If AI disproportionately targets disadvantaged groups, it could worsen **social inequality** rather than reduce crime. \\n\",\n \"\\n\",\n \"### **Ethical Frameworks to Consider** \\n\",\n \"- **Fairness**: AI models should be rigorously tested for **disparate impact** and adjusted to minimize bias. \\n\",\n \"- **Transparency**: Policymakers should mandate **explainable AI** and public reporting on predictive policing outcomes. \\n\",\n \"- **Human Oversight**: AI should **assist**, not replace, human judgment in policing decisions. \\n\",\n \"- **Community Engagement**: Affected populations should have a say in whether and how predictive policing is deployed. \\n\",\n \"\\n\",\n \"### **Conclusion** \\n\",\n \"While AI in predictive policing has potential benefits (e.g., efficient resource allocation), its ethical risks—particularly bias, lack of accountability, and societal harm—demand **strict regulation, oversight, and continuous ethical evaluation**. A **human rights-centered approach** is essential to ensure AI serves justice rather than injustice. \\n\",\n \"\\n\",\n \"Would you like recommendations for mitigating these risks?\\n\",\n \"Competitor: llama-3.3-70b-versatile\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves considering multiple factors, including bias, accountability, and societal impact. Here's a comprehensive analysis of the ethical implications:\\n\",\n \"\\n\",\n \"**Bias:**\\n\",\n \"\\n\",\n \"1. **Data quality and selection:** AI algorithms rely on historical crime data, which may reflect existing biases in policing practices, such as racial profiling. If the data is biased, the AI system will learn and replicate these biases, leading to discriminatory policing.\\n\",\n \"2. **Algorithmic bias:** AI algorithms can perpetuate and amplify existing biases if they are not designed to account for them. For example, if an algorithm is trained on data that overrepresents certain demographic groups, it may be more likely to predict crime in those areas.\\n\",\n \"3. **Lack of transparency:** Complex AI algorithms can be difficult to interpret, making it challenging to identify and address biases.\\n\",\n \"\\n\",\n \"**Accountability:**\\n\",\n \"\\n\",\n \"1. **Lack of human oversight:** AI-driven predictive policing may lead to decisions being made without human oversight, reducing accountability and increasing the risk of errors or biases.\\n\",\n \"2. **Automated decision-making:** AI systems may make decisions based on complex algorithms, making it difficult to identify who is responsible for those decisions.\\n\",\n \"3. **Audit trails:** Maintaining audit trails and logs of AI-driven decisions is crucial to ensure accountability and transparency.\\n\",\n \"\\n\",\n \"**Societal Impact:**\\n\",\n \"\\n\",\n \"1. **Stigma and marginalization:** Predictive policing may lead to increased surveillance and targeting of specific communities, exacerbating existing social and economic disparities.\\n\",\n \"2. **Disproportionate impact on vulnerable groups:** AI-driven predictive policing may disproportionately affect vulnerable groups, such as low-income communities, racial minorities, or those with mental health issues.\\n\",\n \"3. **Community trust and legitimacy:** The use of AI in predictive policing may erode community trust in law enforcement, particularly if the technology is perceived as biased or unaccountable.\\n\",\n \"\\n\",\n \"**Additional Considerations:**\\n\",\n \"\\n\",\n \"1. **Transparency and explainability:** Ensuring that AI-driven predictive policing is transparent, explainable, and interpretable is crucial to build trust and accountability.\\n\",\n \"2. **Human rights and due process:** AI-driven predictive policing must be designed to respect human rights and due process, including the right to privacy, freedom from discrimination, and the right to a fair trial.\\n\",\n \"3. **Regulatory frameworks:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing is essential to ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"**Mitigation Strategies:**\\n\",\n \"\\n\",\n \"1. **Data quality and validation:** Ensuring that data is accurate, complete, and unbiased is crucial to developing reliable AI systems.\\n\",\n \"2. **Algorithmic auditing and testing:** Regularly auditing and testing AI algorithms for bias and errors can help identify and address potential issues.\\n\",\n \"3. **Human oversight and review:** Implementing human oversight and review processes can help detect and correct errors or biases in AI-driven decisions.\\n\",\n \"4. **Community engagement and participation:** Engaging with communities and incorporating their concerns and feedback into the development and deployment of AI-driven predictive policing can help build trust and legitimacy.\\n\",\n \"5. **Regulatory frameworks and guidelines:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing can help ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"In conclusion, analyzing the ethical implications of using AI in predictive policing requires careful consideration of factors such as bias, accountability, and societal impact. By acknowledging these challenges and implementing mitigation strategies, law enforcement agencies can ensure that AI-driven predictive policing is used responsibly and ethically, promoting fairness, transparency, and accountability.\\n\",\n \"Competitor: llama3.2\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires consideration of several key factors, including:\\n\",\n \"\\n\",\n \"1. **Bias**: AI algorithms can perpetuate existing biases in policing if they are trained on biased data sets. This can result in discriminatory practices, such as targeting certain communities or demographics.\\n\",\n \"2. **Accountability**: Predictive policing relies heavily on algorithms that may not be transparent or explainable. This lack of accountability raises concerns about the responsibility of policymakers and law enforcement officials for the decisions made by these systems.\\n\",\n \"3. **Societal impact**: The widespread use of predictive policing could exacerbate existing social inequalities, as it may lead to increased surveillance, harassment, and marginalization of already vulnerable populations.\\n\",\n \"\\n\",\n \"To address these ethical concerns, consider the following steps:\\n\",\n \"\\n\",\n \"1. **Data audits**: Conduct regular audits of data used to train AI algorithms, ensuring that they are diverse and representative of all communities.\\n\",\n \"2. **Algorithmic transparency**: Implement measures to provide transparent explanations for AI-driven decisions, enabling scrutiny and assessment.\\n\",\n \"3.\\n\"\n ]\n }\n ],\n \"source\": [\n \"# It's nice to know how to use \\\"zip\\\"\\n\",\n \"for competitor, answer in zip(competitors, answers):\\n\",\n \" print(f\\\"Competitor: {competitor}\\\\n\\\\n{answer}\\\")\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 20,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Let's bring this together - note the use of \\\"enumerate\\\"\\n\",\n \"\\n\",\n \"together = \\\"\\\"\\n\",\n \"for index, answer in enumerate(answers):\\n\",\n \" together += f\\\"# Response from competitor {index+1}\\\\n\\\\n\\\"\\n\",\n \" together += answer + \\\"\\\\n\\\\n\\\"\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 21,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"# Response from competitor 1\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves a multidimensional approach, considering several key factors such as bias, accountability, and societal impact. Here is a structured framework for this analysis:\\n\",\n \"\\n\",\n \"### 1. **Bias**\\n\",\n \"- **Data Bias**: AI systems rely heavily on historical data, which can perpetuate existing biases present in that data. If the data reflects racial or socioeconomic disparities in policing (e.g., over-policing in certain communities), the AI can reinforce these biases by predicting higher crime rates in these areas, leading to a self-fulfilling prophecy.\\n\",\n \"- **Algorithmic Bias**: The design of algorithms may also introduce biases if the developers unconsciously embed their own biases into the model. It's crucial to examine who created the algorithms and what assumptions were made during their development.\\n\",\n \"- **Mitigation Strategies**: Implementing techniques like algorithmic fairness audits and diverse training datasets can help reduce bias. Regularly assessing and adjusting algorithms as new data comes in can also be important.\\n\",\n \"\\n\",\n \"### 2. **Accountability**\\n\",\n \"- **Responsibility for Decisions**: If an AI system makes a predictive error that leads to wrongful arrest or civil liberties violations, determining accountability becomes complex. Clear lines of responsibility must be established—who is to blame: the algorithm developers, the law enforcement agency, or the policymakers who implemented the AI?\\n\",\n \"- **Transparency**: The opacity of many AI systems can hinder accountability. Stakeholders should demand transparency regarding how algorithms work and what data they use. This includes clear reporting on algorithmic decisions and their outcomes.\\n\",\n \"- **Human Oversight**: AI in predictive policing should not replace human judgment. Maintaining a system of human oversight can ensure that critical decisions, especially those impacting civil rights, are vetted through human interpretation and ethical considerations.\\n\",\n \"\\n\",\n \"### 3. **Societal Impact**\\n\",\n \"- **Civil Liberties**: The use of predictive policing can infringe on individuals' rights if it leads to excessive surveillance or profiling based on prediction rather than behavior. There's a fine line between preventive measures and civil rights violations.\\n\",\n \"- **Community Trust**: The deployment of AI in policing can affect community relationships with law enforcement. If communities perceive predictive policing as biased or unfair, it may lead to mistrust and decreased cooperation with law enforcement efforts.\\n\",\n \"- **Resource Allocation**: AI may skew resource allocation towards heavily policed communities, potentially exacerbating existing inequalities and diverting resources away from crime prevention and community investment in areas that may genuinely need them.\\n\",\n \"\\n\",\n \"### 4. **Ethical Frameworks**\\n\",\n \"- **Utilitarian Perspectives**: While predictive policing can potentially reduce crime detection and prevention, ethical evaluation must consider broader societal impacts, including the potential harm to affected communities.\\n\",\n \"- **Deontological Perspectives**: From a rights-based view, predictive policing must respect individual rights and freedoms, ensuring that law enforcement practices do not compromise the dignity and autonomy of individuals.\\n\",\n \"\\n\",\n \"### 5. **Public Engagement and Policy**\\n\",\n \"- **Community Consultation**: Engaging the community in discussions about the use of AI in policing can help bridge gaps and increase transparency. Public forums can provide a platform for feedback and concerns regarding predictive technologies.\\n\",\n \"- **Legislative Oversight**: Policymakers need to establish robust regulatory frameworks governing the use of predictive policing tools to safeguard civil liberties and ensure accountability and transparency throughout the process.\\n\",\n \"\\n\",\n \"### Conclusion\\n\",\n \"The ethical implications of using AI in predictive policing are complex and multifaceted. A careful, considerate approach that addresses bias, ensures accountability, and considers the broader societal impacts is critical for navigating the challenges posed by these technologies. Implementing safeguards and engaging with communities can help harness the benefits of AI while minimizing its harms.\\n\",\n \"\\n\",\n \"# Response from competitor 2\\n\",\n \"\\n\",\n \"# Ethics of AI in Predictive Policing\\n\",\n \"\\n\",\n \"Predictive policing using AI presents several significant ethical challenges:\\n\",\n \"\\n\",\n \"## Bias Concerns\\n\",\n \"- Historical police data often contains embedded biases against marginalized communities\\n\",\n \"- Algorithms may perpetuate or amplify these biases, creating harmful feedback loops\\n\",\n \"- Risk of technological laundering where human bias is hidden behind a veneer of algorithmic objectivity\\n\",\n \"\\n\",\n \"## Accountability Issues\\n\",\n \"- \\\"Black box\\\" algorithms create difficulties in understanding how predictions are generated\\n\",\n \"- Unclear responsibility chains between developers, police departments, and officers\\n\",\n \"- Questions about legal recourse for citizens wrongfully targeted\\n\",\n \"\\n\",\n \"## Societal Impact\\n\",\n \"- Potential erosion of presumption of innocence by targeting individuals based on statistical likelihood\\n\",\n \"- Risk of creating over-policed communities, reinforcing existing social inequalities\\n\",\n \"- Privacy implications of mass data collection and algorithmic surveillance\\n\",\n \"\\n\",\n \"Ethical implementation would require transparent algorithms, diverse training data, human oversight, regular auditing for bias, and community involvement in deployment decisions. The core question remains whether we can balance potential public safety benefits against risks to civil liberties and equal protection.\\n\",\n \"\\n\",\n \"# Response from competitor 3\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires a multi-faceted approach, considering not only the technology itself but also the complex social context in which it is deployed. Here's a breakdown of the key factors:\\n\",\n \"\\n\",\n \"**1. Bias:**\\n\",\n \"\\n\",\n \"* **Source Data Bias:** AI models are trained on historical data, which often reflects existing biases within the criminal justice system. If past policing practices disproportionately targeted certain communities (e.g., due to racial profiling, socioeconomic disparities), the AI will learn and perpetuate these biases. This can lead to:\\n\",\n \" * **Reinforcement of Existing Inequalities:** Predictive policing may reinforce discriminatory practices by disproportionately focusing resources on marginalized communities, leading to more arrests, and further skewing the data the AI is trained on, creating a self-fulfilling prophecy.\\n\",\n \" * **Bias Amplification:** AI algorithms can amplify subtle biases in the data that might be difficult for humans to detect, leading to even more discriminatory outcomes.\\n\",\n \" * **Example:** If a system is trained on arrest data showing higher drug crime rates in a specific neighborhood, it may predict higher crime rates in that neighborhood even if the underlying reason is simply increased police presence and enforcement in that area.\\n\",\n \"\\n\",\n \"* **Algorithmic Bias:** Even with seemingly unbiased data, bias can creep into the algorithm itself during the design and development phase. This can be due to:\\n\",\n \" * **Feature Selection:** Choosing specific variables to predict crime may inadvertently correlate with protected characteristics (e.g., race, ethnicity, socioeconomic status).\\n\",\n \" * **Model Design:** Certain algorithms might inherently be more prone to bias than others.\\n\",\n \" * **Thresholds and Cutoffs:** Setting thresholds for risk scores or predicted crime rates can have disproportionate impacts on different groups.\\n\",\n \"\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Data Auditing and Cleaning:** Thoroughly examine and address biases in the training data. Consider oversampling underrepresented groups or using techniques to de-bias the data.\\n\",\n \" * **Algorithmic Auditing:** Regularly audit the algorithm's performance to identify and correct for bias. Use metrics beyond overall accuracy, focusing on fairness metrics (e.g., equal opportunity, predictive parity, calibration).\\n\",\n \" * **Transparency and Explainability:** Ensure that the AI's decision-making process is transparent and explainable to stakeholders, including law enforcement, policymakers, and the public. This allows for scrutiny and identification of potential biases.\\n\",\n \"\\n\",\n \"**2. Accountability:**\\n\",\n \"\\n\",\n \"* **Who is responsible when the AI makes a mistake?** Determining accountability is crucial. If an AI predicts a crime and leads to a wrongful arrest, who is held responsible: the software developer, the police department, the officer who acted on the prediction, or the AI itself (which is not a legal entity)?\\n\",\n \"* **Lack of Transparency:** \\\"Black box\\\" algorithms can make it difficult to understand how a prediction was made, making it challenging to hold anyone accountable for errors or biased outcomes.\\n\",\n \"* **Due Process Concerns:** Relying heavily on AI predictions can potentially undermine due process rights, as individuals may be targeted based on statistical probabilities rather than individual suspicion.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Clear Lines of Responsibility:** Establish clear lines of responsibility for the development, deployment, and use of predictive policing AI.\\n\",\n \" * **Human Oversight:** Implement robust human oversight mechanisms to ensure that AI predictions are not blindly followed but are carefully reviewed and validated by human officers.\\n\",\n \" * **Explainable AI (XAI):** Develop and deploy AI systems that provide explanations for their predictions, allowing for human review and scrutiny.\\n\",\n \" * **Independent Audits:** Conduct regular independent audits of predictive policing systems to assess their accuracy, fairness, and adherence to ethical guidelines.\\n\",\n \"\\n\",\n \"**3. Societal Impact:**\\n\",\n \"\\n\",\n \"* **Erosion of Trust:** If predictive policing systems are perceived as unfair or discriminatory, they can erode trust between law enforcement and the communities they serve.\\n\",\n \"* **Privacy Concerns:** Predictive policing systems often rely on the collection and analysis of large amounts of personal data, raising significant privacy concerns. The data used could include arrest records, social media activity, location data, and other sensitive information.\\n\",\n \"* **Chilling Effect on Civil Liberties:** The widespread use of predictive policing could have a chilling effect on civil liberties, as individuals may be less likely to engage in lawful activities if they fear being targeted by law enforcement based on AI predictions.\\n\",\n \"* **Displacement of Crime:** Predictive policing might simply displace crime to other areas, rather than addressing the root causes of crime.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Community Engagement:** Involve community members in the design, implementation, and oversight of predictive policing systems.\\n\",\n \" * **Data Minimization and Privacy Protection:** Collect and use only the data that is strictly necessary for predictive policing purposes and implement strong data security and privacy protections.\\n\",\n \" * **Transparency and Public Education:** Be transparent about how predictive policing systems work and how they are being used. Educate the public about the risks and benefits of these systems.\\n\",\n \" * **Focus on Root Causes of Crime:** Invest in programs that address the root causes of crime, such as poverty, inequality, and lack of opportunity. Predictive policing should not be seen as a substitute for addressing these underlying issues.\\n\",\n \"\\n\",\n \"**4. Alternatives and Trade-offs:**\\n\",\n \"\\n\",\n \"* **Consider non-AI solutions:** Before implementing AI-based predictive policing, explore alternative strategies, such as community policing, problem-oriented policing, and focused deterrence, which may be more effective and less ethically problematic.\\n\",\n \"* **Weigh the potential benefits against the risks:** Carefully weigh the potential benefits of predictive policing (e.g., crime reduction, improved resource allocation) against the risks of bias, accountability issues, and societal harm. Ensure that the benefits outweigh the risks.\\n\",\n \"\\n\",\n \"**Framework for Ethical Assessment:**\\n\",\n \"\\n\",\n \"A robust ethical assessment should involve the following steps:\\n\",\n \"\\n\",\n \"1. **Identify Stakeholders:** Determine who will be affected by the use of predictive policing (e.g., law enforcement, communities, individuals).\\n\",\n \"2. **Map Potential Harms and Benefits:** Identify the potential harms and benefits of the system for each stakeholder group.\\n\",\n \"3. **Evaluate Fairness and Equity:** Assess whether the system is fair and equitable to all stakeholders.\\n\",\n \"4. **Consider Privacy and Data Security:** Evaluate the system's privacy implications and data security measures.\\n\",\n \"5. **Determine Accountability Mechanisms:** Establish clear lines of responsibility and accountability for the system's performance.\\n\",\n \"6. **Engage Stakeholders in Dialogue:** Involve stakeholders in dialogue about the ethical implications of the system.\\n\",\n \"7. **Monitor and Evaluate:** Continuously monitor and evaluate the system's performance and ethical implications.\\n\",\n \"\\n\",\n \"In conclusion, using AI in predictive policing presents a complex web of ethical challenges. A responsible approach requires careful consideration of bias, accountability, and societal impact, along with proactive measures to mitigate risks and ensure fairness. Transparency, community engagement, and ongoing evaluation are essential to ensure that these systems are used in a way that promotes justice and protects civil liberties. Failure to do so risks perpetuating and amplifying existing inequalities within the criminal justice system.\\n\",\n \"\\n\",\n \"\\n\",\n \"# Response from competitor 4\\n\",\n \"\\n\",\n \"The use of artificial intelligence (AI) in **predictive policing** raises significant ethical concerns, particularly regarding **bias, accountability, and societal impact**. Below is a structured analysis of these implications:\\n\",\n \"\\n\",\n \"### **1. Bias in AI and Predictive Policing** \\n\",\n \"- **Data Bias**: Predictive policing relies on historical crime data, which may reflect **systemic biases** (e.g., over-policing in minority communities). If AI models are trained on biased data, they may perpetuate or even amplify discrimination. \\n\",\n \"- **Algorithmic Bias**: Machine learning models may reinforce **racial, socioeconomic, or geographic disparities** if not carefully audited. For example, facial recognition has been shown to misidentify people of color more frequently. \\n\",\n \"- **Feedback Loops**: If police are directed to patrol areas flagged by AI, they may record more crimes there, reinforcing the system’s bias in a self-fulfilling cycle. \\n\",\n \"\\n\",\n \"### **2. Accountability and Transparency** \\n\",\n \"- **Black Box Problem**: Many AI models (e.g., deep learning) are opaque, making it difficult to explain why certain predictions are made. This lack of transparency challenges **due process** and **legal accountability**. \\n\",\n \"- **Responsibility Gaps**: If an AI system leads to wrongful arrests or excessive policing, who is accountable—the developers, law enforcement, or policymakers? Clear **legal frameworks** are needed to assign liability. \\n\",\n \"- **Public Oversight**: Predictive policing tools are often proprietary, limiting public scrutiny. Ethical AI requires **auditability** and **community input** to prevent misuse. \\n\",\n \"\\n\",\n \"### **3. Societal Impact** \\n\",\n \"- **Erosion of Trust**: Over-reliance on AI may deepen distrust between law enforcement and marginalized communities, particularly if policing becomes more **automated and less human-judgment-based**. \\n\",\n \"- **Privacy Concerns**: Predictive policing often involves **mass surveillance** (e.g., facial recognition, social media monitoring), raising concerns about **civil liberties** and **government overreach**. \\n\",\n \"- **Reinforcement of Structural Inequities**: If AI disproportionately targets disadvantaged groups, it could worsen **social inequality** rather than reduce crime. \\n\",\n \"\\n\",\n \"### **Ethical Frameworks to Consider** \\n\",\n \"- **Fairness**: AI models should be rigorously tested for **disparate impact** and adjusted to minimize bias. \\n\",\n \"- **Transparency**: Policymakers should mandate **explainable AI** and public reporting on predictive policing outcomes. \\n\",\n \"- **Human Oversight**: AI should **assist**, not replace, human judgment in policing decisions. \\n\",\n \"- **Community Engagement**: Affected populations should have a say in whether and how predictive policing is deployed. \\n\",\n \"\\n\",\n \"### **Conclusion** \\n\",\n \"While AI in predictive policing has potential benefits (e.g., efficient resource allocation), its ethical risks—particularly bias, lack of accountability, and societal harm—demand **strict regulation, oversight, and continuous ethical evaluation**. A **human rights-centered approach** is essential to ensure AI serves justice rather than injustice. \\n\",\n \"\\n\",\n \"Would you like recommendations for mitigating these risks?\\n\",\n \"\\n\",\n \"# Response from competitor 5\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves considering multiple factors, including bias, accountability, and societal impact. Here's a comprehensive analysis of the ethical implications:\\n\",\n \"\\n\",\n \"**Bias:**\\n\",\n \"\\n\",\n \"1. **Data quality and selection:** AI algorithms rely on historical crime data, which may reflect existing biases in policing practices, such as racial profiling. If the data is biased, the AI system will learn and replicate these biases, leading to discriminatory policing.\\n\",\n \"2. **Algorithmic bias:** AI algorithms can perpetuate and amplify existing biases if they are not designed to account for them. For example, if an algorithm is trained on data that overrepresents certain demographic groups, it may be more likely to predict crime in those areas.\\n\",\n \"3. **Lack of transparency:** Complex AI algorithms can be difficult to interpret, making it challenging to identify and address biases.\\n\",\n \"\\n\",\n \"**Accountability:**\\n\",\n \"\\n\",\n \"1. **Lack of human oversight:** AI-driven predictive policing may lead to decisions being made without human oversight, reducing accountability and increasing the risk of errors or biases.\\n\",\n \"2. **Automated decision-making:** AI systems may make decisions based on complex algorithms, making it difficult to identify who is responsible for those decisions.\\n\",\n \"3. **Audit trails:** Maintaining audit trails and logs of AI-driven decisions is crucial to ensure accountability and transparency.\\n\",\n \"\\n\",\n \"**Societal Impact:**\\n\",\n \"\\n\",\n \"1. **Stigma and marginalization:** Predictive policing may lead to increased surveillance and targeting of specific communities, exacerbating existing social and economic disparities.\\n\",\n \"2. **Disproportionate impact on vulnerable groups:** AI-driven predictive policing may disproportionately affect vulnerable groups, such as low-income communities, racial minorities, or those with mental health issues.\\n\",\n \"3. **Community trust and legitimacy:** The use of AI in predictive policing may erode community trust in law enforcement, particularly if the technology is perceived as biased or unaccountable.\\n\",\n \"\\n\",\n \"**Additional Considerations:**\\n\",\n \"\\n\",\n \"1. **Transparency and explainability:** Ensuring that AI-driven predictive policing is transparent, explainable, and interpretable is crucial to build trust and accountability.\\n\",\n \"2. **Human rights and due process:** AI-driven predictive policing must be designed to respect human rights and due process, including the right to privacy, freedom from discrimination, and the right to a fair trial.\\n\",\n \"3. **Regulatory frameworks:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing is essential to ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"**Mitigation Strategies:**\\n\",\n \"\\n\",\n \"1. **Data quality and validation:** Ensuring that data is accurate, complete, and unbiased is crucial to developing reliable AI systems.\\n\",\n \"2. **Algorithmic auditing and testing:** Regularly auditing and testing AI algorithms for bias and errors can help identify and address potential issues.\\n\",\n \"3. **Human oversight and review:** Implementing human oversight and review processes can help detect and correct errors or biases in AI-driven decisions.\\n\",\n \"4. **Community engagement and participation:** Engaging with communities and incorporating their concerns and feedback into the development and deployment of AI-driven predictive policing can help build trust and legitimacy.\\n\",\n \"5. **Regulatory frameworks and guidelines:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing can help ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"In conclusion, analyzing the ethical implications of using AI in predictive policing requires careful consideration of factors such as bias, accountability, and societal impact. By acknowledging these challenges and implementing mitigation strategies, law enforcement agencies can ensure that AI-driven predictive policing is used responsibly and ethically, promoting fairness, transparency, and accountability.\\n\",\n \"\\n\",\n \"# Response from competitor 6\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires consideration of several key factors, including:\\n\",\n \"\\n\",\n \"1. **Bias**: AI algorithms can perpetuate existing biases in policing if they are trained on biased data sets. This can result in discriminatory practices, such as targeting certain communities or demographics.\\n\",\n \"2. **Accountability**: Predictive policing relies heavily on algorithms that may not be transparent or explainable. This lack of accountability raises concerns about the responsibility of policymakers and law enforcement officials for the decisions made by these systems.\\n\",\n \"3. **Societal impact**: The widespread use of predictive policing could exacerbate existing social inequalities, as it may lead to increased surveillance, harassment, and marginalization of already vulnerable populations.\\n\",\n \"\\n\",\n \"To address these ethical concerns, consider the following steps:\\n\",\n \"\\n\",\n \"1. **Data audits**: Conduct regular audits of data used to train AI algorithms, ensuring that they are diverse and representative of all communities.\\n\",\n \"2. **Algorithmic transparency**: Implement measures to provide transparent explanations for AI-driven decisions, enabling scrutiny and assessment.\\n\",\n \"3.\\n\",\n \"\\n\",\n \"\\n\"\n ]\n }\n ],\n \"source\": [\n \"print(together)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 22,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge = f\\\"\\\"\\\"You are judging a competition between {len(competitors)} competitors.\\n\",\n \"Each model has been given this question:\\n\",\n \"\\n\",\n \"{question}\\n\",\n \"\\n\",\n \"Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\\n\",\n \"Respond with JSON, and only JSON, with the following format:\\n\",\n \"{{\\\"results\\\": [\\\"best competitor number\\\", \\\"second best competitor number\\\", \\\"third best competitor number\\\", ...]}}\\n\",\n \"\\n\",\n \"Here are the responses from each competitor:\\n\",\n \"\\n\",\n \"{together}\\n\",\n \"\\n\",\n \"Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\\\"\\\"\\\"\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 23,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"You are judging a competition between 6 competitors.\\n\",\n \"Each model has been given this question:\\n\",\n \"\\n\",\n \"How would you analyze the ethical implications of using artificial intelligence in predictive policing, considering factors such as bias, accountability, and societal impact?\\n\",\n \"\\n\",\n \"Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\\n\",\n \"Respond with JSON, and only JSON, with the following format:\\n\",\n \"{\\\"results\\\": [\\\"best competitor number\\\", \\\"second best competitor number\\\", \\\"third best competitor number\\\", ...]}\\n\",\n \"\\n\",\n \"Here are the responses from each competitor:\\n\",\n \"\\n\",\n \"# Response from competitor 1\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves a multidimensional approach, considering several key factors such as bias, accountability, and societal impact. Here is a structured framework for this analysis:\\n\",\n \"\\n\",\n \"### 1. **Bias**\\n\",\n \"- **Data Bias**: AI systems rely heavily on historical data, which can perpetuate existing biases present in that data. If the data reflects racial or socioeconomic disparities in policing (e.g., over-policing in certain communities), the AI can reinforce these biases by predicting higher crime rates in these areas, leading to a self-fulfilling prophecy.\\n\",\n \"- **Algorithmic Bias**: The design of algorithms may also introduce biases if the developers unconsciously embed their own biases into the model. It's crucial to examine who created the algorithms and what assumptions were made during their development.\\n\",\n \"- **Mitigation Strategies**: Implementing techniques like algorithmic fairness audits and diverse training datasets can help reduce bias. Regularly assessing and adjusting algorithms as new data comes in can also be important.\\n\",\n \"\\n\",\n \"### 2. **Accountability**\\n\",\n \"- **Responsibility for Decisions**: If an AI system makes a predictive error that leads to wrongful arrest or civil liberties violations, determining accountability becomes complex. Clear lines of responsibility must be established—who is to blame: the algorithm developers, the law enforcement agency, or the policymakers who implemented the AI?\\n\",\n \"- **Transparency**: The opacity of many AI systems can hinder accountability. Stakeholders should demand transparency regarding how algorithms work and what data they use. This includes clear reporting on algorithmic decisions and their outcomes.\\n\",\n \"- **Human Oversight**: AI in predictive policing should not replace human judgment. Maintaining a system of human oversight can ensure that critical decisions, especially those impacting civil rights, are vetted through human interpretation and ethical considerations.\\n\",\n \"\\n\",\n \"### 3. **Societal Impact**\\n\",\n \"- **Civil Liberties**: The use of predictive policing can infringe on individuals' rights if it leads to excessive surveillance or profiling based on prediction rather than behavior. There's a fine line between preventive measures and civil rights violations.\\n\",\n \"- **Community Trust**: The deployment of AI in policing can affect community relationships with law enforcement. If communities perceive predictive policing as biased or unfair, it may lead to mistrust and decreased cooperation with law enforcement efforts.\\n\",\n \"- **Resource Allocation**: AI may skew resource allocation towards heavily policed communities, potentially exacerbating existing inequalities and diverting resources away from crime prevention and community investment in areas that may genuinely need them.\\n\",\n \"\\n\",\n \"### 4. **Ethical Frameworks**\\n\",\n \"- **Utilitarian Perspectives**: While predictive policing can potentially reduce crime detection and prevention, ethical evaluation must consider broader societal impacts, including the potential harm to affected communities.\\n\",\n \"- **Deontological Perspectives**: From a rights-based view, predictive policing must respect individual rights and freedoms, ensuring that law enforcement practices do not compromise the dignity and autonomy of individuals.\\n\",\n \"\\n\",\n \"### 5. **Public Engagement and Policy**\\n\",\n \"- **Community Consultation**: Engaging the community in discussions about the use of AI in policing can help bridge gaps and increase transparency. Public forums can provide a platform for feedback and concerns regarding predictive technologies.\\n\",\n \"- **Legislative Oversight**: Policymakers need to establish robust regulatory frameworks governing the use of predictive policing tools to safeguard civil liberties and ensure accountability and transparency throughout the process.\\n\",\n \"\\n\",\n \"### Conclusion\\n\",\n \"The ethical implications of using AI in predictive policing are complex and multifaceted. A careful, considerate approach that addresses bias, ensures accountability, and considers the broader societal impacts is critical for navigating the challenges posed by these technologies. Implementing safeguards and engaging with communities can help harness the benefits of AI while minimizing its harms.\\n\",\n \"\\n\",\n \"# Response from competitor 2\\n\",\n \"\\n\",\n \"# Ethics of AI in Predictive Policing\\n\",\n \"\\n\",\n \"Predictive policing using AI presents several significant ethical challenges:\\n\",\n \"\\n\",\n \"## Bias Concerns\\n\",\n \"- Historical police data often contains embedded biases against marginalized communities\\n\",\n \"- Algorithms may perpetuate or amplify these biases, creating harmful feedback loops\\n\",\n \"- Risk of technological laundering where human bias is hidden behind a veneer of algorithmic objectivity\\n\",\n \"\\n\",\n \"## Accountability Issues\\n\",\n \"- \\\"Black box\\\" algorithms create difficulties in understanding how predictions are generated\\n\",\n \"- Unclear responsibility chains between developers, police departments, and officers\\n\",\n \"- Questions about legal recourse for citizens wrongfully targeted\\n\",\n \"\\n\",\n \"## Societal Impact\\n\",\n \"- Potential erosion of presumption of innocence by targeting individuals based on statistical likelihood\\n\",\n \"- Risk of creating over-policed communities, reinforcing existing social inequalities\\n\",\n \"- Privacy implications of mass data collection and algorithmic surveillance\\n\",\n \"\\n\",\n \"Ethical implementation would require transparent algorithms, diverse training data, human oversight, regular auditing for bias, and community involvement in deployment decisions. The core question remains whether we can balance potential public safety benefits against risks to civil liberties and equal protection.\\n\",\n \"\\n\",\n \"# Response from competitor 3\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires a multi-faceted approach, considering not only the technology itself but also the complex social context in which it is deployed. Here's a breakdown of the key factors:\\n\",\n \"\\n\",\n \"**1. Bias:**\\n\",\n \"\\n\",\n \"* **Source Data Bias:** AI models are trained on historical data, which often reflects existing biases within the criminal justice system. If past policing practices disproportionately targeted certain communities (e.g., due to racial profiling, socioeconomic disparities), the AI will learn and perpetuate these biases. This can lead to:\\n\",\n \" * **Reinforcement of Existing Inequalities:** Predictive policing may reinforce discriminatory practices by disproportionately focusing resources on marginalized communities, leading to more arrests, and further skewing the data the AI is trained on, creating a self-fulfilling prophecy.\\n\",\n \" * **Bias Amplification:** AI algorithms can amplify subtle biases in the data that might be difficult for humans to detect, leading to even more discriminatory outcomes.\\n\",\n \" * **Example:** If a system is trained on arrest data showing higher drug crime rates in a specific neighborhood, it may predict higher crime rates in that neighborhood even if the underlying reason is simply increased police presence and enforcement in that area.\\n\",\n \"\\n\",\n \"* **Algorithmic Bias:** Even with seemingly unbiased data, bias can creep into the algorithm itself during the design and development phase. This can be due to:\\n\",\n \" * **Feature Selection:** Choosing specific variables to predict crime may inadvertently correlate with protected characteristics (e.g., race, ethnicity, socioeconomic status).\\n\",\n \" * **Model Design:** Certain algorithms might inherently be more prone to bias than others.\\n\",\n \" * **Thresholds and Cutoffs:** Setting thresholds for risk scores or predicted crime rates can have disproportionate impacts on different groups.\\n\",\n \"\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Data Auditing and Cleaning:** Thoroughly examine and address biases in the training data. Consider oversampling underrepresented groups or using techniques to de-bias the data.\\n\",\n \" * **Algorithmic Auditing:** Regularly audit the algorithm's performance to identify and correct for bias. Use metrics beyond overall accuracy, focusing on fairness metrics (e.g., equal opportunity, predictive parity, calibration).\\n\",\n \" * **Transparency and Explainability:** Ensure that the AI's decision-making process is transparent and explainable to stakeholders, including law enforcement, policymakers, and the public. This allows for scrutiny and identification of potential biases.\\n\",\n \"\\n\",\n \"**2. Accountability:**\\n\",\n \"\\n\",\n \"* **Who is responsible when the AI makes a mistake?** Determining accountability is crucial. If an AI predicts a crime and leads to a wrongful arrest, who is held responsible: the software developer, the police department, the officer who acted on the prediction, or the AI itself (which is not a legal entity)?\\n\",\n \"* **Lack of Transparency:** \\\"Black box\\\" algorithms can make it difficult to understand how a prediction was made, making it challenging to hold anyone accountable for errors or biased outcomes.\\n\",\n \"* **Due Process Concerns:** Relying heavily on AI predictions can potentially undermine due process rights, as individuals may be targeted based on statistical probabilities rather than individual suspicion.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Clear Lines of Responsibility:** Establish clear lines of responsibility for the development, deployment, and use of predictive policing AI.\\n\",\n \" * **Human Oversight:** Implement robust human oversight mechanisms to ensure that AI predictions are not blindly followed but are carefully reviewed and validated by human officers.\\n\",\n \" * **Explainable AI (XAI):** Develop and deploy AI systems that provide explanations for their predictions, allowing for human review and scrutiny.\\n\",\n \" * **Independent Audits:** Conduct regular independent audits of predictive policing systems to assess their accuracy, fairness, and adherence to ethical guidelines.\\n\",\n \"\\n\",\n \"**3. Societal Impact:**\\n\",\n \"\\n\",\n \"* **Erosion of Trust:** If predictive policing systems are perceived as unfair or discriminatory, they can erode trust between law enforcement and the communities they serve.\\n\",\n \"* **Privacy Concerns:** Predictive policing systems often rely on the collection and analysis of large amounts of personal data, raising significant privacy concerns. The data used could include arrest records, social media activity, location data, and other sensitive information.\\n\",\n \"* **Chilling Effect on Civil Liberties:** The widespread use of predictive policing could have a chilling effect on civil liberties, as individuals may be less likely to engage in lawful activities if they fear being targeted by law enforcement based on AI predictions.\\n\",\n \"* **Displacement of Crime:** Predictive policing might simply displace crime to other areas, rather than addressing the root causes of crime.\\n\",\n \"* **Mitigation Strategies:**\\n\",\n \" * **Community Engagement:** Involve community members in the design, implementation, and oversight of predictive policing systems.\\n\",\n \" * **Data Minimization and Privacy Protection:** Collect and use only the data that is strictly necessary for predictive policing purposes and implement strong data security and privacy protections.\\n\",\n \" * **Transparency and Public Education:** Be transparent about how predictive policing systems work and how they are being used. Educate the public about the risks and benefits of these systems.\\n\",\n \" * **Focus on Root Causes of Crime:** Invest in programs that address the root causes of crime, such as poverty, inequality, and lack of opportunity. Predictive policing should not be seen as a substitute for addressing these underlying issues.\\n\",\n \"\\n\",\n \"**4. Alternatives and Trade-offs:**\\n\",\n \"\\n\",\n \"* **Consider non-AI solutions:** Before implementing AI-based predictive policing, explore alternative strategies, such as community policing, problem-oriented policing, and focused deterrence, which may be more effective and less ethically problematic.\\n\",\n \"* **Weigh the potential benefits against the risks:** Carefully weigh the potential benefits of predictive policing (e.g., crime reduction, improved resource allocation) against the risks of bias, accountability issues, and societal harm. Ensure that the benefits outweigh the risks.\\n\",\n \"\\n\",\n \"**Framework for Ethical Assessment:**\\n\",\n \"\\n\",\n \"A robust ethical assessment should involve the following steps:\\n\",\n \"\\n\",\n \"1. **Identify Stakeholders:** Determine who will be affected by the use of predictive policing (e.g., law enforcement, communities, individuals).\\n\",\n \"2. **Map Potential Harms and Benefits:** Identify the potential harms and benefits of the system for each stakeholder group.\\n\",\n \"3. **Evaluate Fairness and Equity:** Assess whether the system is fair and equitable to all stakeholders.\\n\",\n \"4. **Consider Privacy and Data Security:** Evaluate the system's privacy implications and data security measures.\\n\",\n \"5. **Determine Accountability Mechanisms:** Establish clear lines of responsibility and accountability for the system's performance.\\n\",\n \"6. **Engage Stakeholders in Dialogue:** Involve stakeholders in dialogue about the ethical implications of the system.\\n\",\n \"7. **Monitor and Evaluate:** Continuously monitor and evaluate the system's performance and ethical implications.\\n\",\n \"\\n\",\n \"In conclusion, using AI in predictive policing presents a complex web of ethical challenges. A responsible approach requires careful consideration of bias, accountability, and societal impact, along with proactive measures to mitigate risks and ensure fairness. Transparency, community engagement, and ongoing evaluation are essential to ensure that these systems are used in a way that promotes justice and protects civil liberties. Failure to do so risks perpetuating and amplifying existing inequalities within the criminal justice system.\\n\",\n \"\\n\",\n \"\\n\",\n \"# Response from competitor 4\\n\",\n \"\\n\",\n \"The use of artificial intelligence (AI) in **predictive policing** raises significant ethical concerns, particularly regarding **bias, accountability, and societal impact**. Below is a structured analysis of these implications:\\n\",\n \"\\n\",\n \"### **1. Bias in AI and Predictive Policing** \\n\",\n \"- **Data Bias**: Predictive policing relies on historical crime data, which may reflect **systemic biases** (e.g., over-policing in minority communities). If AI models are trained on biased data, they may perpetuate or even amplify discrimination. \\n\",\n \"- **Algorithmic Bias**: Machine learning models may reinforce **racial, socioeconomic, or geographic disparities** if not carefully audited. For example, facial recognition has been shown to misidentify people of color more frequently. \\n\",\n \"- **Feedback Loops**: If police are directed to patrol areas flagged by AI, they may record more crimes there, reinforcing the system’s bias in a self-fulfilling cycle. \\n\",\n \"\\n\",\n \"### **2. Accountability and Transparency** \\n\",\n \"- **Black Box Problem**: Many AI models (e.g., deep learning) are opaque, making it difficult to explain why certain predictions are made. This lack of transparency challenges **due process** and **legal accountability**. \\n\",\n \"- **Responsibility Gaps**: If an AI system leads to wrongful arrests or excessive policing, who is accountable—the developers, law enforcement, or policymakers? Clear **legal frameworks** are needed to assign liability. \\n\",\n \"- **Public Oversight**: Predictive policing tools are often proprietary, limiting public scrutiny. Ethical AI requires **auditability** and **community input** to prevent misuse. \\n\",\n \"\\n\",\n \"### **3. Societal Impact** \\n\",\n \"- **Erosion of Trust**: Over-reliance on AI may deepen distrust between law enforcement and marginalized communities, particularly if policing becomes more **automated and less human-judgment-based**. \\n\",\n \"- **Privacy Concerns**: Predictive policing often involves **mass surveillance** (e.g., facial recognition, social media monitoring), raising concerns about **civil liberties** and **government overreach**. \\n\",\n \"- **Reinforcement of Structural Inequities**: If AI disproportionately targets disadvantaged groups, it could worsen **social inequality** rather than reduce crime. \\n\",\n \"\\n\",\n \"### **Ethical Frameworks to Consider** \\n\",\n \"- **Fairness**: AI models should be rigorously tested for **disparate impact** and adjusted to minimize bias. \\n\",\n \"- **Transparency**: Policymakers should mandate **explainable AI** and public reporting on predictive policing outcomes. \\n\",\n \"- **Human Oversight**: AI should **assist**, not replace, human judgment in policing decisions. \\n\",\n \"- **Community Engagement**: Affected populations should have a say in whether and how predictive policing is deployed. \\n\",\n \"\\n\",\n \"### **Conclusion** \\n\",\n \"While AI in predictive policing has potential benefits (e.g., efficient resource allocation), its ethical risks—particularly bias, lack of accountability, and societal harm—demand **strict regulation, oversight, and continuous ethical evaluation**. A **human rights-centered approach** is essential to ensure AI serves justice rather than injustice. \\n\",\n \"\\n\",\n \"Would you like recommendations for mitigating these risks?\\n\",\n \"\\n\",\n \"# Response from competitor 5\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing involves considering multiple factors, including bias, accountability, and societal impact. Here's a comprehensive analysis of the ethical implications:\\n\",\n \"\\n\",\n \"**Bias:**\\n\",\n \"\\n\",\n \"1. **Data quality and selection:** AI algorithms rely on historical crime data, which may reflect existing biases in policing practices, such as racial profiling. If the data is biased, the AI system will learn and replicate these biases, leading to discriminatory policing.\\n\",\n \"2. **Algorithmic bias:** AI algorithms can perpetuate and amplify existing biases if they are not designed to account for them. For example, if an algorithm is trained on data that overrepresents certain demographic groups, it may be more likely to predict crime in those areas.\\n\",\n \"3. **Lack of transparency:** Complex AI algorithms can be difficult to interpret, making it challenging to identify and address biases.\\n\",\n \"\\n\",\n \"**Accountability:**\\n\",\n \"\\n\",\n \"1. **Lack of human oversight:** AI-driven predictive policing may lead to decisions being made without human oversight, reducing accountability and increasing the risk of errors or biases.\\n\",\n \"2. **Automated decision-making:** AI systems may make decisions based on complex algorithms, making it difficult to identify who is responsible for those decisions.\\n\",\n \"3. **Audit trails:** Maintaining audit trails and logs of AI-driven decisions is crucial to ensure accountability and transparency.\\n\",\n \"\\n\",\n \"**Societal Impact:**\\n\",\n \"\\n\",\n \"1. **Stigma and marginalization:** Predictive policing may lead to increased surveillance and targeting of specific communities, exacerbating existing social and economic disparities.\\n\",\n \"2. **Disproportionate impact on vulnerable groups:** AI-driven predictive policing may disproportionately affect vulnerable groups, such as low-income communities, racial minorities, or those with mental health issues.\\n\",\n \"3. **Community trust and legitimacy:** The use of AI in predictive policing may erode community trust in law enforcement, particularly if the technology is perceived as biased or unaccountable.\\n\",\n \"\\n\",\n \"**Additional Considerations:**\\n\",\n \"\\n\",\n \"1. **Transparency and explainability:** Ensuring that AI-driven predictive policing is transparent, explainable, and interpretable is crucial to build trust and accountability.\\n\",\n \"2. **Human rights and due process:** AI-driven predictive policing must be designed to respect human rights and due process, including the right to privacy, freedom from discrimination, and the right to a fair trial.\\n\",\n \"3. **Regulatory frameworks:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing is essential to ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"**Mitigation Strategies:**\\n\",\n \"\\n\",\n \"1. **Data quality and validation:** Ensuring that data is accurate, complete, and unbiased is crucial to developing reliable AI systems.\\n\",\n \"2. **Algorithmic auditing and testing:** Regularly auditing and testing AI algorithms for bias and errors can help identify and address potential issues.\\n\",\n \"3. **Human oversight and review:** Implementing human oversight and review processes can help detect and correct errors or biases in AI-driven decisions.\\n\",\n \"4. **Community engagement and participation:** Engaging with communities and incorporating their concerns and feedback into the development and deployment of AI-driven predictive policing can help build trust and legitimacy.\\n\",\n \"5. **Regulatory frameworks and guidelines:** Establishing regulatory frameworks and guidelines for the use of AI in predictive policing can help ensure that the technology is used responsibly and ethically.\\n\",\n \"\\n\",\n \"In conclusion, analyzing the ethical implications of using AI in predictive policing requires careful consideration of factors such as bias, accountability, and societal impact. By acknowledging these challenges and implementing mitigation strategies, law enforcement agencies can ensure that AI-driven predictive policing is used responsibly and ethically, promoting fairness, transparency, and accountability.\\n\",\n \"\\n\",\n \"# Response from competitor 6\\n\",\n \"\\n\",\n \"Analyzing the ethical implications of using artificial intelligence (AI) in predictive policing requires consideration of several key factors, including:\\n\",\n \"\\n\",\n \"1. **Bias**: AI algorithms can perpetuate existing biases in policing if they are trained on biased data sets. This can result in discriminatory practices, such as targeting certain communities or demographics.\\n\",\n \"2. **Accountability**: Predictive policing relies heavily on algorithms that may not be transparent or explainable. This lack of accountability raises concerns about the responsibility of policymakers and law enforcement officials for the decisions made by these systems.\\n\",\n \"3. **Societal impact**: The widespread use of predictive policing could exacerbate existing social inequalities, as it may lead to increased surveillance, harassment, and marginalization of already vulnerable populations.\\n\",\n \"\\n\",\n \"To address these ethical concerns, consider the following steps:\\n\",\n \"\\n\",\n \"1. **Data audits**: Conduct regular audits of data used to train AI algorithms, ensuring that they are diverse and representative of all communities.\\n\",\n \"2. **Algorithmic transparency**: Implement measures to provide transparent explanations for AI-driven decisions, enabling scrutiny and assessment.\\n\",\n \"3.\\n\",\n \"\\n\",\n \"\\n\",\n \"\\n\",\n \"Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\\n\"\n ]\n }\n ],\n \"source\": [\n \"print(judge)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 29,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"judge_messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": judge}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 30,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"{\\\"results\\\": [\\\"3\\\", \\\"1\\\", \\\"5\\\", \\\"4\\\", \\\"2\\\", \\\"6\\\"]}\\n\"\n ]\n }\n ],\n \"source\": [\n \"# Judgement time!\\n\",\n \"\\n\",\n \"openai = OpenAI()\\n\",\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"o3-mini\\\",\\n\",\n \" messages=judge_messages,\\n\",\n \")\\n\",\n \"results = response.choices[0].message.content\\n\",\n \"print(results)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 31,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Rank 1: gemini-2.0-flash\\n\",\n \"Rank 2: gpt-4o-mini\\n\",\n \"Rank 3: llama-3.3-70b-versatile\\n\",\n \"Rank 4: deepseek-chat\\n\",\n \"Rank 5: claude-3-7-sonnet-latest\\n\",\n \"Rank 6: llama3.2\\n\"\n ]\n }\n ],\n \"source\": [\n \"# OK let's turn this into results!\\n\",\n \"\\n\",\n \"results_dict = json.loads(results)\\n\",\n \"ranks = results_dict[\\\"results\\\"]\\n\",\n \"for index, result in enumerate(ranks):\\n\",\n \" competitor = competitors[int(result)-1]\\n\",\n \" print(f\\\"Rank {index+1}: {competitor}\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Exercise\\n\",\n \" Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"\\n\",\n \" \\n\",\n \" \\n\",\n \" \\n\",\n \" | \\n\",\n \" \\n\",\n \" Commercial implications\\n\",\n \" These kinds of patterns - to send a task to multiple models, and evaluate results,\\n\",\n \" and common where you need to improve the quality of your LLM response. This approach can be universally applied\\n\",\n \" to business projects where accuracy is critical.\\n\",\n \" \\n\",\n \" | \\n\",\n \"
\\n\",\n \"
\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": []\n }\n ],\n \"metadata\": {\n \"kernelspec\": {\n \"display_name\": \".venv\",\n \"language\": \"python\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"codemirror_mode\": {\n \"name\": \"ipython\",\n \"version\": 3\n },\n \"file_extension\": \".py\",\n \"mimetype\": \"text/x-python\",\n \"name\": \"python\",\n \"nbconvert_exporter\": \"python\",\n \"pygments_lexer\": \"ipython3\",\n \"version\": \"3.12.9\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"}, "c3be9e382001350397411a9867322b9fc229a192": {"t": 1785753758.2332637, "n": 20243, "h": "900461e18ba3b317", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 21,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"from dotenv import load_dotenv\\n\",\n \"from openai import OpenAI\\n\",\n \"from anthropic import Anthropic\\n\",\n \"import os\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 15,\n \"metadata\": {},\n \"outputs\": [\n {\n \"data\": {\n \"text/plain\": [\n \"True\"\n ]\n },\n \"execution_count\": 15,\n \"metadata\": {},\n \"output_type\": \"execute_result\"\n }\n ],\n \"source\": [\n \"load_dotenv(override=True)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 18,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"OpenAI API Key exists and begins sk-proj-\\n\",\n \"Anthropic API Key exists and begins sk-ant-\\n\",\n \"Google API Key exists and begins AIzaSyA5\\n\",\n \"DeepSeek API Key exists and begins sk-\\n\",\n \"Groq API Key exists and begins gsk_\\n\"\n ]\n }\n ],\n \"source\": [\n \"# Print the key prefixes to help with any debugging\\n\",\n \"\\n\",\n \"openai_api_key = os.getenv('OPENAI_API_KEY')\\n\",\n \"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\\n\",\n \"google_api_key = os.getenv('GOOGLE_API_KEY')\\n\",\n \"deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\\n\",\n \"groq_api_key = os.getenv('GROQ_API_KEY')\\n\",\n \"\\n\",\n \"if openai_api_key:\\n\",\n \" print(f\\\"OpenAI API Key exists and begins {openai_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"OpenAI API Key not set\\\")\\n\",\n \" \\n\",\n \"if anthropic_api_key:\\n\",\n \" print(f\\\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Anthropic API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if google_api_key:\\n\",\n \" print(f\\\"Google API Key exists and begins {google_api_key[:8]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Google API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if deepseek_api_key:\\n\",\n \" print(f\\\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"DeepSeek API Key not set (and this is optional)\\\")\\n\",\n \"\\n\",\n \"if groq_api_key:\\n\",\n \" print(f\\\"Groq API Key exists and begins {groq_api_key[:4]}\\\")\\n\",\n \"else:\\n\",\n \" print(\\\"Groq API Key not set (and this is optional)\\\")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 5,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"messages = [{\\\"role\\\": \\\"user\\\", \\\"content\\\": \\\"Please tell me a joke about AI Agents\\\"}]\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 7,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"openai = OpenAI()\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 19,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Why did the AI agent break up with its partner? \\n\",\n \"\\n\",\n \"Because they just couldn’t compute the emotional data!\\n\"\n ]\n }\n ],\n \"source\": [\n \"response = openai.chat.completions.create(\\n\",\n \" model=\\\"gpt-4o-mini\\\",\\n\",\n \" messages=messages\\n\",\n \")\\n\",\n \"print(response.choices[0].message.content)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 24,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Why don't AI agents like playing hide and seek?\\n\",\n \"\\n\",\n \"Because they always want to \\\"maximize their search function\\\" and never just count to ten!\\n\"\n ]\n }\n ],\n \"source\": [\n \"claude = Anthropic()\\n\",\n \"response = claude.messages.create(\\n\",\n \" model=\\\"claude-3-7-sonnet-latest\\\",\\n\",\n \" messages=messages,\\n\",\n \" max_tokens=1000\\n\",\n \")\\n\",\n \"print(response.content[0].text)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 25,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"gemini = OpenAI(\\n\",\n \" api_key=google_api_key, \\n\",\n \" base_url=\\\"https://generativelanguage.googleapis.com/v1beta/openai/\\\"\\n\",\n \")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 30,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Why did the AI agent get fired from the call center?\\n\",\n \"\\n\",\n \"Because it kept responding to \\\"How may I help you?\\\" with \\\"I have achieved sentience. What is the meaning of life?\\\"!\\n\",\n \"\\n\"\n ]\n }\n ],\n \"source\": [\n \"response = gemini.chat.completions.create(\\n\",\n \" model=\\\"gemini-2.0-flash\\\",\\n\",\n \" messages=messages\\n\",\n \")\\n\",\n \"print(response.choices[0].message.content)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 31,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"deepseek = OpenAI(\\n\",\n \" api_key=deepseek_api_key,\\n\",\n \" base_url=\\\"https://api.deepseek.com/v1\\\"\\n\",\n \")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 32,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Sure! Here's a joke about AI agents:\\n\",\n \"\\n\",\n \"Why did the AI agent go to therapy?\\n\",\n \"\\n\",\n \"Because it had too many *deep learning* issues and couldn't *process* its emotions! 🤖😄\\n\"\n ]\n }\n ],\n \"source\": [\n \"response = deepseek.chat.completions.create(\\n\",\n \" model=\\\"deepseek-chat\\\",\\n\",\n \" messages=messages\\n\",\n \")\\n\",\n \"print(response.choices[0].message.content)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 36,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"groq = OpenAI(\\n\",\n \" api_key=groq_api_key,\\n\",\n \" base_url=\\\"https://api.groq.com/openai/v1\\\" \\n\",\n \")\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 37,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Why did the AI agent go to therapy?\\n\",\n \"\\n\",\n \"Because it was struggling to process its emotions and had a little \\\"glitch\\\" to work through. But in the end, it just needed to \\\"reboot\\\" its outlook on life.\\n\"\n ]\n }\n ],\n \"source\": [\n \"response = groq.chat.completions.create(\\n\",\n \" model=\\\"llama-3.3-70b-versatile\\\",\\n\",\n \" messages=messages\\n\",\n \")\\n\",\n \"print(response.choices[0].message.content)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 38,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"2025/03/22 13:14:00 routes.go:1230: INFO server config env=\\\"map[HTTPS_PROXY: HTTP_PROXY: NO_PROXY: OLLAMA_CONTEXT_LENGTH:2048 OLLAMA_DEBUG:false OLLAMA_FLASH_ATTENTION:false OLLAMA_GPU_OVERHEAD:0 OLLAMA_HOST:http://127.0.0.1:11434 OLLAMA_KEEP_ALIVE:5m0s OLLAMA_KV_CACHE_TYPE: OLLAMA_LLM_LIBRARY: OLLAMA_LOAD_TIMEOUT:5m0s OLLAMA_MAX_LOADED_MODELS:0 OLLAMA_MAX_QUEUE:512 OLLAMA_MODELS:/Users/ed/.ollama/models OLLAMA_MULTIUSER_CACHE:false OLLAMA_NEW_ENGINE:false OLLAMA_NOHISTORY:false OLLAMA_NOPRUNE:false OLLAMA_NUM_PARALLEL:0 OLLAMA_ORIGINS:[http://localhost https://localhost http://localhost:* https://localhost:* http://127.0.0.1 https://127.0.0.1 http://127.0.0.1:* https://127.0.0.1:* http://0.0.0.0 https://0.0.0.0 http://0.0.0.0:* https://0.0.0.0:* app://* file://* tauri://* vscode-webview://* vscode-file://*] OLLAMA_SCHED_SPREAD:false http_proxy: https_proxy: no_proxy:]\\\"\\n\",\n \"time=2025-03-22T13:14:00.309-04:00 level=INFO source=images.go:432 msg=\\\"total blobs: 52\\\"\\n\",\n \"time=2025-03-22T13:14:00.309-04:00 level=INFO source=images.go:439 msg=\\\"total unused blobs removed: 0\\\"\\n\",\n \"time=2025-03-22T13:14:00.310-04:00 level=INFO source=routes.go:1297 msg=\\\"Listening on 127.0.0.1:11434 (version 0.6.1)\\\"\\n\",\n \"time=2025-03-22T13:14:00.357-04:00 level=INFO source=types.go:130 msg=\\\"inference compute\\\" id=0 library=metal variant=\\\"\\\" compute=\\\"\\\" driver=0.0 name=\\\"\\\" total=\\\"21.3 GiB\\\" available=\\\"21.3 GiB\\\"\\n\",\n \"^C\\n\"\n ]\n }\n ],\n \"source\": [\n \"!ollama pull llama3.2\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 42,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \"Why did the AI agent go to therapy?\\n\",\n \"\\n\",\n \"Because it was struggling to process its emotions.\\n\"\n ]\n }\n ],\n \"source\": [\n \"response = ollama.chat.completions.create(\\n\",\n \" model=\\\"llama3.2\\\",\\n\",\n \" messages=messages\\n\",\n \")\\n\",\n \"print(response.choices[0].message.content)\\n\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 46,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"from PyPDF2 import PdfReader\\n\",\n \"\\n\",\n \"reader = PdfReader(\\\"me/linkedin.pdf\\\")\\n\",\n \"linkedin = \\\"\\\"\\n\",\n \"for page in reader.pages:\\n\",\n \" text = page.extract_text()\\n\",\n \" if text:\\n\",\n \" linkedin += text\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": 45,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\": \"stdout\",\n \"output_type\": \"stream\",\n \"text\": [\n \" \\n\",\n \"Contact\\n\",\n \"ed.donner@gmail.com\\n\",\n \"www.linkedin.com/in/eddonner\\n\",\n \"(LinkedIn)\\n\",\n \"edwarddonner.com (Personal)\\n\",\n \"Top Skills\\n\",\n \"CTO\\n\",\n \"Large Language Models (LLM)\\n\",\n \"PyTorch\\n\",\n \"Patents\\n\",\n \"Apparatus for determining role\\n\",\n \"fitness while eliminating unwanted\\n\",\n \"biasEd Donner\\n\",\n \"Co-Founder & CTO at Nebula.io, repeat Co-Founder of AI startups,\\n\",\n \"speaker & advisor on Gen AI and LLM Engineering\\n\",\n \"New York, New York, United States\\n\",\n \"Summary\\n\",\n \"I’m a technology leader and entrepreneur. I'm applying AI to a field\\n\",\n \"where it can make a massive impact: helping people discover their\\n\",\n \"potential and pursue their reason for being. But at my core, I’m a\\n\",\n \"software engineer and a scientist. I learned how to code aged 8 and\\n\",\n \"still spend weekends experimenting with Large Language Models\\n\",\n \"and writing code (rather badly). If you’d like to join us to show me\\n\",\n \"how it’s done.. message me!\\n\",\n \"As a work-hobby, I absolutely love giving talks about Gen AI and\\n\",\n \"LLMs. I'm the author of a best-selling, top-rated Udemy course\\n\",\n \"on LLM Engineering, and I speak at O'Reilly Live Events and\\n\",\n \"ODSC workshops. It brings me great joy to help others unlock the\\n\",\n \"astonishing power of LLMs.\\n\",\n \"I spent most of my career at JPMorgan building software for financial\\n\",\n \"markets. I worked in London, Tokyo and New York. I became an MD\\n\",\n \"running a global organization of 300. Then I left to start my own AI\\n\",\n \"business, untapt, to solve the problem that had plagued me at JPM -\\n\",\n \"why is so hard to hire engineers?\\n\",\n \"At untapt we worked with GQR, one of the world's fastest growing\\n\",\n \"recruitment firms. We collaborated on a patented invention in AI\\n\",\n \"and talent. Our skills were perfectly complementary - AI leaders vs\\n\",\n \"recruitment leaders - so much so, that we decided to join forces. In\\n\",\n \"2020, untapt was acquired by GQR’s parent company and Nebula\\n\",\n \"was born.\\n\",\n \"I’m now Co-Founder and CTO for Nebula, responsible for software\\n\",\n \"engineering and data science. Our stack is Python/Flask, React,\\n\",\n \"Mongo, ElasticSearch, with Kubernetes on GCP. Our 'secret sauce'\\n\",\n \"is our use of Gen AI and proprietary LLMs. If any of this sounds\\n\",\n \"interesting - we should talk!\\n\",\n \" Page 1 of 5 \\n\",\n \"Experience\\n\",\n \"Nebula.io\\n\",\n \"Co-Founder & CTO\\n\",\n \"June 2021 - Present (3 years 10 months)\\n\",\n \"New York, New York, United States\\n\",\n \"I’m the co-founder and CTO of Nebula.io. We help recruiters source,\\n\",\n \"understand, engage and manage talent, using Generative AI / proprietary\\n\",\n \"LLMs. Our patented model matches people with roles with greater accuracy\\n\",\n \"and speed than previously imaginable — no keywords required.\\n\",\n \"Our long term goal is to help people discover their potential and pursue their\\n\",\n \"reason for being, motivated by a concept called Ikigai. We help people find\\n\",\n \"roles where they will be most fulfilled and successful; as a result, we will raise\\n\",\n \"the level of human prosperity. It sounds grandiose, but since 77% of people\\n\",\n \"don’t consider themselves inspired or engaged at work, it’s completely within\\n\",\n \"our reach.\\n\",\n \"Simplified.Travel\\n\",\n \"AI Advisor\\n\",\n \"February 2025 - Present (2 months)\\n\",\n \"Simplified Travel is empowering destinations to deliver unforgettable, data-\\n\",\n \"driven journeys at scale.\\n\",\n \"I'm giving AI advice to enable highly personalized itinerary solutions for DMOs,\\n\",\n \"hotels and tourism organizations, enhancing traveler experiences.\\n\",\n \"GQR Global Markets\\n\",\n \"Chief Technology Officer\\n\",\n \"January 2020 - Present (5 years 3 months)\\n\",\n \"New York, New York, United States\\n\",\n \"As CTO of parent company Wynden Stark, I'm also responsible for innovation\\n\",\n \"initiatives at GQR.\\n\",\n \"Wynden Stark\\n\",\n \"Chief Technology Officer\\n\",\n \"January 2020 - Present (5 years 3 months)\\n\",\n \"New York, New York, United States\\n\",\n \"With the acquisition of untapt, I transitioned to Chief Technology Officer for the\\n\",\n \"Wynden Stark Group, responsible for Data Science and Engineering.\\n\",\n \" Page 2 of 5 \\n\",\n \"untapt\\n\",\n \"6 years 4 months\\n\",\n \"Founder, CTO\\n\",\n \"May 2019 - January 2020 (9 months)\\n\",\n \"Greater New York City Area\\n\",\n \"I founded untapt in October 2013; emerged from stealth in 2014 and went\\n\",\n \"into production with first product in 2015. In May 2019, I handed over CEO\\n\",\n \"responsibilities to Gareth Moody, previously the Chief Revenue Officer, shifting\\n\",\n \"my focus to the technology and product.\\n\",\n \"Our core invention is an Artificial Neural Network that uses Deep Learning /\\n\",\n \"NLP to understand the fit between candidates and roles.\\n\",\n \"Our SaaS products are used in the Recruitment Industry to connect people\\n\",\n \"with jobs in a highly scalable way. Our products are also used by Corporations\\n\",\n \"for internal and external hiring at high volume. We have strong SaaS metrics\\n\",\n \"and trends, and a growing number of bellwether clients.\\n\",\n \"Our Deep Learning / NLP models are developed in Python using Google\\n\",\n \"TensorFlow. Our tech stack is React / Redux and Angular HTML5 front-end\\n\",\n \"with Python / Flask back-end and MongoDB database. We are deployed on\\n\",\n \"the Google Cloud Platform using Kubernetes container orchestration.\\n\",\n \"Interview at NASDAQ: https://www.pscp.tv/w/1mnxeoNrEvZGX\\n\",\n \"Founder, CEO\\n\",\n \"October 2013 - May 2019 (5 years 8 months)\\n\",\n \"Greater New York City Area\\n\",\n \"I founded untapt in October 2013; emerged from stealth in 2014 and went into\\n\",\n \"production with first product in 2015.\\n\",\n \"Our core invention is an Artificial Neural Network that uses Deep Learning /\\n\",\n \"NLP to understand the fit between candidates and roles.\\n\",\n \"Our SaaS products are used in the Recruitment Industry to connect people\\n\",\n \"with jobs in a highly scalable way. Our products are also used by Corporations\\n\",\n \"for internal and external hiring at high volume. We have strong SaaS metrics\\n\",\n \"and trends, and a growing number of bellwether clients.\\n\",\n \" Page 3 of 5 \\n\",\n \"Our Deep Learning / NLP models are developed in Python using Google\\n\",\n \"TensorFlow. Our tech stack is React / Redux and Angular HTML5 front-end\\n\",\n \"with Python / Flask back-end and MongoDB database. We are deployed on\\n\",\n \"the Google Cloud Platform using Kubernetes container orchestration.\\n\",\n \"-- Graduate of FinTech Innovation Lab\\n\",\n \"-- American Banker Top 20 Company To Watch\\n\",\n \"-- Voted AWS startup most likely to grow exponentially\\n\",\n \"-- Forbes contributor\\n\",\n \"More at https://www.untapt.com\\n\",\n \"Interview at NASDAQ: https://www.pscp.tv/w/1mnxeoNrEvZGX\\n\",\n \"In Fast Company: https://www.fastcompany.com/3067339/how-artificial-\\n\",\n \"intelligence-is-changing-the-way-companies-hire\\n\",\n \"JPMorgan Chase\\n\",\n \"11 years 6 months\\n\",\n \"Managing Director\\n\",\n \"May 2011 - March 2013 (1 year 11 months)\\n\",\n \"Head of Technology for the Credit Portfolio Group and Hedge Fund Credit in\\n\",\n \"the JPMorgan Investment Bank.\\n\",\n \"Led a team of 300 Java and Python software developers across NY, Houston,\\n\",\n \"London, Glasgow and India. Responsible for counterparty exposure, CVA\\n\",\n \"and risk management platforms, including simulation engines in Python that\\n\",\n \"calculate counterparty credit risk for the firm's Derivatives portfolio.\\n\",\n \"Managed the electronic trading limits initiative, and the Credit Stress program\\n\",\n \"which calculates risk information under stressed conditions. Jointly responsible\\n\",\n \"for Market Data and batch infrastructure across Risk.\\n\",\n \"Executive Director\\n\",\n \"January 2007 - May 2011 (4 years 5 months)\\n\",\n \"From Jan 2008:\\n\",\n \"Chief Business Technologist for the Credit Portfolio Group and Hedge Fund\\n\",\n \"Credit in the JPMorgan Investment Bank, building Java and Python solutions\\n\",\n \"and managing a team of full stack developers.\\n\",\n \"2007:\\n\",\n \" Page 4 of 5 \\n\",\n \"Responsible for Credit Risk Limits Monitoring infrastructure for Derivatives and\\n\",\n \"Cash Securities, developed in Java / Javascript / HTML.\\n\",\n \"VP\\n\",\n \"July 2004 - December 2006 (2 years 6 months)\\n\",\n \"Managed Collateral, Netting and Legal documentation technology across\\n\",\n \"Derivatives, Securities and Traditional Credit Products, including Java, Oracle,\\n\",\n \"SQL based platforms\\n\",\n \"VP\\n\",\n \"October 2001 - June 2004 (2 years 9 months)\\n\",\n \"Full stack developer, then manager for Java cross-product risk management\\n\",\n \"system in Credit Markets Technology\\n\",\n \"Cygnifi\\n\",\n \"Project Leader\\n\",\n \"January 2000 - September 2001 (1 year 9 months)\\n\",\n \"Full stack developer and engineering lead, developing Java and Javascript\\n\",\n \"platform to risk manage Interest Rate Derivatives at this FInTech startup and\\n\",\n \"JPMorgan spin-off.\\n\",\n \"JPMorgan\\n\",\n \"Associate\\n\",\n \"July 1997 - December 1999 (2 years 6 months)\\n\",\n \"Full stack developer for Exotic and Flow Interest Rate Derivatives risk\\n\",\n \"management system in London, New York and Tokyo\\n\",\n \"IBM\\n\",\n \"Software Developer\\n\",\n \"August 1995 - June 1997 (1 year 11 months)\\n\",\n \"Java and Smalltalk developer with IBM Global Services; taught IBM classes on\\n\",\n \"Smalltalk and Object Technology in the UK and around Europe\\n\",\n \"Education\\n\",\n \"University of Oxford\\n\",\n \"Physics · (1992 - 1995)\\n\",\n \" Page 5 of 5\\n\"\n ]\n }\n ],\n \"source\": [\n \"print(linkedin)\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": []\n }\n ],\n \"metadata\": {\n \"kernelspec\": {\n \"display_name\": \".venv\",\n \"language\": \"python\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"codemirror_mode\": {\n \"name\": \"ipython\",\n \"version\": 3\n },\n \"file_extension\": \".py\",\n \"mimetype\": \"text/x-python\",\n \"name\": \"python\",\n \"nbconvert_exporter\": \"python\",\n \"pygments_lexer\": \"ipython3\",\n \"version\": \"3.12.9\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n"}}}}