Giter Club home page Giter Club logo

gemini-pro-bot's Introduction

GEMINI-PRO-BOT

A Python Telegram bot powered by Google's gemini-pro LLM API

This is a Python Telegram bot that uses Google's gemini-pro LLM API to generate creative text formats based on user input. It is designed to be a fun and interactive way to explore the possibilities of large language models.

Screencast.from.20-12-23.01.07.12.PM.+0530.webm

Features

  • Generate creative text formats like poems, code, scripts, musical pieces, etc.
  • Stream the generation process, so you can see the text unfold in real-time.
  • Reply to your messages with Bard's creative output.
  • Easy to use with simple commands:
    • /start: Greet the bot and get started.
    • /help: Get information about the bot's capabilities.
  • Send any text message to trigger the generation process.
  • Send any image with captions to generate responses based on the image. (Multi-modal support)
  • User authentication to prevent unauthorized access by setting AUTHORIZED_USERS in the .env file (optional).

Requirements

  • Python 3.10+
  • Telegram Bot API token
  • Google gemini-pro API key
  • dotenv (for environment variables)

Docker

GitHub Container Registry

Simply run the following command to run the pre-built image from GitHub Container Registry:

docker run --env-file .env ghcr.io/rabilrbl/gemini-pro-bot:latest

Update the image with:

docker pull ghcr.io/rabilrbl/gemini-pro-bot:latest

Build

Build the image with:

docker build -t gemini-pro-bot .

Once the image is built, you can run it with:

docker run --env-file .env gemini-pro-bot

Installation

  1. Clone this repository.
  2. Install the required dependencies:
    • pipenv install (if using pipenv)
    • pip install -r requirements.txt (if not using pipenv)
  3. Create a .env file and add the following environment variables:
    • BOT_TOKEN: Your Telegram Bot API token. You can get one by talking to @BotFather.
    • GOOGLE_API_KEY: Your Google Bard API key. You can get one from Google AI Studio.
    • AUTHORIZED_USERS: A comma-separated list of Telegram usernames or user IDs that are authorized to access the bot. (optional) Example value: shonan23,1234567890
  4. Run the bot:
    • python main.py (if not using pipenv)
    • pipenv run python main.py (if using pipenv)

Usage

  1. Start the bot by running the script.
    python main.py
  2. Open the bot in your Telegram chat.
  3. Send any text message to the bot.
  4. The bot will generate creative text formats based on your input and stream the results back to you.
  5. If you want to restrict public access to the bot, you can set AUTHORIZED_USERS in the .env file to a comma-separated list of Telegram user IDs. Only these users will be able to access the bot. Example:
    AUTHORIZED_USERS=shonan23,1234567890

Bot Commands

Command Description
/start Greet the bot and get started.
/help Get information about the bot's capabilities.
/new Start a new chat session.

Star History

Star History Chart

Contributing

We welcome contributions to this project. Please feel free to fork the repository and submit pull requests.

Disclaimer

This bot is still under development and may sometimes provide nonsensical or inappropriate responses. Use it responsibly and have fun!

License

This is a free and open-source project released under the GNU Affero General Public License v3.0 license. See the LICENSE file for details.

gemini-pro-bot's People

Contributors

dependabot[bot] avatar rabilrbl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gemini-pro-bot's Issues

Bug: Await expression

in send_message_async
    response = await self.model.generate_content(
TypeError: object GenerateContentResponse can't be used in 'await' expression

Voice message options

Can you please add the following feature to the bot: the ability to receive and send voice messages? "google cli" 😃

Gemini Telegram Bot API Access Issue - Location Restriction Error

Hello Dear,

I am writing to report an issue with accessing the Google AI API from my server located in Frankfurt, Germany. My Telegram bot, which utilizes the API for research and study purposes, has suddenly stopped functioning since April 29, 2024. Upon investigation, I encountered the following error message: "400 User location is not supported for the API use."

I have confirmed that my API key is valid and functioning correctly, as demonstrated by a successful connection test using a provided script. Therefore, I suspect the issue is related to a location restriction on the Google AI API.

The Telegram bot is crucial for my ongoing research and work activities. Its unavailability is causing significant disruption and hindering my progress.

I kindly request your assistance in resolving this issue as soon as possible. Please advise if there are any restrictions on accessing the API from Frankfurt or if alternative solutions are available. I would greatly appreciate any guidance on how to restore functionality to my Telegram bot.

Thank you for your time and attention to this matter.

Sincerely,
Robert

Google Speech Synthesis

To investigate the Python code of the source code of the GitHub repository "https://github.com/rabilrbl/gemini-pro-bot" and integrate Google Cli Speech Synthesis, so that this bot turns on and off the output of the text via voice message when interacting with the command "/voice on" or "/voice off", you can follow these steps:

  1. Clone the GitHub repository:

git clone https://github.com/rabilrbl/gemini-pro-bot

  1. Install the required Python modules:

pip install -r requirements.txt

  1. Create a Google Cloud Platform (GCP) project and enable the Text-to-Speech API:
  1. Create a service account key:
  • Go to the Service Accounts page and click "Create Service Account".
  • Enter a name for the service account and select the role "Text-to-Speech API User".
  • Click "Create Key" and select "JSON" as the key type.
  • Save the downloaded JSON key in a safe place.
  1. Add the Google Cloud Platform credentials to the Python code:
  • Create a new file named credentials.json in the source code directory.
  • Copy the contents of the JSON key that you downloaded earlier into this file.
  1. Import the required Python modules:
  • Add the following lines at the beginning of the gemini_pro_bot.py file:

import google.cloud.texttospeech as tts

Load the Google Cloud Platform credentials

with open('credentials.json', 'r') as f:
credentials = google.auth.load_credentials_from_file(f)

  1. Instantiate the Text-to-Speech client:
  • Add the following line at the end of the gemini_pro_bot.py file:

client = tts.TextToSpeechClient(credentials=credentials)

  1. Add the "/voice on" and "/voice off" commands:
  • Add the following lines to the handle_message() function in the gemini_pro_bot.py file:

if message.text == '/voice on':
global voice_on
voice_on = True
bot.send_message(message.chat.id, 'Voice output turned on.')
elif message.text == '/voice off':
global voice_on
voice_on = False
bot.send_message(message.chat.id, 'Voice output turned off.')

  1. Add the function to generate speech messages:
  • Add the following function to the gemini_pro_bot.py file:

def generate_speech(text):
synthesis_input = tts.SynthesisInput(text=text)
voice = tts.VoiceSelectionParams(
language_code='en-US',
ssml_gender=tts.SsmlVoiceGender.NEUTRAL
)
audio_config = tts.AudioConfig(
audio_encoding=tts.AudioEncoding.MP3
)
response = client.synthesize_speech(
input=synthesis_input,
voice=voice,
audio_config=audio_config
)
return response.audio_content

  1. Send speech messages when the "voice output" option is enabled:
  • Add the following line to the handle_message() function in the gemini_pro_bot.py file:

if voice_on and message.text != '/voice on' and message.text != '/voice off':
audio_content = generate_speech(message.text)
bot.send_audio(message.chat.id, audio_content)

  1. Start the bot:
  • Run the following command to start the bot:

python gemini_pro_bot.py

After following these steps, the bot should turn on and off the output of the text via voice message when interacting with the "/voice on" or "/voice off" command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.