From 528dcb2168bd41c5f46c96ca93372095fa470f15 Mon Sep 17 00:00:00 2001 From: rabea-al Date: Thu, 12 Dec 2024 15:23:25 +0800 Subject: [PATCH] Update README --- README.md | 102 ++++++++++++++---- examples/gemini_example.xircuits | 180 +++++++++++++++---------------- 2 files changed, 170 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index f2d03ea..3cbb92c 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,95 @@ -# Google Generative AI Components for Xircuits +

+ Component Libraries • + Project Templates +
+ Docs • + Install • + Tutorials • + Developer Guides • + Contribute • + Blog • + Discord +

-This repository offers a suite of components designed to integrate the [Google Generative AI library](https://github.com/google/generative-ai-python) into the Xircuits framework. These components facilitate various operations, including content generation, chat sessions, and token counting, leveraging Google's advanced AI models. + + + + +

Xircuits Component Library for Gemini – Seamless Integration with Google Generative AI.

+ +--- +### Xircuits Component Library for Gemini +Seamlessly integrate Google Generative AI into Xircuits. This library enables efficient authorization, content generation, token management, and chat-based interactions with Gemini models. + +## Table of Contents + +- [Preview](#preview) +- [Prerequisites](#prerequisites) +- [Main Xircuits Components](#main-xircuits-components) +- [Try the Examples](#try-the-examples) +- [Installation](#installation) + +## Preview + +### The Example: + +gemini_example + +### The Result: + +gemini_example_result ## Prerequisites -- Python 3.8 or higher +Before you begin, you will need the following: -## Installation +1. Python3.9+. +2. Xircuits. -Once Xircuits is installed, simply run +## Main Xircuits Components -```bash -xircuits install google_gemini -``` +### GeminiAuthorize Component: +Configures API authorization for the Gemini library using an API key, either provided directly or from an environment variable. -You may also manually clone this repository to `xai_components` and install the requirements.txt. +GeminiAuthorize -## Usage +### GeminiGenerateContent Component: +Creates content using input data and a specified generative model. -It is recommended to store your Google API key in an environment variable for security and ease of use, or export it via: +GeminiGenerateContent -```bash -export GOOGLE_API_KEY='your_api_key_here' +### GeminiGenerateContentStream Component: +Generates content in real-time using a streaming approach, allowing dynamic responses. + +### GeminiStartChat Component: +Starts a conversational session with the Gemini model, enabling interactive AI chats. + +### GeminiChatSendMessage Component: +Sends a message in an ongoing chat and retrieves the AI's response. + +### GeminiChatSendMessageStream Component +Facilitates real-time chat interactions using streaming for continuous response delivery. + +### GeminiCountTokens Component: +Calculates token count for input text to optimize API usage and cost management. + +## Installation +To use this component library, ensure that you have an existing [Xircuits setup](https://xircuits.io/docs/main/Installation). You can then install the Gemini library using the [component library interface](https://xircuits.io/docs/component-library/installation#installation-using-the-xircuits-library-interface), or through the CLI using: + +``` +xircuits install gemini +``` +You can also do it manually by cloning and installing it: +``` +# base Xircuits directory +git clone https://github.com/XpressAI/xai-gemini xai_components/xai_gemini +pip install -r xai_components/xai_gemini/requirements.txt ``` -## Components Overview +## Usage -The library includes the following components for seamless integration with Google's Generative AI capabilities: +Store your Google API key in an environment variable for enhanced security and convenience. Example: - - **`GeminiAuthorize`**: Handles authorization with the Google Generative AI library using an API key, which can be provided directly or fetched from an environment variable named `GOOGLE_API_KEY`. - - **`GeminiGenerateContent`**: Generates content based on provided input data using a specified generative model. - - **`GeminiGenerateContentStream`**: Offers real-time content generation through streaming, similar to `GeminiGenerateContent`. - - **`GeminiStartChat`**: Initiates a chat session using a specified generative model. - - **`GeminiChatSendMessage`**: Sends a message and receives a response within an active chat session. - - **`GeminiChatSendMessageStream`**: Enables real-time chat interaction through streaming, similar to `GeminiChatSendMessage`. - - **`GeminiCountTokens`**: Counts the number of tokens in the provided input data using a specified generative model. +```bash +export GOOGLE_API_KEY='your_api_key_here' +``` \ No newline at end of file diff --git a/examples/gemini_example.xircuits b/examples/gemini_example.xircuits index 426db8c..5d802ba 100644 --- a/examples/gemini_example.xircuits +++ b/examples/gemini_example.xircuits @@ -1,12 +1,12 @@ { "id": "37d9543b-5e7c-4c1e-9955-20370bb059fa", - "offsetX": 191.9848008346557, - "offsetY": 15.10138671874995, - "zoom": 90.02282714843751, + "offsetX": 117.15205968053593, + "offsetY": 68.73236196181186, + "zoom": 88.0228271484375, "gridSize": 0, "layers": [ { - "id": "470a9ca2-78a4-4eb1-b419-d696dbcac239", + "id": "81548147-a9d2-462d-82a3-76150944cb9b", "type": "diagram-links", "isSvg": true, "transformed": true, @@ -23,14 +23,14 @@ { "id": "5ebf45df-cc78-4878-837d-92e033e87371", "type": "point", - "x": 167.75000978857366, - "y": 137.10000786475874 + "x": -25.54855328241692, + "y": 110.4375075228978 }, { "id": "d85f7a23-5f43-4b95-8ecc-b54c078a1e8e", "type": "point", - "x": 289.06248885543357, - "y": 178.10000875462907 + "x": 236.8500475894661, + "y": 109.22499107194834 } ], "labels": [], @@ -51,14 +51,14 @@ { "id": "890897ab-92d8-4ac2-9bb2-d77da5d307f5", "type": "point", - "x": 424.8000201619192, - "y": 178.10000875462907 + "x": 372.58754244096036, + "y": 109.22499107194834 }, { "id": "0deb9921-e6ee-42b6-b0ac-74243dd41be2", "type": "point", - "x": 499.06252953521994, - "y": 296.10000061867174 + "x": 621.975046852727, + "y": 108.36252425987539 } ], "labels": [], @@ -79,14 +79,14 @@ { "id": "d6152922-f0f1-4372-bae4-80e21d058f86", "type": "point", - "x": 334.74999716088996, - "y": 429.8000032543829 + "x": 576.3375409241446, + "y": 234.28750121294456 }, { "id": "52429212-d632-40b7-8797-b3874bb19680", "type": "point", - "x": 499.06252953521994, - "y": 339.30000143226744 + "x": 621.975046852727, + "y": 151.56250955976458 } ], "labels": [], @@ -107,14 +107,14 @@ { "id": "0e06d987-80d8-4189-8e2d-4b45211e8d88", "type": "point", - "x": 675.0999657866046, - "y": 296.10000061867174 + "x": 798.0125628616331, + "y": 108.36252425987539 }, { "id": "8845ea9f-9f2b-4c09-b69d-dd50f2f793fe", "type": "point", - "x": 758.0624576675972, - "y": 336.0999800669047 + "x": 870.5626021774956, + "y": 108.37501957074807 } ], "labels": [], @@ -135,14 +135,14 @@ { "id": "fb6d04de-cc62-4a38-99a1-92f1104492c5", "type": "point", - "x": 675.0999657866046, - "y": 317.70001797538055 + "x": 798.0125628616331, + "y": 129.9625342448563 }, { "id": "da36f93c-3733-4162-9c53-8c446ae82819", "type": "point", - "x": 758.0624576675972, - "y": 357.7000313234355 + "x": 870.5626021774956, + "y": 129.97502955572898 } ], "labels": [], @@ -163,14 +163,14 @@ { "id": "c9b0dbb9-ed5d-4460-a489-8af28d59cb26", "type": "point", - "x": 831.0999768464216, - "y": 336.0999800669047 + "x": 943.6001027148816, + "y": 108.37501957074807 }, { "id": "e951120d-5026-4c4d-ab7c-1e34f3c25bcc", "type": "point", - "x": 928.1000322302556, - "y": 223.1000223145578 + "x": 1022.312539424664, + "y": 107.51251808860246 } ], "labels": [], @@ -191,14 +191,14 @@ { "id": "7809ae74-07e9-46f3-845b-974e6f70f80a", "type": "point", - "x": 204.86251787368118, - "y": 285.0999829907644 + "x": 151.537538488572, + "y": 289.55000220104165 }, { "id": "c3d25d2b-ff26-443f-a10b-b2ba9a79200d", "type": "point", - "x": 289.06248885543357, - "y": 221.30000956822477 + "x": 236.8500475894661, + "y": 152.42499695719317 } ], "labels": [], @@ -219,14 +219,14 @@ { "id": "bb9948c1-65c7-4c97-bac8-734b4b9e8483", "type": "point", - "x": 61.49996741379621, - "y": 176.1625152803448 + "x": 152.5750057426884, + "y": 222.8250204721699 }, { "id": "4d4cde75-26c2-463e-b26b-2be49cdb689f", "type": "point", - "x": 289.06248885543357, - "y": 199.70001233953522 + "x": 236.8500475894661, + "y": 130.82500105692927 } ], "labels": [], @@ -238,7 +238,7 @@ } }, { - "id": "1f177233-6e6a-4944-beda-976a32d29788", + "id": "53524df0-93d6-480a-a442-21c158902a34", "type": "diagram-nodes", "isSvg": false, "transformed": true, @@ -246,20 +246,20 @@ "28ba4e10-3bdb-47a9-a606-92c2d33b2bb0": { "id": "28ba4e10-3bdb-47a9-a606-92c2d33b2bb0", "type": "custom-node", - "selected": false, + "selected": true, "extras": { "type": "Start", "borderColor": "rgb(0,192,255)" }, - "x": 100, - "y": 100, + "x": -93.3095492456275, + "y": 73.34009521781992, "ports": [ { "id": "d24c39ce-6454-4e23-967b-a876f6c234ba", "type": "default", "extras": {}, - "x": 157.4499959404964, - "y": 126.80002156028681, + "x": -35.84853240236566, + "y": 100.13750023351504, "name": "out-0", "alignment": "right", "parentNode": "28ba4e10-3bdb-47a9-a606-92c2d33b2bb0", @@ -287,15 +287,15 @@ "extras": { "type": "Finish" }, - "x": 917, - "y": 186, + "x": 1011.214474558941, + "y": 70.4220931720467, "ports": [ { "id": "ee601e91-b0f3-4461-9d1b-dd131be66b85", "type": "default", "extras": {}, - "x": 917.8000183821783, - "y": 212.80002223828322, + "x": 1012.0125321352813, + "y": 97.2125248839367, "name": "in-0", "alignment": "left", "parentNode": "e39f69ad-fb12-4f3e-be58-bb32c8180a53", @@ -312,8 +312,8 @@ "id": "203a4929-4878-42e1-999f-3eea4f9864c2", "type": "default", "extras": {}, - "x": 917.8000183821783, - "y": 234.4000056951701, + "x": 1012.0125321352813, + "y": 118.81250019884496, "name": "parameter-dynalist-outputs", "alignment": "left", "parentNode": "e39f69ad-fb12-4f3e-be58-bb32c8180a53", @@ -354,15 +354,15 @@ ], "borderColor": "rgb(0,192,255)" }, - "x": 277.969, - "y": 141, + "x": 225.76001980156397, + "y": 72.12857931270146, "ports": [ { "id": "900138f6-6de6-4e9d-8c91-36cfba91889e", "type": "default", "extras": {}, - "x": 278.76247500735633, - "y": 167.80000867835446, + "x": 226.5500403000833, + "y": 98.92498378256556, "name": "in-0", "alignment": "left", "parentNode": "40b5b183-ef7e-49a2-bdf6-4df5c95f99a9", @@ -379,8 +379,8 @@ "id": "da5acbce-4235-4608-9761-b87bb4c5f423", "type": "default", "extras": {}, - "x": 278.76247500735633, - "y": 189.4000260350633, + "x": 226.5500403000833, + "y": 120.52499376754649, "name": "parameter-secret-api_key", "alignment": "left", "parentNode": "40b5b183-ef7e-49a2-bdf6-4df5c95f99a9", @@ -397,8 +397,8 @@ "id": "1a159ae2-a326-4e00-87b7-37ebdc51cb46", "type": "default", "extras": {}, - "x": 278.76247500735633, - "y": 211.00000949195018, + "x": 226.5500403000833, + "y": 142.12500375252742, "name": "parameter-boolean-from_env", "alignment": "left", "parentNode": "40b5b183-ef7e-49a2-bdf6-4df5c95f99a9", @@ -415,8 +415,8 @@ "id": "5418be12-accd-4cfc-9254-8ce3df800481", "type": "default", "extras": {}, - "x": 414.5000063138419, - "y": 167.80000867835446, + "x": 362.2875351515776, + "y": 98.92498378256556, "name": "out-0", "alignment": "right", "parentNode": "40b5b183-ef7e-49a2-bdf6-4df5c95f99a9", @@ -449,15 +449,15 @@ "type": "string", "attached": false }, - "x": 159.969, - "y": 388, + "x": 401.5616212812333, + "y": 192.49403159734607, "ports": [ { "id": "e004fe3a-f19f-48de-9826-52629a997399", "type": "default", "extras": {}, - "x": 324.45001085641803, - "y": 419.50001694991096, + "x": 566.0375888901901, + "y": 223.9874939235618, "name": "out-0", "alignment": "right", "parentNode": "c839ab15-d2bd-4ffe-96f1-9b9d47bd3a6b", @@ -494,15 +494,15 @@ ], "nextNode": "None" }, - "x": 746.969, - "y": 299, + "x": 859.4732721321238, + "y": 71.27997998554514, "ports": [ { "id": "90442ac1-486a-4b52-a52e-2d0e72eaf7d7", "type": "default", "extras": {}, - "x": 747.76244381952, - "y": 325.7999937624328, + "x": 860.2625948881127, + "y": 98.07501228136529, "name": "in-0", "alignment": "left", "parentNode": "b48ca4af-306d-4198-bfae-a1898f3852ca", @@ -519,8 +519,8 @@ "id": "a71648c4-7339-4f95-9b37-ef5426ae1b54", "type": "default", "extras": {}, - "x": 747.76244381952, - "y": 347.40004501896357, + "x": 860.2625948881127, + "y": 119.6750222663462, "name": "parameter-any-msg", "alignment": "left", "parentNode": "b48ca4af-306d-4198-bfae-a1898f3852ca", @@ -537,8 +537,8 @@ "id": "44bc2595-f2cc-4d85-9cd6-23dd3772bf0c", "type": "default", "extras": {}, - "x": 820.8000170261855, - "y": 325.7999937624328, + "x": 933.3000954254989, + "y": 98.07501228136529, "name": "out-0", "alignment": "right", "parentNode": "b48ca4af-306d-4198-bfae-a1898f3852ca", @@ -577,15 +577,15 @@ } ] }, - "x": 487.969, - "y": 259, + "x": 610.8839586001583, + "y": 71.26983715881526, "ports": [ { "id": "1949c6c2-1e87-4773-ab46-94098dd2111d", "type": "default", "extras": {}, - "x": 488.76251568714264, - "y": 285.8000005423972, + "x": 611.674984307916, + "y": 98.06253105520963, "name": "in-0", "alignment": "left", "parentNode": "d5ed7ebf-d132-4759-871a-f034f50c6add", @@ -602,8 +602,8 @@ "id": "31814ac1-cb73-4643-9e7f-adb1382422c6", "type": "default", "extras": {}, - "x": 488.76251568714264, - "y": 307.400017899106, + "x": 611.674984307916, + "y": 119.66254104019055, "name": "parameter-string-model_name", "alignment": "left", "parentNode": "d5ed7ebf-d132-4759-871a-f034f50c6add", @@ -618,8 +618,8 @@ "id": "be2e08b2-7f6e-4877-8330-5ce95ae3d95e", "type": "default", "extras": {}, - "x": 488.76251568714264, - "y": 329.0000013559929, + "x": 611.674984307916, + "y": 141.26251635509882, "name": "parameter-string-input_data", "alignment": "left", "parentNode": "d5ed7ebf-d132-4759-871a-f034f50c6add", @@ -636,8 +636,8 @@ "id": "064cb37a-5c49-4e41-a7b0-23e35aee0860", "type": "default", "extras": {}, - "x": 664.7999519385273, - "y": 285.8000005423972, + "x": 787.7125555722504, + "y": 98.06253105520963, "name": "out-0", "alignment": "right", "parentNode": "d5ed7ebf-d132-4759-871a-f034f50c6add", @@ -654,8 +654,8 @@ "id": "486463aa-1078-4a73-8aa3-0e198c98c0fa", "type": "default", "extras": {}, - "x": 664.7999519385273, - "y": 307.400017899106, + "x": 787.7125555722504, + "y": 119.66254104019055, "name": "parameter-out-string-output", "alignment": "right", "parentNode": "d5ed7ebf-d132-4759-871a-f034f50c6add", @@ -689,15 +689,15 @@ "type": "boolean", "attached": false }, - "x": 124.966, - "y": 251.008, + "x": 71.64619043563985, + "y": 255.45131746369668, "ports": [ { "id": "a3731d61-2e07-45d5-922c-f368eb979454", "type": "default", "extras": {}, - "x": 194.56250402560391, - "y": 274.79998291448976, + "x": 141.23753119918922, + "y": 279.24999491165886, "name": "out-0", "alignment": "right", "parentNode": "a62d1199-a6d8-4978-9431-05685ab38f8d", @@ -726,15 +726,15 @@ "type": "string", "borderColor": "rgb(0,192,255)" }, - "x": -78.4076763350088, - "y": 142.0735354937916, + "x": 12.68033167077314, + "y": 188.72836886260677, "ports": [ { "id": "621b594d-7545-483a-85b3-199e556e5b8c", "type": "default", "extras": {}, - "x": 51.19995356571895, - "y": 165.86251520407018, + "x": 142.2749984533056, + "y": 212.52501318278715, "name": "parameter-out-0", "alignment": "right", "parentNode": "e2bb2c6f-4635-4425-a49e-9bec3f530134",