Gemini is Google’s language model, usable through a chat interface or a Python library. Try it as an alternative when choosing a model for a task. section 8.0 section 8.3
You can use Gemini to:
- Ask questions in the web interface, including questions about uploaded pictures. section 8.3.1
- Enable Google tool integrations, such as access to email, to help find information in your inbox. section 8.3.1
- Send a question from Python using an API key and the generate_content method. section 8.3.2
Ask Gemini a question from Python
Provide an API key and a question, configure the library with the key, generate a Gemini model, and print its reply. The example uses the question “What is the meaning of life?” section 8.3.2
Listing 8.3 Answering questions using Google’s Gemini model
import argparse
import google.generativeai as genai
if __name__ == '__main__':
#1
parser = argparse.ArgumentParser()
parser.add_argument('api_key', type=str, help='Google API key')
parser.add_argument('question', type=str, help='Question to answer')
args = parser.parse_args()
#2
genai.configure(api_key=args.api_key)
#3
model = genai.GenerativeModel('gemini-1.5-flash')
reply = model.generate_content(args.question)
#4
print(reply.text)
See the complete Python example for configuring the API key and generating a reply. section 8.3.2






