Skip to content

Commit 3896ba0

Browse files
committed
feat(hallucination): warn and exit if 'n' param unsupported
1 parent 73d3ffd commit 3896ba0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

nemoguardrails/library/hallucination/actions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141

4242
@action()
4343
async def self_check_hallucination(
44+
llm: BaseLLM,
4445
llm_task_manager: LLMTaskManager,
4546
context: Optional[dict] = None,
46-
llm: Optional[BaseLLM] = None,
4747
use_llm_checking: bool = True,
4848
config: Optional[RailsConfig] = None,
4949
):
@@ -72,6 +72,13 @@ async def self_check_hallucination(
7272
f"Current LLM engine is {type(llm).__name__}, which may not support all features."
7373
)
7474

75+
if "n" not in llm.__fields__:
76+
log.warning(
77+
f"LLM engine {type(llm).__name__} does not support the 'n' parameter for generating multiple completion choices. "
78+
f"Please use an OpenAI LLM engine or a model that supports the 'n' parameter for optimal performance."
79+
)
80+
return False
81+
7582
# Use the "generate" call from langchain to get all completions in the same response.
7683
last_bot_prompt = PromptTemplate(template="{text}", input_variables=["text"])
7784
chain = LLMChain(prompt=last_bot_prompt, llm=llm)

0 commit comments

Comments
 (0)