We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 135612d commit 2b9734dCopy full SHA for 2b9734d
src/ragas/metrics/llms.py
@@ -20,10 +20,12 @@ def generate(
20
n: t.Optional[int] = None,
21
) -> LLMResult:
22
old_n = None
23
+ n_swapped = False
24
if n is not None:
25
if isinstance(llm, OpenAI) or isinstance(llm, ChatOpenAI):
26
old_n = llm.n
27
llm.n = n
28
+ n_swapped = True
29
else:
30
raise Exception(
31
f"n={n} was passed to generate but the LLM {llm} does not support it."
@@ -36,6 +38,6 @@ def generate(
36
38
ps = [p.format_messages() for p in prompts]
37
39
result = llm.generate(ps)
40
- if isinstance(llm, OpenAI) or isinstance(llm, ChatOpenAI):
41
+ if (isinstance(llm, OpenAI) or isinstance(llm, ChatOpenAI)) and n_swapped:
42
llm.n = old_n # type: ignore
43
return result
0 commit comments