From 8ec6a15aaef11541a30741465d5c63e85b4abce2 Mon Sep 17 00:00:00 2001 From: Thomas Capelle Date: Mon, 3 Jun 2024 12:09:00 +0200 Subject: [PATCH] clean up --- ..._to_use_Gemini_Pro_API_with_WB_Weave.ipynb | 153 +++++------------- colabs/gemini/google-demo-rag.ipynb | 22 +-- 2 files changed, 45 insertions(+), 130 deletions(-) diff --git a/colabs/gemini/How_to_use_Gemini_Pro_API_with_WB_Weave.ipynb b/colabs/gemini/How_to_use_Gemini_Pro_API_with_WB_Weave.ipynb index 18acbe5e..bc161655 100644 --- a/colabs/gemini/How_to_use_Gemini_Pro_API_with_WB_Weave.ipynb +++ b/colabs/gemini/How_to_use_Gemini_Pro_API_with_WB_Weave.ipynb @@ -2,7 +2,6 @@ "cells": [ { "cell_type": "markdown", - "id": "c5eb1db5-a89e-4bba-8a4c-078b647be1b7", "metadata": {}, "source": [ "\"Open\n", @@ -12,9 +11,7 @@ { "cell_type": "markdown", "id": "_7u7Ft1-GXrK", - "metadata": { - "id": "_7u7Ft1-GXrK" - }, + "metadata": {}, "source": [ "# How to use Gemini Pro API with W&B Weave\n", "\n", @@ -24,9 +21,7 @@ { "cell_type": "markdown", "id": "Nk3L-jqbGsrN", - "metadata": { - "id": "Nk3L-jqbGsrN" - }, + "metadata": {}, "source": [ "## Installation" ] @@ -35,9 +30,7 @@ "cell_type": "code", "execution_count": null, "id": "4fdc0c0e-bc69-41ed-9b09-ec469a3a781b", - "metadata": { - "id": "4fdc0c0e-bc69-41ed-9b09-ec469a3a781b" - }, + "metadata": {}, "outputs": [], "source": [ "%%capture\n", @@ -48,9 +41,7 @@ "cell_type": "code", "execution_count": null, "id": "fiI5pF6WGyd_", - "metadata": { - "id": "fiI5pF6WGyd_" - }, + "metadata": {}, "outputs": [], "source": [ "import google.generativeai as genai\n", @@ -60,9 +51,7 @@ { "cell_type": "markdown", "id": "Avj5TxGjFhE9", - "metadata": { - "id": "Avj5TxGjFhE9" - }, + "metadata": {}, "source": [ "## Set up your Google API key and log into W&B Weave\n", "\n", @@ -73,9 +62,7 @@ "cell_type": "code", "execution_count": null, "id": "d0Lv-deDFgLl", - "metadata": { - "id": "d0Lv-deDFgLl" - }, + "metadata": {}, "outputs": [], "source": [ "from google.colab import userdata\n", @@ -87,9 +74,7 @@ "cell_type": "code", "execution_count": null, "id": "894d8781-bea4-4f74-b1cd-b893f91bfee6", - "metadata": { - "id": "894d8781-bea4-4f74-b1cd-b893f91bfee6" - }, + "metadata": {}, "outputs": [], "source": [ "weave.init('prompt-eng/gemini-weave')" @@ -98,9 +83,7 @@ { "cell_type": "markdown", "id": "wFiQm3JAJpvw", - "metadata": { - "id": "wFiQm3JAJpvw" - }, + "metadata": {}, "source": [ "## Generate a summary and track it in Weave" ] @@ -109,9 +92,7 @@ "cell_type": "code", "execution_count": null, "id": "82d096fc-309a-4c57-a3a8-926d88a520d3", - "metadata": { - "id": "82d096fc-309a-4c57-a3a8-926d88a520d3" - }, + "metadata": {}, "outputs": [], "source": [ "%%capture\n", @@ -124,9 +105,7 @@ "cell_type": "code", "execution_count": null, "id": "3343fcb9-b96d-478d-a4a8-fbb1e7b27a34", - "metadata": { - "id": "3343fcb9-b96d-478d-a4a8-fbb1e7b27a34" - }, + "metadata": {}, "outputs": [], "source": [ "model_info = genai.get_model('models/gemini-1.5-pro-latest')\n", @@ -137,9 +116,7 @@ "cell_type": "code", "execution_count": null, "id": "03216cd4-9fca-4dcb-aa73-b250cda7ef26", - "metadata": { - "id": "03216cd4-9fca-4dcb-aa73-b250cda7ef26" - }, + "metadata": {}, "outputs": [], "source": [ "model = genai.GenerativeModel('models/gemini-1.5-pro-latest')\n", @@ -150,9 +127,7 @@ "cell_type": "code", "execution_count": null, "id": "ba32823a-f4f1-4233-8389-590e8757e85e", - "metadata": { - "id": "ba32823a-f4f1-4233-8389-590e8757e85e" - }, + "metadata": {}, "outputs": [], "source": [ "@weave.op()\n", @@ -168,9 +143,7 @@ "cell_type": "code", "execution_count": null, "id": "9128199a-e13f-4d7e-b26c-55267ab8e161", - "metadata": { - "id": "9128199a-e13f-4d7e-b26c-55267ab8e161" - }, + "metadata": {}, "outputs": [], "source": [ "summary = generate_summary(long_paper_text)" @@ -179,9 +152,7 @@ { "cell_type": "markdown", "id": "ur0vXGNtJ5IF", - "metadata": { - "id": "ur0vXGNtJ5IF" - }, + "metadata": {}, "source": [ "## Gemini API JSON Mode" ] @@ -190,9 +161,7 @@ "cell_type": "code", "execution_count": null, "id": "4de6d4b7-f567-4070-b9d5-1867b72fc045", - "metadata": { - "id": "4de6d4b7-f567-4070-b9d5-1867b72fc045" - }, + "metadata": {}, "outputs": [], "source": [ "model = genai.GenerativeModel(\"gemini-1.5-pro-latest\",\n", @@ -203,9 +172,7 @@ "cell_type": "code", "execution_count": null, "id": "c403ccf8-58fd-4e8a-b951-91e7aa39022c", - "metadata": { - "id": "c403ccf8-58fd-4e8a-b951-91e7aa39022c" - }, + "metadata": {}, "outputs": [], "source": [ "from pydantic import BaseModel, Field\n", @@ -222,9 +189,7 @@ "cell_type": "code", "execution_count": null, "id": "9a49b8de-e40d-4dc5-8e79-97af5efb1797", - "metadata": { - "id": "9a49b8de-e40d-4dc5-8e79-97af5efb1797" - }, + "metadata": {}, "outputs": [], "source": [ "import json" @@ -234,9 +199,7 @@ "cell_type": "code", "execution_count": null, "id": "10b19a45-c4a9-47be-abda-97607f0e4431", - "metadata": { - "id": "10b19a45-c4a9-47be-abda-97607f0e4431" - }, + "metadata": {}, "outputs": [], "source": [ "@weave.op()\n", @@ -268,9 +231,7 @@ "cell_type": "code", "execution_count": null, "id": "b8b03f96-f04b-44b6-b03c-0065243408d3", - "metadata": { - "id": "b8b03f96-f04b-44b6-b03c-0065243408d3" - }, + "metadata": {}, "outputs": [], "source": [ "new_summary = generate_summary(long_paper_text, schema)" @@ -279,9 +240,7 @@ { "cell_type": "markdown", "id": "EFuMHhC5J8NO", - "metadata": { - "id": "EFuMHhC5J8NO" - }, + "metadata": {}, "source": [ "## Evaluation with Weave" ] @@ -290,9 +249,7 @@ "cell_type": "code", "execution_count": null, "id": "65abebe7-a0f4-4a7a-bdae-888d67e9403f", - "metadata": { - "id": "65abebe7-a0f4-4a7a-bdae-888d67e9403f" - }, + "metadata": {}, "outputs": [], "source": [ "from pydantic import model_validator\n", @@ -333,9 +290,7 @@ "cell_type": "code", "execution_count": null, "id": "4b8343cb-4a54-4fea-b2b0-b2c21b39e061", - "metadata": { - "id": "4b8343cb-4a54-4fea-b2b0-b2c21b39e061" - }, + "metadata": {}, "outputs": [], "source": [ "prompt_template = \"\"\"Generate a concise summary of below text using below JSON schema.\n", @@ -351,9 +306,7 @@ "cell_type": "code", "execution_count": null, "id": "d69ed0c0-e032-4ced-8fd8-919ee332a95f", - "metadata": { - "id": "d69ed0c0-e032-4ced-8fd8-919ee332a95f" - }, + "metadata": {}, "outputs": [], "source": [ "model = SummaryModel(model_name='gemini-1.5-pro-latest', prompt_template=prompt_template, \\\n", @@ -364,9 +317,7 @@ "cell_type": "code", "execution_count": null, "id": "3d78ca87-bd61-45e6-b62c-0b82754d2b79", - "metadata": { - "id": "3d78ca87-bd61-45e6-b62c-0b82754d2b79" - }, + "metadata": {}, "outputs": [], "source": [ "await model.predict(long_paper_text)" @@ -376,9 +327,7 @@ "cell_type": "code", "execution_count": null, "id": "dca5e402-0805-4888-8f08-0b28748fea11", - "metadata": { - "id": "dca5e402-0805-4888-8f08-0b28748fea11" - }, + "metadata": {}, "outputs": [], "source": [ "dataset_uri = \"weave:///prompt-eng/gemini-weave/object/long_papers:9N9vkE4XY1SYoXLbvbCtP0YKqyqXErilG4XW8jYmQgE\"\n", @@ -389,9 +338,7 @@ "cell_type": "code", "execution_count": null, "id": "de2f8804-dfd7-49b1-adbe-0a3dbb0c5ff1", - "metadata": { - "id": "de2f8804-dfd7-49b1-adbe-0a3dbb0c5ff1" - }, + "metadata": {}, "outputs": [], "source": [ "# Scoring function checking format adherence\n", @@ -412,9 +359,7 @@ "cell_type": "code", "execution_count": null, "id": "yfF8_ZsRMhYe", - "metadata": { - "id": "yfF8_ZsRMhYe" - }, + "metadata": {}, "outputs": [], "source": [ "# Scoring function checking length of summary\n", @@ -436,9 +381,7 @@ "cell_type": "code", "execution_count": null, "id": "1d1c6bdb-83f9-4a63-99c4-0b2f0d3e9139", - "metadata": { - "id": "1d1c6bdb-83f9-4a63-99c4-0b2f0d3e9139" - }, + "metadata": {}, "outputs": [], "source": [ "evaluation = weave.Evaluation(\n", @@ -450,9 +393,7 @@ "cell_type": "code", "execution_count": null, "id": "fa5b2822-55cf-4983-a52f-10314ca79c0a", - "metadata": { - "id": "fa5b2822-55cf-4983-a52f-10314ca79c0a" - }, + "metadata": {}, "outputs": [], "source": [ "await evaluation.evaluate(model)" @@ -462,9 +403,7 @@ "cell_type": "code", "execution_count": null, "id": "ba244582", - "metadata": { - "id": "ba244582" - }, + "metadata": {}, "outputs": [], "source": [] }, @@ -472,9 +411,7 @@ "cell_type": "code", "execution_count": null, "id": "c39dc979", - "metadata": { - "id": "c39dc979" - }, + "metadata": {}, "outputs": [], "source": [] }, @@ -482,9 +419,7 @@ "cell_type": "code", "execution_count": null, "id": "8d2f8124", - "metadata": { - "id": "8d2f8124" - }, + "metadata": {}, "outputs": [], "source": [] }, @@ -492,33 +427,21 @@ "cell_type": "code", "execution_count": null, "id": "f3012c72", - "metadata": { - "id": "f3012c72" - }, + "metadata": {}, "outputs": [], "source": [] } ], "metadata": { + "accelerator": "GPU", "colab": { - "provenance": [] + "include_colab_link": true, + "provenance": [], + "toc_visible": true }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", + "display_name": "Python 3", "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.10.12" } }, "nbformat": 4, diff --git a/colabs/gemini/google-demo-rag.ipynb b/colabs/gemini/google-demo-rag.ipynb index 13b20c49..bf28685e 100644 --- a/colabs/gemini/google-demo-rag.ipynb +++ b/colabs/gemini/google-demo-rag.ipynb @@ -2,7 +2,6 @@ "cells": [ { "cell_type": "markdown", - "id": "18e2cdd1-0663-45fd-b5cd-63eee509fd79", "metadata": {}, "source": [ "\"Open\n", @@ -332,22 +331,15 @@ } ], "metadata": { + "accelerator": "GPU", + "colab": { + "include_colab_link": true, + "provenance": [], + "toc_visible": true + }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", + "display_name": "Python 3", "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.10.12" } }, "nbformat": 4,