diff --git a/.github/assets/logos/Google Gemini.png b/.github/assets/logos/Google Gemini.png new file mode 100644 index 0000000000..d2ff0f7261 Binary files /dev/null and b/.github/assets/logos/Google Gemini.png differ diff --git a/Google Gemini/Google_Gemini_Setup_connection.ipynb b/Google Gemini/Google_Gemini_Setup_connection.ipynb new file mode 100644 index 0000000000..e8e280a3c3 --- /dev/null +++ b/Google Gemini/Google_Gemini_Setup_connection.ipynb @@ -0,0 +1,279 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "be5dd6e3-f6cd-4c02-a6aa-722079e94fdd", + "metadata": { + "execution": { + "iopub.execute_input": "2021-02-23T14:22:16.610471Z", + "iopub.status.busy": "2021-02-23T14:22:16.610129Z", + "iopub.status.idle": "2021-02-23T14:22:16.627784Z", + "shell.execute_reply": "2021-02-23T14:22:16.626866Z", + "shell.execute_reply.started": "2021-02-23T14:22:16.610384Z" + }, + "papermill": {}, + "tags": [] + }, + "source": [ + "\"OpenAI.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "a5b2c509-2c29-49e8-af91-4f3f1e386da3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Google Gemini - Setup connection\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "d77fe283-4edd-42d3-a909-8e207d4b842f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #googlegemini #naas #secret #connection #setup" + ] + }, + { + "cell_type": "markdown", + "id": "b90f2d91-c886-4e36-8265-b09d06bb1c7f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" + ] + }, + { + "cell_type": "markdown", + "id": "6bbf7807-dda4-4b8a-b016-fe258a0fa33f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2024-02-01 (Created: 2024-02-01)" + ] + }, + { + "cell_type": "markdown", + "id": "214749fe-7f0b-4755-b7ea-1d200c234cc6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook help you setup your connection with Google Gemini and add required credentials to Naas secret. You will be able to establish a seamless connection to Google Gemini without the need to repeatedly redefine your credentials in variables by using `naas.secret.get()` in your notebook." + ] + }, + { + "cell_type": "markdown", + "id": "a1329bea-ad80-4981-874c-8776b11f89a8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Google AI Dev](https://ai.google.dev)\n", + "- [Gemini Python Docs](https://ai.google.dev/tutorials/python_quickstart)\n", + "- [Naas Secret Documentation](https://site.naas.ai/docs/developers/jobs/secret)" + ] + }, + { + "cell_type": "markdown", + "id": "cff349c8-2816-4ae4-9229-027c068eeb51", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "80266a9e-fe54-4f3e-aeb2-01483bbc53f9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc038b10-2679-42bc-909e-09a298339df4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import naas" + ] + }, + { + "cell_type": "markdown", + "id": "30127040-e487-4115-8317-5084823b3a6f", + "metadata": { + "papermill": {}, + "tags": [ + "variables" + ] + }, + "source": [ + "### Setup variables\n", + "**Mandatory**\n", + "- `api_key`: Google Gemini API Key. This value will be stored under the secret 'GOOGLE_GEMINI_API_KEY'.\n", + "\n", + "**Optional**\n", + "- `secrets`: Dict to add secrets to naas" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d86b8fb-2576-426d-a305-50043c24c23e", + "metadata": { + "papermill": {}, + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "# Mandatory\n", + "api_key = None\n", + "\n", + "# Optional\n", + "secrets = {\n", + " \"GOOGLE_GEMINI_API_KEY\": api_key,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "1b0ae044-cac2-479f-b1fc-a3318696adf5", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "3aadae7f-fbe5-4f97-a6a9-6efe9dd1a42f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Add secret" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e235794a-6907-4f0e-ab2b-5aa6668a8d3b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "for secret in secrets:\n", + " new_value = secrets.get(secret)\n", + " if new_value:\n", + " naas.secret.add(secret, secrets.get(secret))" + ] + }, + { + "cell_type": "markdown", + "id": "7c97931b-4ce8-46f9-a70c-45393c5669ee", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "760ec150-d79a-4208-adfe-d0336d443dc8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4005faa2-a781-4805-9c08-74951e900d12", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df = naas.secret.list()\n", + "df = df[df[\"name\"].isin(secrets.keys())]\n", + "df" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.9.6" + }, + "naas": { + "notebook_id": "3a9b0b5281032399d79196d4dc442bbaa86480c0f1a67a059f517daec95f977a", + "notebook_path": "OpenAI/OpenAI_Setup_connection.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.4.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Google Gemini/Google_Gemini_Write_a_social_media_post.ipynb b/Google Gemini/Google_Gemini_Write_a_social_media_post.ipynb new file mode 100644 index 0000000000..0a980ec91a --- /dev/null +++ b/Google Gemini/Google_Gemini_Write_a_social_media_post.ipynb @@ -0,0 +1,284 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "88c104cc-bf08-4242-821b-b3a40908152a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"OpenAI.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "compressed-wilson", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Google Gemini - Write a social media post" + ] + }, + { + "cell_type": "markdown", + "id": "religious-programmer", + "metadata": {}, + "source": [ + "**Tags:** #googlegemini #socialmedia #post #prompt #tone #platform" + ] + }, + { + "cell_type": "markdown", + "id": "1fe9f56e-561c-4f52-aef8-b861c9462107", + "metadata": {}, + "source": [ + "**Author:** [Sriniketh Jayasendil](https://www.linkedin.com/in/sriniketh-jayasendil)" + ] + }, + { + "cell_type": "markdown", + "id": "0de144be-594d-463e-9849-696fb2f6d1a8", + "metadata": {}, + "source": [ + "**Last update:** 2024-01-31 (Created: 2024-01-15)" + ] + }, + { + "cell_type": "markdown", + "id": "31ea7cdb-e10d-43fc-b026-f69249a59736", + "metadata": {}, + "source": [ + "**Description:** This notebook will help us write a social media post and configure based on the topic, the tone and the platform." + ] + }, + { + "cell_type": "markdown", + "id": "d4b89388-5cd5-409a-8169-c53cc8dfab96", + "metadata": {}, + "source": [ + "**References:**\n", + "- [Naas Documentation](https://site.naas.ai/)\n", + "- [Google AI Dev](https://ai.google.dev)\n", + "- [Gemini Python Docs](https://ai.google.dev/tutorials/python_quickstart)" + ] + }, + { + "cell_type": "markdown", + "id": "distinguished-truth", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "numeric-mediterranean", + "metadata": {}, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "potential-surfing", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import naas\n", + "try:\n", + " import google.generativeai as genai\n", + "except ModuleNotFoundError:\n", + " !pip install google-generativeai --user\n", + " import google.generativeai as genai" + ] + }, + { + "cell_type": "markdown", + "id": "aggressive-trustee", + "metadata": {}, + "source": [ + "### Setup variables\n", + "\n", + "- `api_key`: Google Gemini API. Get one from [here](https://makersuite.google.com/app/apikey)\n", + "- `topic`: the topic of the blog post\n", + "- `tone`: the tone of the blog post\n", + "- `platform`: social media platform to publish your post\n", + "\n", + "#### About \"tone\"\n", + "\n", + "Here are some different tones you can use for a blog post:\n", + "\n", + "- **Formal**: Use proper language, professional terms, and formal sentence structures. This tone is best used for academic or business-related blog posts.\n", + "- **Informative**: Stick to facts and provide helpful information. Avoid adding your opinion and present the content in a straightforward and objective manner.\n", + "- **Conversational**: Write as if you're talking to a friend. Use casual language, contractions, and personal anecdotes. This tone is best suited for lifestyle or personal blogs.\n", + "- **Inspirational**: Write in a way that motivates and encourages readers. Use positive language, inspiring stories, and uplifting messages.\n", + "- **Humorous**: Add some humor and make readers laugh. Use witty remarks, funny anecdotes, and sarcastic comments to engage readers.\n", + "- **Persuasive**: Try to persuade readers to take action or change their mind about a topic. Use strong arguments, statistics, and emotional appeals to convince readers.\n", + "- **Opinionated**: Share your personal opinion on a topic. Use strong language, personal experiences, and bold statements to express your views.\n", + "- **Educational**: Teach readers something new. Use step-by-step instructions, infographics, and helpful tips to educate readers on a topic.\n", + "- **Critical**: Analyze a topic critically and provide a detailed analysis. Use logic, reasoning, and evidence to support your arguments.\n", + "- **Empathetic**: Write in a way that connects with readers on an emotional level. Use empathy, compassion, and understanding to create a sense of community and support.\n", + "\n", + "#### About \"social media platforms\"\n", + "\n", + "Here's a list of social media platforms where you can write articles:\n", + "\n", + "- **LinkedIn**: LinkedIn is a professional social media platform where you can publish articles on industry-related topics. It's a great place to establish yourself as a thought leader and connect with other professionals in your field.\n", + "- **Facebook Notes**: Facebook Notes is a feature on Facebook that allows users to write long-form posts and publish them to their profile or page. It's a great way to share personal stories or thoughts with your friends and followers.\n", + "- **Twitter Threads**: Twitter Threads are a series of connected tweets that can be used to share longer thoughts or stories. It's a great way to break up longer articles into bite-sized pieces and share them with your Twitter followers.\n", + "- **Instagram Stories**: Instagram Stories are a feature on Instagram that allows users to share short videos or images that disappear after 24 hours. It can be a great way to share personal stories or behind-the-scenes glimpses into your life or business.\n", + "- **Reddit**: Reddit is a social news aggregation and discussion platform where users can post articles, stories, and links to other websites. It's a great platform for niche communities and can be a good place to share your writing with like-minded individuals." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "continuous-melbourne", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "google_api_key = naas.secret.get(\"GOOGLE_GEMINI_API_KEY\") or \"Enter your API key\"\n", + "topic = \"What are the benefits of being consistent?\"\n", + "tone = \"Inspirational\"\n", + "platform = \"Twitter\"\n", + "prompt = f\"Write a {tone.lower()} social media post about '{topic}' for {platform}.\"\n", + "\n", + "# Outputs\n", + "file_path = f\"Social_Media_Post_{topic.replace(' ', '_')}_{tone}_on_{platform}_characters.md\"" + ] + }, + { + "cell_type": "markdown", + "id": "registered-showcase", + "metadata": {}, + "source": [ + "## Model\n", + "### Send requests to OpenAI API" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "crude-louisville", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "try:\n", + " genai.configure(api_key=google_api_key)\n", + " model = genai.GenerativeModel('gemini-pro')\n", + " response = model.generate_content(prompt)\n", + "except:\n", + " print(\"Cannot run code in your region. Check here for valid regions: https://ai.google.dev/available_regions#available_regions\")" + ] + }, + { + "cell_type": "markdown", + "id": "472ed28e-e11f-4820-8aee-73006c25c28c", + "metadata": {}, + "source": [ + "### Get text" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3f14b302-c1b6-4f30-8097-2b2baef8e089", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "text = response.text\n", + "print(text)" + ] + }, + { + "cell_type": "markdown", + "id": "lonely-pacific", + "metadata": { + "execution": { + "iopub.execute_input": "2021-07-02T23:32:10.789097Z", + "iopub.status.busy": "2021-07-02T23:32:10.788829Z", + "iopub.status.idle": "2021-07-02T23:32:10.796900Z", + "shell.execute_reply": "2021-07-02T23:32:10.796358Z", + "shell.execute_reply.started": "2021-07-02T23:32:10.789033Z" + } + }, + "source": [ + "## Output\n", + "### Save text to txt file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c4e3b7b-6440-4844-8054-265f1aec65eb", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "text_file = open(file_path, \"w\")\n", + "text_file.write(text)\n", + "text_file.close()\n", + "print('Done...')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5d441ee-af04-4438-9d6f-316e998ad62a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.9.6" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.3" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/template.ipynb b/template.ipynb index 63580c3239..a02710101a 100644 --- a/template.ipynb +++ b/template.ipynb @@ -27,7 +27,7 @@ "id": "religious-programmer", "metadata": {}, "source": [ - "**Tags**: #tool -> hastags of the topics the notebook is about, as text starting with the name of the tool" + "**Tags:** #tool" ] }, { @@ -35,7 +35,7 @@ "id": "1fe9f56e-561c-4f52-aef8-b861c9462107", "metadata": {}, "source": [ - "**Author:** [Firstname Lastname](https://www.linkedin.com/) -> name and social profile link of the author(s)" + "**Author:** [Firstname Lastname](https://www.linkedin.com/)" ] }, { @@ -43,7 +43,7 @@ "id": "0de144be-594d-463e-9849-696fb2f6d1a8", "metadata": {}, "source": [ - "**Last update:** YYYY-MM-DD (Created: YYYY-MM-DD) -> The last update date refers to when the notebook was last edited, while the created date corresponds to when the notebook was initially merged." + "**Last update:** YYYY-MM-DD (Created: YYYY-MM-DD)" ] }, { @@ -59,7 +59,7 @@ "id": "d4b89388-5cd5-409a-8169-c53cc8dfab96", "metadata": {}, "source": [ - "**References:** list of references and websites utilized in the creation of this notebook\n", + "**References:**\n", "- [Naas Documentation](https://site.naas.ai/)" ] },