Gemini API#

In this notebook we use the model Gemini 1.5 Flash

def prompt_gemini(request, model="gemini-1.5-flash-001"):
    """Send a prompt to Google Gemini and return the response"""
    from google import generativeai as genai
    import os
    genai.configure(api_key=os.environ['GOOGLE_API_KEY'])
    
    client = genai.GenerativeModel(model)
    result = client.generate_content(request)
    return result.text
prompt_gemini("Hello, what is the capital of France?")
'The capital of France is **Paris**. \n'

Exercise#

List the models available by google and try them out!

from google.generativeai import list_models

[m.name for m in list_models()]
['models/chat-bison-001',
 'models/text-bison-001',
 'models/embedding-gecko-001',
 'models/gemini-1.0-pro',
 'models/gemini-1.0-pro-001',
 'models/gemini-1.0-pro-latest',
 'models/gemini-1.0-pro-vision-latest',
 'models/gemini-1.5-flash',
 'models/gemini-1.5-flash-001',
 'models/gemini-1.5-flash-latest',
 'models/gemini-1.5-pro',
 'models/gemini-1.5-pro-001',
 'models/gemini-1.5-pro-latest',
 'models/gemini-pro',
 'models/gemini-pro-vision',
 'models/embedding-001',
 'models/text-embedding-004',
 'models/aqa']