Pastebin

Paste #28298: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

import google.generativeai as genai

# Configure Gemini API with your API key directly
# Replace "YOUR_API_KEY_HERE" with your actual API key
API_KEY = "AIzaSyCQf_SF4Sbwd-m-D2IYx8XTw21B18gBnIU"
genai.configure(api_key=API_KEY)

def query_gemini(current_sentence, prefix_string):
    """
    Takes a sentence, prefixes it with a string, sends to the fastest Gemini model,
    and stores the response in a variable.
    
    Args:
        current_sentence (str): The current sentence to process
        prefix_string (str): The prefix to add before the sentence
        
    Returns:
        str: The response from the Gemini model
    """
    # Combine the prefix and the current sentence
    prompt = f"{prefix_string} {current_sentence}"
    
    # Use Gemini-1.5-flash as it's the fastest model in the current Gemini lineup
    model = genai.GenerativeModel('gemini-1.5-flash')
    
    # Send the request to the Gemini API
    response = model.generate_content(prompt)
    
    # Store the response in a variable
    gemini_response = response.text
    
    return gemini_response

# Example usage
if __name__ == "__main__":
    # Example sentence and prefix
    current_sentence = "What are the key features of Python?"
    prefix_string = "Explain briefly:"
    
    # Call the function and store the response
    result = query_gemini(current_sentence, prefix_string)
    
    # Print the result
    print(f"Prompt: {prefix_string} {current_sentence}")
    print(f"Response from Gemini: {result}")

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.