base_url을 https://openrouter.ai/api/v1로, 모델을 다양한 채팅 모델 중 하나로 변경하세요. weave.init()를 호출할 때는 트레이스를 위한 프로젝트 이름을 지정하세요. 지정하지 않으면 기본 entity가 사용됩니다. 기본 entity를 찾거나 업데이트하려면 W&B Models 문서의 User Settings를 참고하세요.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Help us improve these docs. Take our quick survey.
자동 Weave 인테그레이션으로 여러 LLM에서 OpenRouter의 통합 인터페이스를 사용하세요
base_url을 https://openrouter.ai/api/v1로, 모델을 다양한 채팅 모델 중 하나로 변경하세요. weave.init()를 호출할 때는 트레이스를 위한 프로젝트 이름을 지정하세요. 지정하지 않으면 기본 entity가 사용됩니다. 기본 entity를 찾거나 업데이트하려면 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)