Use random seed (#13544)

For default eval llm
This commit is contained in:
William FH 2023-11-17 16:33:31 -08:00 committed by GitHub
parent 79ed66f870
commit cac849ae86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -160,7 +160,7 @@ class PairwiseStringEvalChain(PairwiseStringEvaluator, LLMEvalChain, LLMChain):
Example: Example:
>>> from langchain.chat_models import ChatOpenAI >>> from langchain.chat_models import ChatOpenAI
>>> from langchain.evaluation.comparison import PairwiseStringEvalChain >>> from langchain.evaluation.comparison import PairwiseStringEvalChain
>>> llm = ChatOpenAI(temperature=0, model_name="gpt-4") >>> llm = ChatOpenAI(temperature=0, model_name="gpt-4", model_kwargs={"random_seed": 42})
>>> chain = PairwiseStringEvalChain.from_llm(llm=llm) >>> chain = PairwiseStringEvalChain.from_llm(llm=llm)
>>> result = chain.evaluate_string_pairs( >>> result = chain.evaluate_string_pairs(
... input = "What is the chemical formula for water?", ... input = "What is the chemical formula for water?",
@ -179,7 +179,7 @@ class PairwiseStringEvalChain(PairwiseStringEvaluator, LLMEvalChain, LLMChain):
# . " by explaining what the formula means.\\n[[B]]" # . " by explaining what the formula means.\\n[[B]]"
# } # }
""" """ # noqa: E501
output_key: str = "results" #: :meta private: output_key: str = "results" #: :meta private:
output_parser: BaseOutputParser = Field( output_parser: BaseOutputParser = Field(

View File

@ -130,7 +130,9 @@ def load_evaluator(
evaluator_cls = _EVALUATOR_MAP[evaluator] evaluator_cls = _EVALUATOR_MAP[evaluator]
if issubclass(evaluator_cls, LLMEvalChain): if issubclass(evaluator_cls, LLMEvalChain):
try: try:
llm = llm or ChatOpenAI(model="gpt-4", temperature=0) llm = llm or ChatOpenAI(
model="gpt-4", model_kwargs={"seed": 42}, temperature=0
)
except Exception as e: except Exception as e:
raise ValueError( raise ValueError(
f"Evaluation with the {evaluator_cls} requires a " f"Evaluation with the {evaluator_cls} requires a "