import weave
// TODO: 'your-team-name/your-project-name' を正しい値に設定します。
client = weave.init('your-team-name/your-project-name')
# プロンプトの 2 つのバージョンを公開します。
v0_ref = weave.publish(
weave.StringPrompt("Answer the user's question: {question}"),
name="my-prompt",
)
v1_ref = weave.publish(
weave.StringPrompt("Answer the user's question helpfully and concisely: {question}"),
name="my-prompt",
)
# --- エイリアス: 特定のバージョンを指す名前付きポインタ。 ---
# バージョンにエイリアスを設定します。
client.set_aliases(v0_ref, "staging")
client.set_aliases(v1_ref, "production")
# バージョンのエイリアスを取得します。
client.get_aliases(v1_ref) # ["production", "latest"]
# 別のバージョンに設定してエイリアスを移動します。
client.set_aliases(v0_ref, "production") # v1 から自動的に解除されます。
# エイリアスを解決してオブジェクトを読み込みます。
prompt = weave.ref("my-prompt:production").get()
# プロジェクト内のすべてのエイリアスを一覧表示します。
client.list_aliases()
# エイリアスを削除します。
client.remove_aliases(v0_ref, "production")
# --- タグ: 特定のバージョンに付くラベル。 ---
# バージョンにタグを追加します。
client.add_tags(v0_ref, ["reviewed", "passed-eval"])
client.add_tags(v1_ref, ["reviewed", "needs-improvement"])
# バージョンのタグを取得します。
client.get_tags(v0_ref) # ["passed-eval", "reviewed"]
# プロジェクト内の重複しないすべてのタグを一覧表示します。
client.list_tags()
# バージョンからタグを削除します。
client.remove_tags(v1_ref, ["needs-improvement"])
# --- 組み合わせ: 両方を 1 回の呼び出しで取得します。 ---
tags, aliases = client.get_tags_and_aliases(v0_ref)
# --- タグとエイリアスをインラインで付けて公開します。 ---
ref = weave.publish(
weave.StringPrompt("Be brief: {question}"),
name="my-prompt",
tags=["reviewed"],
aliases=["production"],
)