base_url을 https://openrouter.ai/api/v1로, 모델을 OpenRouter의 여러 채팅 모델 중 하나로 변경하면 됩니다. weave.init()을 호출할 때 trace를 기록할 프로젝트 이름을 입력하세요. 별도로 지정하지 않으면 기본 엔티티가 사용됩니다. 기본 엔티티를 확인하거나 업데이트하려면 W&B Models 문서의 User Settings를 참조하세요.
자동 Weave 인테그레이션과 함께 OpenRouter의 통합 인터페이스를 사용하여 다양한 LLM을 활용하세요.
base_url을 https://openrouter.ai/api/v1로, 모델을 OpenRouter의 여러 채팅 모델 중 하나로 변경하면 됩니다. weave.init()을 호출할 때 trace를 기록할 프로젝트 이름을 입력하세요. 별도로 지정하지 않으면 기본 엔티티가 사용됩니다. 기본 엔티티를 확인하거나 업데이트하려면 W&B Models 문서의 User Settings를 참조하세요.
import os
import openai
import weave
weave.init('openrouter-weave')
system_content = "You are a travel agent. Be descriptive and helpful."
user_content = "Tell me about San Francisco"
client = openai.OpenAI(
api_key=os.environ.get("OPENROUTER_API_KEY"),
base_url="https://openrouter.ai/api/v1",
)
chat_completion = client.chat.completions.create(
extra_headers={
"HTTP-Referer": $YOUR_SITE_URL, # 선택 사항, openrouter.ai 순위에 앱을 포함하려는 경우 사용합니다.
"X-Title": $YOUR_APP_NAME, # 선택 사항. openrouter.ai의 순위에 표시됩니다.
},
model="meta-llama/llama-3.1-8b-instruct:free",
messages=[
{"role": "system", "content": system_content},
{"role": "user", "content": user_content},
],
temperature=0.7,
max_tokens=1024,
)
response = chat_completion.choices[0].message.content
print("Model response:\n", response)