LoginSignup
1
1

[LangChain]AzureChatOpenAIでseedを固定する方法

Posted at

はじめに

GPT4-TurboのseedをLangChainのAzureChatOpenAIで指定する方法が分からなかったので調べてみました。
結論はmodel_kwargsに書くそうです。しかし、結果が安定しなかったので、本当に固定できているのか簡単な検証をしてみました。

gpt4 = AzureChatOpenAI(
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    openai_api_key=os.environ["AZURE_OPENAI_API_KEY"],
    openai_api_version="2023-09-01-preview",
    deployment_name=deployment_name,
    model_name=model_name,
    model_kwargs={"seed": 42}, #ここにseedを書く
    temperature=0.0
)

検証

ランダムな値を出力するプロンプトで実験しました。

prompt = """
完全にランダムな数字を1つ返してください。数字だけ返してください。
"""

for i in range(10):
    response = gpt4.invoke(prompt)
    print(response)
#seedなしの場合
content='2473659'
content='7548329'
content='9827'
content='7429'
content='156349'
content='3759'
content='3478'
content='54783921'
content='9827'
content='4179'

#seedありの場合
content='4287'
content='4287'
content='4287'
content='4287'
content='4287'
content='4287'
content='4287'
content='4287'
content='4287'
content='4287'

seedありの方は結果が固定されています。

まとめ

LangChainのAzureChatOpenAIでseedを固定する方法を調べました。
ただし、結果は結構ぶれるので、現状はそこまで期待しないほうがよさそうです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1