새로운 W&B Inference 서비스를 무료로 사용해 보세요. API와 Weave Playground를 통해 AI 모델에 액세스할 수 있습니다.
첫 번째 호출을 추적하려면 다음 단계를 따르세요. 또한 Open In Colab

1. Weave 설치 및 API 키 받기

weave 설치 먼저, weave 라이브러리를 설치하세요:
pip install weave
API 키 받기 W&B 계정을 https://wandb.ai에서 만드세요. 그런 다음 https://wandb.ai/authorize에서 API 키를 복사하세요.

2. 새 프로젝트에 추적 기록하기

첫 번째 프로젝트를 추적하려면 다음 단계를 따르세요:
  • 라이브러리 weave 가져오기
  • 추적을 시작하려면 weave.init('project-name') 호출하기
    • 아직 로그인하지 않은 경우 시스템이 API 키를 요청합니다
    • 팀에 로깅하려면 team-name/project-name
    • 로그인 프롬프트를 건너뛰려면 WANDB_API_KEY 환경 변수를 설정하세요
  • 추적하려는 함수에 @weave.op()를 추가하세요
이 예제는 OpenAI를 사용합니다. OpenAI API key가 필요합니다.
import weave
from openai import OpenAI

client = OpenAI()

# Weave tracks the inputs, outputs and code of this function
@weave.op()
def extract_dinos(sentence):
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {
                "role": "system",
                "content": """Extract dinosaurs from the text. Return JSON with:
- dinosaurs: list of dinosaurs
- name: scientific name  
- common_name: nickname
- diet: herbivore or carnivore."""
            },
            {
                "role": "user",
                "content": sentence
            }
        ],
        response_format={ "type": "json_object" }
    )
    return response.choices[0].message.content


# Start the weave project
weave.init('jurassic-park')

sentence = """I saw a T. rex chase a Triceratops. 
The T. rex eats meat. The Triceratops eats plants.
A Brachiosaurus ate leaves from tall trees nearby."""

result = extract_dinos(sentence)
print(result)
호출하면 extract_dinos, Weave는 추적을 볼 수 있는 링크를 보여줍니다.

3. 자동 AI 라이브러리 로깅

Weave는 많은 AI 서비스에 대한 호출을 추적합니다: Weave 로깅:
  • AI 모델 정보
  • 토큰 사용량
  • 비용
다른 AI 도구를 추적하려면 @weave.op()로 래핑하세요.

4. 프로젝트에서 추적 보기

잘 하셨습니다. 이제 Weave는 함수를 호출할 때마다 데이터를 캡처합니다. 또한 코드 변경 사항도 추적합니다. Weave Trace Outputs 1

다음 단계

  • 앱에서 track data flow하는 방법 배우기
  • Weave 작동 방식을 알아보려면 Tracing에 대해 읽어보세요
  • 모든 AI 제공업체에 대한 Integrations를 확인하세요
  • 다양한 모델을 테스트하려면 Playground를 사용해 보세요