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は Cerebras Cloud SDK を介して行われたLLM呼び出しを自動的に追跡し、ログに記録します。
トレース
LLM呼び出しの追跡は、デバッグとパフォーマンスモニタリングにとって非常に重要です。Weaveは、Cerebras Cloud SDKのトレースを自動的にキャプチャすることで、これを支援します。
以下は、WeaveをCerebrasと共に使用する例です:
import os
import weave
from cerebras.cloud.sdk import Cerebras
# Initialise the weave project
weave.init("cerebras_speedster")
# Use the Cerebras SDK as usual
api_key = os.environ["CEREBRAS_API_KEY"]
model = "llama3.1-8b" # Cerebras model
client = Cerebras(api_key=api_key)
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "What's the fastest land animal?"}],
)
print(response.choices[0].message.content)
これで、Weaveは、Cerebras SDKを通じて行われるすべてのLLM呼び出しを追跡し、ログに記録します。トークン使用量やレスポンス時間などの詳細を含むトレースは、Weaveウェブインターフェースで確認できます。
独自のopsでラップする
Weave opsは、実験の再現性とトレーサビリティを強化するための強力な方法を提供します。コードを自動的にバージョン管理し、入力と出力をキャプチャします。以下は、Cerebras SDKでWeave opsを活用する方法の例です:
import os
import weave
from cerebras.cloud.sdk import Cerebras
# Initialise the weave project
weave.init("cerebras_speedster")
client = Cerebras(api_key=os.environ["CEREBRAS_API_KEY"])
# Weave will track the inputs, outputs and code of this function
@weave.op
def animal_speedster(animal: str, model: str) -> str:
"Find out how fast an animal can run"
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": f"How fast can a {animal} run?"}],
)
return response.choices[0].message.content
animal_speedster("cheetah", "llama3.1-8b")
animal_speedster("ostrich", "llama3.1-8b")
animal_speedster("human", "llama3.1-8b")
より簡単な実験のために Model を作成する
Weaveの Model クラスは、アプリケーションの異なるイテレーションを整理し比較するのに役立ちます。これは、Cerebrasモデルを実験する際に特に便利です。以下は例です:
import os
import weave
from cerebras.cloud.sdk import Cerebras
# Initialise the weave project
weave.init("cerebras_speedster")
client = Cerebras(api_key=os.environ["CEREBRAS_API_KEY"])
class AnimalSpeedModel(weave.Model):
model: str
temperature: float
@weave.op
def predict(self, animal: str) -> str:
"Predict the top speed of an animal"
response = client.chat.completions.create(
model=self.model,
messages=[{"role": "user", "content": f"What's the top speed of a {animal}?"}],
temperature=self.temperature
)
return response.choices[0].message.content
speed_model = AnimalSpeedModel(
model="llama3.1-8b",
temperature=0.7
)
result = speed_model.predict(animal="cheetah")
print(result)
このセットアップにより、Cerebrasを活用した推論を追跡しながら、異なるモデルやパラメータを簡単に実験できます!
