Skip to content

Commit

Permalink
Merge pull request #2 from rabea-al/main
Browse files Browse the repository at this point in the history
Update README
  • Loading branch information
mansouralawi authored Dec 18, 2024
2 parents d3fe565 + 528dcb2 commit f24ef69
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 112 deletions.
102 changes: 80 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,95 @@
# Google Generative AI Components for Xircuits
<p align="center">
<a href="https://github.com/XpressAI/xircuits/tree/master/xai_components#xircuits-component-library-list">Component Libraries</a> •
<a href="https://github.com/XpressAI/xircuits/tree/master/project-templates#xircuits-project-templates-list">Project Templates</a>
<br>
<a href="https://xircuits.io/">Docs</a> •
<a href="https://xircuits.io/docs/Installation">Install</a> •
<a href="https://xircuits.io/docs/category/tutorials">Tutorials</a> •
<a href="https://xircuits.io/docs/category/developer-guide">Developer Guides</a> •
<a href="https://github.com/XpressAI/xircuits/blob/master/CONTRIBUTING.md">Contribute</a> •
<a href="https://www.xpress.ai/blog/">Blog</a> •
<a href="https://discord.com/invite/vgEg2ZtxCw">Discord</a>
</p>

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.




<p align="center"><i>Xircuits Component Library for Gemini – Seamless Integration with Google Generative AI.</i></p>

---
### 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:

<img src="https://github.com/user-attachments/assets/3fb2ec14-ebeb-403e-83e8-f468655ded85" alt="gemini_example" />

### The Result:

<img src="https://github.com/user-attachments/assets/197b57ba-dbb6-4a9e-b160-bbad79d1bdf3" alt="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.
<img src="https://github.com/user-attachments/assets/1dd131c8-0122-4c51-aeda-2924c34d8ecd" alt="GeminiAuthorize" width="200" height="100" />

## 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:
<img src="https://github.com/user-attachments/assets/7d99754e-c2bc-4048-a442-06ad7097f1a4" alt="GeminiGenerateContent" width="200" height="100" />

```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'
```
Loading

0 comments on commit f24ef69

Please sign in to comment.