# 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)