Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Weave を使用して、Cerebras Cloud SDK 経由の LLM call をトレースしてログする
import os import weave from cerebras.cloud.sdk import Cerebras # Weave プロジェクトを初期化する weave.init("cerebras_speedster") # Cerebras SDK を通常通り使用する api_key = os.environ["CEREBRAS_API_KEY"] model = "llama3.1-8b" # Cerebras モデル 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)
import os import weave from cerebras.cloud.sdk import Cerebras # Weave プロジェクトを初期化する weave.init("cerebras_speedster") client = Cerebras(api_key=os.environ["CEREBRAS_API_KEY"]) # Weave はこの関数の入力、出力、コードをトラッキングする @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
import os import weave from cerebras.cloud.sdk import Cerebras # Weave プロジェクトを初期化する 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)
このページは役に立ちましたか?