> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cohere

> Weave를 사용하여 Cohere Python 라이브러리를 통해 이루어진 LLM Call을 자동으로 추적하고 로깅하세요

<a target="_blank" href="https://colab.research.google.com/github/wandb/examples/blob/master/weave/docs/quickstart_cohere.ipynb" aria-label="Open in Google Colab">
  <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" />
</a>

`weave.init()`을 호출한 후 Weave는 [Cohere Python 라이브러리](https://github.com/cohere-ai/cohere-python)를 통해 이루어진 LLM Call을 자동으로 추적하고 로깅합니다.

<h2 id="traces">
  트레이스
</h2>

개발 단계와 프로덕션 단계 모두에서 LLM application의 트레이스를 중앙 데이터베이스에 저장하는 것이 중요합니다. 이러한 트레이스는 디버깅에 사용되며, 애플리케이션을 개선하는 데 도움이 되는 데이터셋으로 사용됩니다.

Weave는 `cohere-python`에 대한 트레이스를 자동으로 캡처합니다. 평소처럼 라이브러리를 사용하세요. `weave.init()`을 호출하는 것으로 시작합니다.

```python lines {8} theme={"system"}
import cohere
import os
import weave

# Cohere 라이브러리를 평소처럼 사용하세요
co = cohere.Client(api_key=os.environ["COHERE_API_KEY"])

weave.init("cohere_project")

response = co.chat(
    message="How is the weather in Boston?",
    # 질문에 답하기 전에 웹 검색을 수행합니다. 자신만의 맞춤형 connector를 사용할 수도 있습니다.
    connectors=[{"id": "web-search"}],
)
print(response.text)
```

CoreWeave Forge 팀을 지정하지 않으면 `weave.init()` 호출 시 Weave는 default entity를 사용합니다. default entity를 찾거나 업데이트하려면 Weights & Biases Models 문서의 [User Settings](/ko/products/wandb/platform/app/settings-page/user-settings#default-team)를 참고하세요.

Cohere 모델은 [connectors](https://docs.cohere.com/docs/overview-rag-connectors#using-connectors-to-create-grounded-generations)를 지원하므로 엔드포인트 측에서 다른 API에 요청할 수 있습니다. 그러면 응답에 connector에서 반환된 문서로 연결되는 인용 요소가 포함된 생성된 텍스트가 포함됩니다.

[<img src="https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/weave/_media/cohere_trace.png?fit=max&auto=format&n=3Dv_sw2eg8feUJlx&q=85&s=a1d4f7186c61a76c92e1ad2b4791f715" alt="cohere_trace.png" width="2156" height="1174" data-path="products/wandb/weave/_media/cohere_trace.png" />](https://forge.coreweave.com/wandb/capecape/cohere_dev/weave/calls)

<Note>
  Weave는 Cohere의 `Client.chat()`, `AsyncClient.chat()`, `Client.chat_stream()`, `AsyncClient.chat_stream()` 메서드를 패치하여 LLM Call을 추적합니다.
</Note>

<h2 id="wrap-with-your-own-ops">
  자신의 Weave Op으로 래핑하기
</h2>

Weave Op은 실험 시 코드를 자동으로 버전 관리하여 결과를 *재현 가능*하게 만들고, 입력과 출력을 캡처합니다. Cohere의 채팅 메서드를 호출하는 [`@weave.op()`](/ko/products/wandb/weave/guides/tracking/ops)으로 데코레이팅된 함수를 생성하면, Weave가 입력과 출력을 추적해 줍니다. 예시는 다음과 같습니다:

```python lines {9} theme={"system"}
import cohere
import os
import weave

co = cohere.Client(api_key=os.environ["COHERE_API_KEY"])

weave.init("cohere_project")

@weave.op()
def weather(location: str, model: str) -> str:
    response = co.chat(
        model=model,
        message=f"How is the weather in {location}?",
        # 질문에 답하기 전에 web search를 수행합니다. 자신만의 맞춤형 connector를 사용할 수도 있습니다.
        connectors=[{"id": "web-search"}],
    )
    return response.text

print(weather("Boston", "command"))
```

[<img src="https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/weave/_media/cohere_ops.png?fit=max&auto=format&n=3Dv_sw2eg8feUJlx&q=85&s=a05e51dc0c7958fa690e6f25ce4eb89d" alt="cohere_ops.png" width="2170" height="844" data-path="products/wandb/weave/_media/cohere_ops.png" />](https://forge.coreweave.com/wandb/capecape/cohere_dev/weave/calls)

<h2 id="create-a-model-for-easier-experimentation">
  Create a `Model` for easier experimentation
</h2>

변경되는 요소가 많으면 실험을 체계적으로 관리하기 어렵습니다. [`Model`](/ko/products/wandb/weave/guides/core-types/models) 클래스를 사용하면 system 프롬프트나 사용 중인 모델 등 앱의 실험 세부 정보를 캡처하고 정리할 수 있습니다. 이를 통해 앱의 여러 개선 버전을 정리하고 비교할 수 있습니다.

코드 버전 관리와 입력/출력 캡처뿐 아니라 [`Model`](/ko/products/wandb/weave/guides/core-types/models) 클래스는 애플리케이션의 동작을 제어하는 구조화된 매개변수도 캡처하여, 어떤 매개변수가 가장 효과적이었는지 파악하는 데 도움을 줍니다. Weave Model을 `serve` 및 [`Evaluation`](/ko/products/wandb/weave/guides/core-types/evaluations)와 함께 사용할 수도 있습니다.

다음 예시에서는 `model`과 `temperature`로 실험할 수 있습니다. 둘 중 하나를 변경할 때마다 `WeatherModel`의 새 *버전*이 생성됩니다.

```python lines theme={"system"}
import weave
import cohere
import os

weave.init('weather-cohere')

class WeatherModel(weave.Model):
    model: str
    temperature: float
  
    @weave.op()
    def predict(self, location: str) -> str:
        co = cohere.Client(api_key=os.environ["COHERE_API_KEY"])
        response = co.chat(
            message=f"How is the weather in {location}?",
            model=self.model,
            temperature=self.temperature,
            connectors=[{"id": "web-search"}]
        )
        return response.text

weather_model = WeatherModel(
    model="command",
    temperature=0.7
)
result = weather_model.predict("Boston")
print(result)
```

[<img src="https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/weave/_media/cohere_model.png?fit=max&auto=format&n=3Dv_sw2eg8feUJlx&q=85&s=c2d86a9270fc8909694c41838d726da0" alt="cohere_model.png" width="2906" height="994" data-path="products/wandb/weave/_media/cohere_model.png" />](https://forge.coreweave.com/wandb/capecape/cohere_dev/weave/models)


## Related topics

- [로컬 Scorer를 사용한 평가](/ko/products/wandb/weave/guides/evaluation/weave_local_scorers.md)
