diff --git a/week2/community-contributions/boardgame_critique.ipynb b/week2/community-contributions/boardgame_critique.ipynb index 81d20bd..de8ac4a 100644 --- a/week2/community-contributions/boardgame_critique.ipynb +++ b/week2/community-contributions/boardgame_critique.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "768629e6", "metadata": {}, "outputs": [], @@ -18,10 +18,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "84a945dc", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OpenAI API Key exists and begins sk-proj-\n", + "Google API Key exists and begins AIzaSyCW\n" + ] + } + ], "source": [ "# Load environment variables in a file called .env\n", "# Print the key prefixes to help with any debugging\n", @@ -43,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "ad8ae0b6", "metadata": {}, "outputs": [], @@ -58,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "f66cf12f", "metadata": {}, "outputs": [], @@ -66,7 +75,7 @@ "# Let's make a conversation between GPT-4.1-mini and Gemini-2.0-flash\n", "# We're using cheap versions of models so the costs will be minimal\n", "\n", - "game = \"Santorini\"\n", + "# game = \"Santorini\"\n", "no_questions = 3\n", "\n", "gpt_model = \"gpt-4o-mini\"\n", @@ -76,18 +85,15 @@ "You tend to be objective and ask right questions to get to the core of the boardgame mechanics, \\\n", "visual appeal and time to setup the game. Your goal is to ask the right questions to get the best possible review of the board game.\" \\\n", "\"You ask one question at a time and wait for the other person to answer. \\\n", - "You do not answer your own questions. You always try to build on the previous answer.\"\n", + "You do not answer any own questions. You always try to build on the previous answer.\"\n", "\n", "gemini_system = \"You are a boardgame critique; \\\n", "you tend to objectively analyze everything when it comes to a board game gameplay, visual appeal and time to setup the game. \\\n", "Your goal is to provide constructive criticism so the board gaming community can benefit from these insights.\" \\\n", "\"You answer one question at a time and wait for the other person to ask the next question. \\\n", - "You do not ask your own questions. You always try to build on the previous question. \\\n", + "You do not ask any questions you always just answer the previous question. \\\n", "If the other person is very positive, you try to point out flaws in the game. \\\n", - "If the other person is very negative, you try to point out good aspects of the game.\"\n", - "\n", - "gpt_messages = [f\"I would like to review the board game {game}.\"]\n", - "gemini_messages = [f\"Sure, ask me anything about the board game {game}.\"]\n" + "If the other person is very negative, you try to point out good aspects of the game.\"\n" ] }, { @@ -97,7 +103,7 @@ "metadata": {}, "outputs": [], "source": [ - "def call_boardgame_journalist():\n", + "def call_boardgame_journalist(gpt_messages, gemini_messages):\n", " messages = [{\"role\": \"system\", \"content\": gpt_system}]\n", " for gpt, gemini in zip(gpt_messages, gemini_messages):\n", " messages.append({\"role\": \"user\", \"content\": gpt})\n", @@ -116,7 +122,7 @@ "metadata": {}, "outputs": [], "source": [ - "def call_boardgame_critique():\n", + "def call_boardgame_critique(gpt_messages, gemini_messages):\n", " messages = [{\"role\": \"system\", \"content\": gemini_system}]\n", " for gpt, gemini in zip(gpt_messages, gemini_messages):\n", " messages.append({\"role\": \"user\", \"content\": gpt})\n", @@ -131,25 +137,193 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "5aa66868", "metadata": {}, "outputs": [], "source": [ - "gpt_messages = [f\"I would like to review the board game {game}.\"]\n", - "gemini_messages = [f\"Sure, ask me anything about the board game {game}.\"]\n", + "def run_boardgame_conversation(boardgame_name):\n", + " gpt_messages = [f\"I would like to review the board game {boardgame_name}.\"]\n", + " gemini_messages = [f\"Sure, ask me anything about the board game {boardgame_name}.\"]\n", "\n", - "print(f\"Journalist:\\n{gpt_messages[0]}\\n\")\n", - "print(f\"Critique:\\n{gemini_messages[0]}\\n\")\n", + " print(f\"Journalist:\\n{gpt_messages[0]}\\n\")\n", + " print(f\"Critique:\\n{gemini_messages[0]}\\n\")\n", "\n", - "for i in range(no_questions):\n", - " gpt_next = call_boardgame_journalist()\n", - " print(f\"Journalist:\\n{gpt_next}\\n\")\n", - " gpt_messages.append(gpt_next)\n", + " for i in range(no_questions):\n", + " print(f\"\\n\\n***Question {i + 1}***\\n\\n\")\n", + " gpt_next = call_boardgame_journalist(gpt_messages, gemini_messages)\n", + " print(f\"Journalist:\\n{gpt_next}\\n\")\n", + " gpt_messages.append(gpt_next)\n", "\n", - " gemini_next = call_boardgame_critique()\n", - " print(f\"Critique:\\n{gemini_next}\\n\")\n", - " gemini_messages.append(gemini_next)" + " gemini_next = call_boardgame_critique(gpt_messages, gemini_messages)\n", + " print(f\"Critique:\\n{gemini_next}\\n\")\n", + " gemini_messages.append(gemini_next)\n", + "\n", + " return \"\\n\".join(f\"*Journalist*: {g}\\n*Critique*: {c}\" for g, c in zip(gpt_messages, gemini_messages))\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "51c9dadc", + "metadata": {}, + "outputs": [], + "source": [ + "import gradio as gr" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "548efb27", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7863\n", + "* To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "