> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-update-reference-docs-40.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google

> Weave를 사용해 Google GenAI 모델 호출을 트레이스하고 로그합니다

<a target="_blank" href="https://github.com/wandb/examples/blob/master/weave/docs/quickstart_google.ipynb">
  <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Colab에서 열기" />
</a>

<Note>
  [LLM 플레이그라운드](../tools/playground)를 사용하면 별도 설정 없이 Weave에서 Google AI 모델을 실험해 볼 수 있습니다.
</Note>

이 페이지에서는 W\&B Weave를 Google Vertex AI API 및 Google Gemini API와 함께 사용하는 방법을 설명합니다.

Weave를 사용하면 Google GenAI 애플리케이션을 평가하고, 모니터링하고, 반복적으로 개선할 수 있습니다. Weave는 다음의 트레이스를 자동으로 캡처합니다:

1. Python SDK, Node.js SDK, Go SDK 및 REST를 통해 액세스할 수 있는 [Google GenAI SDK](https://github.com/googleapis/python-genai).
2. Google의 Gemini 모델과 [다양한 파트너 모델](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-partner-models)에 대한 액세스를 제공하는 [Google Vertex AI API](https://cloud.google.com/vertex-ai/docs).

<Note>
  사용 중단된 [Google AI Python SDK for the Gemini API](https://github.com/google-gemini/deprecated-generative-ai-python)도 지원합니다. 이 지원 역시 사용 중단되었으며 향후 버전에서 제거될 예정입니다.
</Note>

<div id="get-started">
  ## 시작하기
</div>

Weave는 [Google GenAI SDK](https://github.com/googleapis/python-genai)의 트레이스를 자동으로 캡처합니다. 추적을 시작하려면 `weave.init(project_name="<YOUR-WANDB-PROJECT-NAME>")`를 호출한 다음, 평소처럼 라이브러리를 사용하세요.

```python lines theme={null}
import os
from google import genai
import weave

weave.init(project_name="google-genai")

google_client = genai.Client(api_key=os.getenv("GOOGLE_GENAI_KEY"))
response = google_client.models.generate_content(
    model="gemini-2.0-flash",
    contents="What's the capital of France?",
)
```

[<img src="https://mintcdn.com/wb-21fd5541-update-reference-docs-40/6Tgk4MMVj_q4f1o8/weave/guides/integrations/imgs/google-genai-trace.png?fit=max&auto=format&n=6Tgk4MMVj_q4f1o8&q=85&s=96ddc025c864afba29372417b720f3c1" alt="dspy_trace.png" width="3452" height="1866" data-path="weave/guides/integrations/imgs/google-genai-trace.png" />](https://wandb.ai/geekyrakshit/google-genai/weave/traces)

Weave는 [Vertex APIs](https://github.com/googleapis/python-aiplatform/tree/main/vertexai/generative_models)의 트레이스도 자동으로 캡처합니다. 추적을 시작하려면 `weave.init(project_name="<YOUR-WANDB-PROJECT-NAME>")`를 호출한 다음, 평소처럼 라이브러리를 사용하세요.

```python lines theme={null}
import vertexai
import weave
from vertexai.generative_models import GenerativeModel

weave.init(project_name="vertex-ai-test")
vertexai.init(project="<YOUR-VERTEXAIPROJECT-NAME>", location="<YOUR-VERTEXAI-PROJECT-LOCATION>")
model = GenerativeModel("gemini-1.5-flash-002")
response = model.generate_content(
    "What's a good name for a flower shop specialising in selling dried flower bouquets?"
)
```

<div id="track-your-own-ops">
  ## 직접 ops 추적하기
</div>

함수를 `@weave.op`으로 감싸면 입력, 출력, 앱 로직 캡처가 시작되어 데이터가 앱 전체에서 어떻게 흐르는지 디버깅할 수 있습니다. ops를 깊게 중첩하고, 추적하려는 함수들을 트리 형태로 구성할 수 있습니다. 또한 실험하는 동안 코드 버전 관리도 자동으로 시작되어 아직 git에 커밋되지 않은 임시 세부 사항까지 캡처합니다.

[`@weave.op`](/ko/weave/guides/tracking/ops)으로 데코레이팅된 함수를 만들기만 하면 됩니다.

아래 예제에는 도시에서 방문할 장소를 추천하는, `@weave.op`으로 감싼 함수 `recommend_places_to_visit`가 있습니다.

```python lines theme={null}
import os
from google import genai
import weave

weave.init(project_name="google-genai")
google_client = genai.Client(api_key=os.getenv("GOOGLE_GENAI_KEY"))


@weave.op()
def recommend_places_to_visit(city: str, model: str = "gemini-1.5-flash"):
    response = google_client.models.generate_content(
        model=model,
        contents="You are a helpful assistant meant to suggest all budget-friendly places to visit in a city",
    )
    return response.text


recommend_places_to_visit("New York")
recommend_places_to_visit("Paris")
recommend_places_to_visit("Kolkata")
```

[<img src="https://mintcdn.com/wb-21fd5541-update-reference-docs-40/6Tgk4MMVj_q4f1o8/weave/guides/integrations/imgs/google-genai-ops.png?fit=max&auto=format&n=6Tgk4MMVj_q4f1o8&q=85&s=f7934d1b347c52679d46b7fe6aec3319" alt="dspy_trace.png" width="3452" height="1866" data-path="weave/guides/integrations/imgs/google-genai-ops.png" />](https://wandb.ai/geekyrakshit/google-genai/weave/traces)

<div id="create-a-model-for-easier-experimentation">
  ## 더 쉽게 실험할 수 있도록 `Model` 만들기
</div>

구성 요소가 많아지면 실험을 체계적으로 정리하기가 어려워집니다. [`Model`](../core-types/models) 클래스를 사용하면 system prompt나 사용 중인 모델처럼 앱의 실험 세부 정보를 캡처하고 정리할 수 있습니다. 이렇게 하면 앱의 여러 반복 버전을 정리하고 비교하는 데 도움이 됩니다.

코드를 버전 관리하고 입력/출력을 캡처하는 것에 더해, [`Model`](../core-types/models)은 애플리케이션의 동작을 제어하는 구조화된 매개변수도 캡처하므로 어떤 매개변수가 가장 효과적이었는지 쉽게 찾을 수 있습니다. 또한 Weave Models를 `serve` 및 [`Evaluation`](../core-types/evaluations)과 함께 사용할 수도 있습니다.

아래 예시에서는 `CityVisitRecommender`를 실험해 볼 수 있습니다. 이 중 하나를 변경할 때마다 `CityVisitRecommender`의 새 *버전*이 생성됩니다.

```python lines theme={null}
import os
from google import genai
import weave

weave.init(project_name="google-genai")
google_client = genai.Client(api_key=os.getenv("GOOGLE_GENAI_KEY"))


class CityVisitRecommender(weave.Model):
    model: str

    @weave.op()
    def predict(self, city: str) -> str:
        response = google_client.models.generate_content(
            model=self.model,
            contents="You are a helpful assistant meant to suggest all budget-friendly places to visit in a city",
        )
        return response.text


city_recommender = CityVisitRecommender(model="gemini-1.5-flash")
print(city_recommender.predict("New York"))
print(city_recommender.predict("San Francisco"))
print(city_recommender.predict("Los Angeles"))
```
