From aed79ce28f72fac44ecb5fc160fda6f591796718 Mon Sep 17 00:00:00 2001 From: Bill Glennon <1130086+billglennon@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:36:30 -0500 Subject: [PATCH] add gemini to brochure, add tone to brochure, had to add safety_settings for google gemini to work with brochure --- .../Week2_Day2_AddGeminModel.ipynb | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb b/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb index 3011f7b..ccd8a6e 100644 --- a/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb +++ b/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb @@ -318,15 +318,20 @@ "def stream_gemini(prompt):\n", " gemini = genai.GenerativeModel(\n", " model_name='gemini-1.5-flash',\n", + " safety_settings=None,\n", " system_instruction=system_message\n", " )\n", "\n", - " response = gemini.generate_content(prompt, stream=True)\n", + " response = gemini.generate_content(prompt, safety_settings=[\n", + " {\"category\": \"HARM_CATEGORY_DANGEROUS_CONTENT\", \"threshold\": \"BLOCK_NONE\"},\n", + " {\"category\": \"HARM_CATEGORY_SEXUALLY_EXPLICIT\", \"threshold\": \"BLOCK_NONE\"},\n", + " {\"category\": \"HARM_CATEGORY_HATE_SPEECH\", \"threshold\": \"BLOCK_NONE\"},\n", + " {\"category\": \"HARM_CATEGORY_HARASSMENT\", \"threshold\": \"BLOCK_NONE\"}], stream=True)\n", " \n", " result = \"\"\n", " for chunk in response:\n", " result += chunk.text\n", - " yield result" + " yield result\n" ] }, { @@ -489,8 +494,8 @@ "metadata": {}, "outputs": [], "source": [ - "system_prompt = \"You are an assistant that analyzes the contents of a company website landing page \\\n", - "and creates a short brochure about the company for prospective customers, investors and recruits. Respond in markdown.\"" + "system_message = \"You are an assistant that analyzes the contents of a company website landing page \\\n", + "and creates a short brochure about the company for prospective customers, investors and recruits. Do not use any logos. Respond in markdown.\"" ] }, { @@ -500,13 +505,15 @@ "metadata": {}, "outputs": [], "source": [ - "def stream_brochure(company_name, url, model):\n", - " prompt = f\"Please generate a company brochure for {company_name}. Here is their landing page:\\n\"\n", + "def stream_brochure(company_name, url, model, response_tone):\n", + " prompt = f\"Please generate a {response_tone} company brochure for {company_name}. Here is their landing page:\\n\"\n", " prompt += Website(url).get_contents()\n", " if model==\"GPT\":\n", " result = stream_gpt(prompt)\n", " elif model==\"Claude\":\n", " result = stream_claude(prompt)\n", + " elif model==\"Gemini\":\n", + " result = stream_gemini(prompt)\n", " else:\n", " raise ValueError(\"Unknown model\")\n", " yield from result" @@ -524,7 +531,8 @@ " inputs=[\n", " gr.Textbox(label=\"Company name:\"),\n", " gr.Textbox(label=\"Landing page URL including http:// or https://\"),\n", - " gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\")],\n", + " gr.Dropdown([\"GPT\", \"Claude\", \"Gemini\"], label=\"Select model\"),\n", + " gr.Dropdown([\"Informational\", \"Promotional\", \"Humorous\"], label=\"Select tone\")],\n", " outputs=[gr.Markdown(label=\"Brochure:\")],\n", " flagging_mode=\"never\"\n", ")\n",