Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-feature-automate-reference-docs-generation.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
이것은 인터랙티브 노트북입니다. 로컬에서 실행하거나 아래 링크를 사용할 수 있습니다:
🔑 사전 요구사항
Weave에서 추적을 시작하기 전에 다음 사전 요구사항을 완료하세요.
- W&B Weave SDK를 설치하고 다음으로 로그인하세요 API key.
- OpenAI SDK를 설치하고 다음으로 로그인하세요 API key.
- W&B 프로젝트를 초기화하세요.
# Install dependancies and imports
!pip install wandb weave openai -q
import json
import os
from getpass import getpass
from openai import OpenAI
import weave
# 🔑 Setup your API keys
# Running this cell will prompt you for your API key with `getpass` and will not echo to the terminal.
#####
print("---")
print(
"You can find your Weights and Biases API key here: https://wandb.ai/settings#api"
)
os.environ["WANDB_API_KEY"] = getpass("Enter your Weights and Biases API key: ")
print("---")
print("You can generate your OpenAI API key here: https://platform.openai.com/api-keys")
os.environ["OPENAI_API_KEY"] = getpass("Enter your OpenAI API key: ")
print("---")
#####
# 🏠 Enter your W&B project name
weave_client = weave.init("MY_PROJECT_NAME") # 🐝 Your W&B project name
🐝 첫 번째 추적 실행하기
다음 코드 샘플은 @weave.op 데코레이터를 사용하여 Weave에서 추적을 캡처하고 시각화하는 방법을 보여줍니다. 이는 extract_fruit라는 함수를 정의하며, 이 함수는 OpenAI의 GPT-4o에 문장에서 구조화된 데이터(과일, 색상, 맛)를 추출하도록 프롬프트를 보냅니다. 함수를 @weave.op로 데코레이팅하면, Weave는 입력, 출력 및 중간 단계를 포함한 함수 실행을 자동으로 추적합니다. 샘플 문장으로 함수가 호출되면 전체 추적이 저장되고 Weave UI에서 볼 수 있습니다.
@weave.op() # 🐝 Decorator to track requests
def extract_fruit(sentence: str) -> dict:
client = OpenAI()
system_prompt = (
"Parse sentences into a JSON dict with keys: fruit, color and flavor."
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": sentence},
],
temperature=0.7,
response_format={"type": "json_object"},
)
extracted = response.choices[0].message.content
return json.loads(extracted)
sentence = "There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy."
extract_fruit(sentence)
🚀 더 많은 예제를 찾고 계신가요?