Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-john-wbdocs-2044-rename-serverless-products.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
코드에 트레이싱을 추가해 Weave로 LLM call을 추적하는 방법을 알아보세요. 이 퀵스타트에서는 OpenAI로 보내는 요청을 트레이스하고 Weave UI에서 결과를 확인하는 방법을 안내합니다.
이 가이드에서는 다음 방법을 설명합니다:
- 코드에 Weave를 임포트하고 설정하기
weave.op 데코레이터를 사용해 코드를 추적하기
- Weave UI에서 트레이스 보기
- W&B 계정
- Python 3.8+ 또는 Node.js 18+
- 필수 패키지가 설치되어 있어야 합니다:
- Python:
pip install weave openai
- TypeScript:
npm install weave openai
- OpenAI API 키를 환경 변수로 설정해야 합니다
코드 추적을 시작하고 Weave에 트레이스를 기록하려면 다음 단계를 따르세요.
- 코드에
weave 라이브러리를 임포트합니다.
- 코드에서
weave.init('your_wb_team/project_name')를 호출하여 추적 정보를 W&B 팀과 프로젝트로 보냅니다. 팀을 설정하지 않으면 트레이스는 기본 팀으로 전송됩니다. 지정한 프로젝트가 팀에 없으면 Weave가 자동으로 생성합니다.
- 추적하려는 특정 함수에
@weave.op() 데코레이터를 추가합니다. Weave는 지원되는 LLM에 대한 call을 자동으로 추적하지만, Weave 데코레이터를 추가하면 특정 함수의 입력, 출력, 코드도 추적할 수 있습니다. TypeScript에서 데코레이터는 다음 구문을 사용합니다: weave.op(your_function)
다음 예제 코드는 OpenAI에 요청을 보내고(OpenAI API 키 필요), Weave는 해당 요청의 트레이싱 정보를 기록합니다. 이 요청은 OpenAI 모델에 입력에서 공룡 이름을 추출하고 각 공룡의 식성(초식 또는 육식)을 식별하도록 합니다.
다음 예제 코드를 실행해 Weave로 첫 번째 프로젝트를 추적하세요:
# Weave 라이브러리를 임포트합니다
import weave
from openai import OpenAI
client = OpenAI()
# Weave는 이 함수의 입력, 출력, 코드를 자동으로 추적합니다
@weave.op()
def extract_dinos(sentence: str) -> dict:
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": """In JSON format extract a list of `dinosaurs`, with their `name`,
their `common_name`, and whether its `diet` is a herbivore or carnivore"""
},
{
"role": "user",
"content": sentence
}
],
response_format={ "type": "json_object" }
)
return response.choices[0].message.content
# Weave를 초기화하고, 데이터를 기록할 팀과 프로젝트를 설정합니다
weave.init('your-team/traces-quickstart')
sentence = """I watched as a Tyrannosaurus rex (T. rex) chased after a Triceratops (Trike), \
both carnivore and herbivore locked in an ancient dance. Meanwhile, a gentle giant \
Brachiosaurus (Brachi) calmly munched on treetops, blissfully unaware of the chaos below."""
result = extract_dinos(sentence)
print(result)
// Weave 라이브러리를 임포트합니다
import * as weave from 'weave';
import OpenAI from 'openai';
const openai = new OpenAI();
// Weave는 이 함수의 입력, 출력, 코드를 자동으로 추적합니다
async function extractDinos(input: string) {
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{
role: 'user',
content: `In JSON format extract a list of 'dinosaurs', with their 'name', their 'common_name', and whether its 'diet' is a herbivore or carnivore: ${input}`,
},
],
});
return response.choices[0].message.content;
}
const extractDinosOp = weave.op(extractDinos);
async function main() {
// Weave를 초기화하고, 데이터를 기록할 팀과 프로젝트를 설정합니다
await weave.init('your-team/traces-quickstart');
const result = await extractDinosOp(
'I watched as a Tyrannosaurus rex (T. rex) chased after a Triceratops (Trike), both carnivore and herbivore locked in an ancient dance. Meanwhile, a gentle giant Brachiosaurus (Brachi) calmly munched on treetops, blissfully unaware of the chaos below.'
);
console.log(result);
}
main();
extract_dinos 함수를 호출하면 Weave는 터미널에 트레이스를 확인할 수 있는 링크를 출력합니다. 출력은 다음과 같습니다:
weave: $ pip install weave --upgrade
weave: Logged in as Weights & Biases user: example-username.
weave: View Weave data at https://wandb.ai/your-team/traces-quickstart/weave
weave: 🍩 https://wandb.ai/your-team/traces-quickstart/r/call/019ae171-7f32-7c96-8b42-931a32f900b7
{
"dinosaurs": [
{
"name": "Tyrannosaurus rex",
"common_name": "T. rex",
"diet": "carnivore"
},
{
"name": "Triceratops",
"common_name": "Trike",
"diet": "herbivore"
},
{
"name": "Brachiosaurus",
"common_name": "Brachi",
"diet": "herbivore"
}
]
}
터미널의 링크를 클릭하거나 브라우저에 붙여넣어 Weave UI를 여세요. Weave UI의 Traces 패널에서 트레이스를 클릭하면 입력, 출력, 지연 시간, token 사용량 등의 데이터를 볼 수 있습니다.
- 함수에 데코레이터를 적용하고 call 정보를 조회하는 방법을 알아보세요.
- 플레이그라운드를 사용해 로깅된 트레이스에서 다양한 모델을 테스트해 보세요.
- 인테그레이션을 살펴보세요. Weave는 OpenAI, Anthropic 등 다양한 LLM 라이브러리에 대한 call을 자동으로 추적합니다. 현재 사용 중인 LLM 라이브러리가 인테그레이션에 포함되어 있지 않더라도,
@weave.op()로 감싸면 다른 LLM 라이브러리나 프레임워크에 대한 call도 쉽게 추적할 수 있습니다.
앱 평가 시작하기를 먼저 살펴본 다음, RAG 애플리케이션 평가 방법을 확인하세요.