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

# Google

<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="Open In Colab" />
</a>

<Tip>
  최신 튜토리얼은 [Google Cloud의 Weights & Biases](https://wandb.ai/site/partners/googlecloud/)를 방문하세요.
</Tip>

<Note>
  설정 없이 Weave에서 Google AI 모델을 실험해 보고 싶으신가요? [LLM Playground](../tools/playground.mdx)를 시도해 보세요.
</Note>

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

Weave를 사용하여 Google GenAI 애플리케이션을 평가, 모니터링 및 반복할 수 있습니다. Weave는 다음에 대한 추적을 자동으로 캡처합니다:

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

<Note>
  또한 더 이상 사용되지 않는 [Google AI Python SDK for the Gemini API](https://github.com/google-gemini/deprecated-generative-ai-python)에 대한 지원도 있습니다. 이 지원도 더 이상 사용되지 않으며 향후 버전에서 제거될 예정입니다.
</Note>

## 시작하기

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

```python
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?",
)
```

[![dspy\_trace.png](https://mintlify.s3.us-west-1.amazonaws.com/wb-21fd5541-feature-automate-reference-docs-generation/ko/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
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?"
)
```

## 자체 작업 추적하기

함수를 wrapping하는 `@weave.op` 입력, 출력 및 앱 로직을 캡처하여 데이터가 앱을 통해 어떻게 흐르는지 디버깅할 수 있게 합니다. 추적하고자 하는 함수들을 깊게 중첩하여 트리를 구축할 수 있습니다. 또한 실험할 때 코드를 자동으로 버전 관리하여 git에 커밋되지 않은 임시 세부 정보를 캡처합니다.

간단히 [`@weave.op`](/ko/guides/tracking/ops)로 장식된 함수를 만들면 됩니다.

아래 예시에서는 `recommend_places_to_visit` 함수가 `@weave.op`로 래핑된 함수로, 도시에서 방문할 장소를 추천합니다.

```python
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")
```

[![dspy\_trace.png](https://mintlify.s3.us-west-1.amazonaws.com/wb-21fd5541-feature-automate-reference-docs-generation/ko/guides/integrations/imgs/google-genai-ops.png)](https://wandb.ai/geekyrakshit/google-genai/weave/traces)

## 더 쉬운 실험을 위해 `Model` 생성하기

많은 요소가 있을 때 실험을 체계화하기는 어렵습니다. [`Model`](../core-types/models) 클래스를 사용하면 시스템 프롬프트나 사용 중인 모델과 같은 앱의 실험 세부 정보를 캡처하고 구성할 수 있습니다. 이를 통해 앱의 다양한 반복을 구성하고 비교할 수 있습니다.

코드 버전 관리 및 입력/출력 캡처 외에도 [`Model`](../core-types/models)는 애플리케이션의 동작을 제어하는 구조화된 매개변수를 캡처하여 어떤 매개변수가 가장 잘 작동했는지 쉽게 찾을 수 있게 합니다. Weave Models를 `serve`, 그리고 [`Evaluation`](../core-types/evaluations.mdx)와 함께 사용할 수도 있습니다.

아래 예시에서는 `CityVisitRecommender`로 실험할 수 있습니다. 이 중 하나를 변경할 때마다 새로운 *version*의 `CityVisitRecommender`를 얻게 됩니다.

```python
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"))
```
