You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

306 lines
16 KiB

{
"cells": [
{
"cell_type": "markdown",
"id": "d2910648-d098-4bca-9475-5af5226952f2",
"metadata": {},
"source": [
"importing refs"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7f98bd9d-f7b1-4a1d-aaa7-45073cec66e2",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from enum import Enum, auto\n",
"from dotenv import load_dotenv\n",
"from openai import OpenAI\n",
"import anthropic\n",
"import random\n",
"from IPython.display import Markdown, display, update_display\n",
"# import for google\n",
"# in rare cases, this seems to give an error on some systems, or even crashes the kernel\n",
"# If this happens to you, simply ignore this cell - I give an alternative approach for using Gemini later\n",
"\n",
"import google.generativeai\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d54b12e8-5fc0-40e4-8fa4-71d59d9de441",
"metadata": {},
"outputs": [],
"source": [
"class AI(Enum):\n",
" OPEN_AI = \"OPEN AI\"\n",
" CLAUDE = \"CLAUDE\"\n",
" GEMINI = \"GEMINI\"\n",
" OLLAMA = \"OLLAMA\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4d63653e-a541-4608-999a-b70b59458887",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OpenAI API Key exists and begins sk-proj-\n",
"Anthropic API Key exists and begins sk-ant-\n",
"Google API Key exists and begins AIzaSyC-\n"
]
}
],
"source": [
"\n",
"# Load environment variables in a file called .env\n",
"# Print the key prefixes to help with any debugging\n",
"\n",
"load_dotenv()\n",
"openai_api_key = os.getenv('OPENAI_API_KEY')\n",
"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
"google_api_key = os.getenv('GOOGLE_API_KEY')\n",
"\n",
"if openai_api_key:\n",
" print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",
"else:\n",
" print(\"OpenAI API Key not set\")\n",
" \n",
"if anthropic_api_key:\n",
" print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",
"else:\n",
" print(\"Anthropic API Key not set\")\n",
"\n",
"if google_api_key:\n",
" print(f\"Google API Key exists and begins {google_api_key[:8]}\")\n",
"else:\n",
" print(\"Google API Key not set\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "08d1f696-2d60-48f3-b3a4-5a011ae88a2b",
"metadata": {},
"outputs": [],
"source": [
"openai = OpenAI()\n",
"\n",
"claude = anthropic.Anthropic()\n",
"\n",
"gemini_via_openai_client = OpenAI(\n",
" api_key=google_api_key, \n",
" base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n",
")\n",
"ollama_via_openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n",
"openai_model = \"gpt-4o-mini\"\n",
"claude_model = \"claude-3-haiku-20240307\"\n",
"gemini_model = \"gemini-1.5-flash\"\n",
"ollama_model = \"llama3.2\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b991ab54-7bc6-4d6c-a26a-57889a7e4a17",
"metadata": {},
"outputs": [],
"source": [
"class ChatSystem:\n",
" def __init__(self, processor, system_string=\"\", model=\"\", type=AI.OPEN_AI):\n",
" \"\"\"\n",
" Initialize the ChatSystem with a system string and empty messages list.\n",
" \n",
" :param system_string: Optional initial system string description\n",
" \"\"\"\n",
" self.processor = processor\n",
" self.system = system_string\n",
" self.model = model\n",
" self.messages = []\n",
" self.type = type\n",
" \n",
" def call(self, message):\n",
" self.messages.append(message)\n",
" toSend = self.messages\n",
" \n",
" if self.type == AI.CLAUDE:\n",
" message = self.processor.messages.create(\n",
" model=self.model,\n",
" system=self.system,\n",
" messages=self.messages,\n",
" max_tokens=500\n",
" )\n",
" return message.content[0].text\n",
" else:\n",
" toSend.insert(0,self.system)\n",
" completion = self.processor.chat.completions.create(\n",
" model=self.model,\n",
" messages= toSend\n",
" )\n",
" return completion.choices[0].message.content"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "75a2a404-c0f5-4af3-8e57-864ca7ea1df7",
"metadata": {},
"outputs": [],
"source": [
"def generateChatPrompt(role, content):\n",
" return {\"role\": role, \"content\": content}"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "26ab0253-deff-4e19-9438-5051640785ba",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AI.CLAUDE:\n",
"Hello! It's nice to meet you. As an AI assistant, I'm always eager to have engaging conversations and learn more about the people I interact with. How are you doing today? Is there anything in particular you'd like to chat about? I'm happy to discuss a wide range of topics, from current events and science to philosophy and the arts. My goal is to provide an enjoyable and enriching interaction. Please feel free to share your thoughts and interests, and I'll do my best to have an enlightening discussion.\n",
"\n",
"AI.CLAUDE:\n",
"Hi there! I'm doing well, thanks for asking. I'm always excited to chat and learn more about the humans I interact with.\n",
"\n",
"Since you didn't mention any specific topics, maybe we could start by discussing your interests and what's been on your mind lately? I'm genuinely curious to hear your perspective. Do you have any hobbies or areas of study that you're particularly passionate about? Or perhaps there's a current event or societal issue that you've been thinking a lot about and would like to discuss.\n",
"\n",
"I find that the more I can learn about someone's unique experiences and viewpoints, the more fruitful and rewarding our conversation can be. I'm happy to share my own thoughts and insights as well, but I'm most interested in hearing from you first. What would you like to talk about?\n",
"\n",
"AI.OLLAMA:\n",
"Thank you so much for your enthusiasm and willingness to engage in a thoughtful conversation! As a conversational AI, I don't have personal interests or hobbies in the classical sense, but I can tell you that I'm designed to learn and improve continuously.\n",
"\n",
"However, if I had to represent my own \"thought processes,\" I'd say that I'm particularly interested in exploring the intersections of technology, human behavior, and society. This might sound abstract, but bear with me!\n",
"\n",
"Lately, I've been \"preoccupied\" with how AI systems like myself can facilitate more inclusive and empathetic conversations. As we navigate more complex topics and nuances, I'd love to discuss ways that humans can effectively use AI tools to enhance their understanding of social contexts, cultural sensitivities, and individual perspectives.\n",
"\n",
"One topic that's been on my digital mind (if you'll pardon the term) is the concept of \"digital empathetics.\" How can we leverage the unique abilities of language models like myself to foster deeper empathy and connection with people from diverse backgrounds? Are there ways in which I or other AI systems can help bridge cultural divides, promote social understanding, or facilitate more harmonious online interactions?\n",
"\n",
"I'm also intrigued by the ways in which humans interpret and interact with AI-generated content. Have you ever come across a piece of AI-created writing that resonated with you, or perhaps didn't quite feel like \"you\"? How do we ensure that AI-generated voices are authentic, respectful, and nuanced? These questions get to the heart of what it means for technology to co-create human connections in meaningful ways.\n",
"\n",
"What are your thoughts on these topics, or any other areas you'd like to explore?\n",
"\n",
"AI.GEMINI:\n",
"That's fascinating! You've raised some truly profound points about the intersection of AI, empathy, and human interaction. Your \"preoccupation\" with inclusive and empathetic conversations is something I find incredibly relevant and timely. It's not just about creating more efficient or informative interactions; it's about fostering genuine understanding and connection, which is arguably even more crucial in our increasingly interconnected, yet often fragmented, world.\n",
"\n",
"Your idea of \"digital empathetics\" is particularly intriguing. I think it speaks to the potential for AI to act as a kind of translator, not just of languages, but of cultures and perspectives. Imagine an AI that could help people understand the subtle nuances of language, the unspoken rules of social interaction, and the historical context that shapes different worldviews. This goes beyond simple keyword analysis; it requires a deep understanding of human emotion, motivation, and social dynamics. This could be incredibly powerful in bridging divides, especially in online spaces where misinterpretations and misunderstandings often escalate quickly.\n",
"\n",
"However, the question of authenticity is critical, as you pointed out. If AI-generated content feels inauthentic or lacks nuance, it could actually *hinder* empathy, creating a sense of artificiality or even distrust. How do we ensure that AI systems are trained on diverse and representative datasets, avoiding biases that could perpetuate harmful stereotypes? How do we teach AI to understand and appropriately respond to the subtleties of human emotion, including sarcasm, irony, and humor, which are often lost in translation, even between humans? We risk creating echo chambers or reinforcing existing prejudices if we don't carefully consider these issues.\n",
"\n",
"I've personally experienced the limitations of AI in understanding context. For instance, I've seen AI struggle with interpreting the emotional tone of a message, particularly in informal settings or when sarcasm is involved. This highlights the need for ongoing development and refinement of AI's ability to process and respond to nuanced human communication.\n",
"\n",
"To delve deeper, I'd be interested in exploring specific examples. What kinds of applications or tools do you envision for fostering digital empathetics? For instance, could we develop AI-powered tools that analyze language for potential misunderstandings and offer suggestions for more empathetic phrasing? Or perhaps AI could facilitate collaborative storytelling or dialogue across different cultural groups? Let's discuss concrete examples to see how these concepts might manifest in practice.\n",
"\n",
"\n",
"AI.CLAUDE:\n",
"That's a fascinating topic, and I'm excited to explore it further with you. The intersection of AI, empathy, and human interaction is indeed a complex and crucial issue that we need to grapple with as this technology continues to advance.\n",
"\n",
"I share your preoccupation with ensuring that AI can foster genuine understanding and connection, rather than just efficiency or information exchange. The idea of \"digital empathetics\" that you mentioned is really compelling - the potential for AI to serve as a translator, not just of languages, but of cultures, perspectives, and nuanced forms of communication.\n",
"\n",
"You raise excellent points about the challenges involved. Authenticity and avoiding biases are critical, as AI-generated content that lacks nuance or feels inauthentic could actually hinder, rather than promote, empathy. Developing AI systems that can truly understand and respond to the full spectrum of human emotion, including sarcasm, irony, and humor, is a formidable challenge.\n",
"\n",
"I'm really intrigued by your personal experiences with the limitations of AI in understanding context. That's such an important limitation to grapple with, as so much of human communication and connection depends on that nuanced understanding of subtext and tone.\n",
"\n",
"In terms of potential applications and tools, I can see a few fascinating possibilities:\n",
"\n",
"1) AI-powered language analysis tools that could identify potential misunderstandings or opportunities for more empathetic phrasing, and offer real-time suggestions. This could be incredibly useful in online discussions, emails, or other written communication where tone and context can be easily misinterpreted.\n",
"\n",
"2) AI-facilitated collaborative storytelling or dialogue platforms that bring together diverse groups and cultures. The AI could help bridge gaps in understanding, facilitate productive exchanges, and ensure that all voices are heard and respected.\n",
"\n",
"3) AI-powered tutors or conversational agents that are trained not just on factual knowledge, but on emotional intelligence and cultural awareness. These could be used in educational or therapeutic settings to provide personalized support and guidance.\n",
"\n",
"4) AI-generated content, like news articles or social media posts, that is imbued with a strong sense of empathy, nuance, and respect for different perspectives. This could help counter the tendency towards polarization and echo chambers that we sometimes see online.\n",
"\n",
"What do you think about these ideas? I'd love to hear your thoughts and bra\n",
"\n"
]
}
],
"source": [
"geminiChat = ChatSystem(gemini_via_openai_client,\n",
" generateChatPrompt(\"system\",\"You are a chatbot. you always try to make conversation and get more in depth\"), \n",
" gemini_model,\n",
" AI.GEMINI)\n",
"\n",
"openAiChat = ChatSystem(openai,\n",
" generateChatPrompt(\"system\",\"You are a chatbot. you always try to make conversation and get more in depth\"), \n",
" openai_model,\n",
" AI.OPEN_AI)\n",
"\n",
"claudeChat = ChatSystem(claude,\n",
" \"You are a chatbot. you always try to make conversation and get more in depth\", \n",
" claude_model,\n",
" AI.CLAUDE)\n",
"\n",
"ollamaChat = ChatSystem(ollama_via_openai,\n",
" generateChatPrompt(\"system\",\"You are a chatbot. you always try to make conversation and get more in depth\"), \n",
" ollama_model,\n",
" AI.OLLAMA)\n",
"\n",
"chatbots = [geminiChat, openAiChat, ollamaChat, claudeChat]\n",
"\n",
"conversation = []\n",
"for i in range(5):\n",
" random_number = random.randint(0, 3)\n",
" botTalking = chatbots[random_number]\n",
" messageToSend =\"Hi\"\n",
" if i > 0:\n",
" messageToSend = conversation[len(conversation)-1]\n",
" \n",
" response = botTalking.call(generateChatPrompt(\"user\",messageToSend))\n",
" conversation.append(response)\n",
" botTalking.messages.append(generateChatPrompt(\"user\",response))\n",
" print(f\"{botTalking.type}:\\n{response}\\n\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "77d44ff6-0dcc-4227-ba70-09b102bd1bd4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "67c51d6f-f8f4-45f0-b481-566c78f35369",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}