google-generativeai>=0.1.0 is currently supported.
1
Install the AgentOps SDK
pip install agentops
poetry add agentops
2
Install the Gemini SDK
google-generativeai>=0.1.0 is required for Gemini integration.
pip install google-generativeai
poetry add google-generativeai
3
Add 3 lines of code
Make sure to call agentops.init before calling any openai, cohere, crew, etc models.
import google.generativeai as genaiimport agentopsagentops.init(<INSERT YOUR API KEY HERE>)model = genai.GenerativeModel("gemini-1.5-flash")...# End of program (e.g. main.py)agentops.end_session("Success") # Success|Fail|Indeterminate
Set your API key as an .env variable for easy access.
AGENTOPS_API_KEY=<YOUR API KEY>GEMINI_API_KEY=<YOUR GEMINI API KEY>
import google.generativeai as genaiimport agentopsagentops.init(<INSERT YOUR API KEY HERE>)model = genai.GenerativeModel("gemini-1.5-flash")response = model.generate_content( "Write a haiku about AI and humans working together")print(response.text)agentops.end_session('Success')
import google.generativeai as genaiimport agentopsagentops.init(<INSERT YOUR API KEY HERE>)model = genai.GenerativeModel("gemini-1.5-flash")response = model.generate_content( "Write a haiku about AI and humans working together", stream=True)for chunk in response: print(chunk.text, end="")agentops.end_session('Success')