Gemini

Gemini

AgentOps 관찰을 통해 Google DeepMind의 Gemini를 살펴볼 수 있어요. Gemini(Google Generative AI)를 AgentOps와 함께 사용하는 방법을 알아볼게요.

출처: 문서

본문

Gemini (Google Generative AI)는 AI 도구와 서비스를 제공하는 선도 기업이에요. 더 많은 정보는 Gemini API를 살펴보세요.

참고: google-generativeai>=0.1.0이 현재 지원돼요.

단계 (Steps)

1. AgentOps SDK 설치하기 (Install the AgentOps SDK)

pip install agentops
poetry add agentops

2. Gemini SDK 설치하기 (Install the Gemini SDK)

참고: Gemini 통합에는 google-generativeai>=0.1.0이 필요해요.

pip install google-generativeai
poetry add google-generativeai

3. 코드 3줄 추가하기 (Add 3 lines of code)

참고: openai, cohere, crew 등 어떤 모델을 호출하기 전에 반드시 agentops.init을 먼저 호출해야 해요.

import google.generativeai as genai
import agentops

agentops.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

팁: API key를 .env 변수로 설정하면 쉽게 사용할 수 있어요.

AGENTOPS_API_KEY=<YOUR API KEY>
GEMINI_API_KEY=<YOUR GEMINI API KEY>

환경 변수에 대한 자세한 내용은 Advanced Configuration에서 확인할 수 있어요.

4. 에이전트 실행하기 (Run your Agent)

프로그램을 실행하고 app.agentops.ai/drilldown을 방문해서 여러분의 에이전트를 관찰해보세요! 🕵️

팁: 실행 후 AgentOps는 대시보드의 세션으로 바로 연결되는 클릭 가능한 URL을 콘솔에 출력해요.

전체 예제 (Full Examples)

import google.generativeai as genai
import agentops

agentops.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 genai
import agentops

agentops.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')

더 많은 예제는 Gemini Examples 섹션에서 찾을 수 있어요.

더 알아보기 (Learn more)