community: Force opt-in for qa chains (#26278)

The underlying code is already documented as requiring appropriate RBAC
control, but adding a forced user opt-in to make sure that users
that don't read documentation are still aware of what's required
from a security perspective.

https://huntr.com/bounties/8f4ad910-7fdc-4089-8f0a-b5df5f32e7c5
This commit is contained in:
Eugene Yurtsev
2024-09-10 15:59:03 -04:00
committed by GitHub
parent c43c62b6c9
commit 374bb40852
12 changed files with 346 additions and 0 deletions

View File

@@ -59,6 +59,7 @@ def test_graph_cypher_qa_chain_prompt_selection_1() -> None:
return_intermediate_steps=False,
qa_prompt=qa_prompt,
cypher_prompt=cypher_prompt,
allow_dangerous_requests=True,
)
assert chain.qa_chain.prompt == qa_prompt # type: ignore[union-attr]
assert chain.cypher_generation_chain.prompt == cypher_prompt
@@ -71,6 +72,7 @@ def test_graph_cypher_qa_chain_prompt_selection_2() -> None:
graph=FakeGraphStore(),
verbose=True,
return_intermediate_steps=False,
allow_dangerous_requests=True,
)
assert chain.qa_chain.prompt == CYPHER_QA_PROMPT # type: ignore[union-attr]
assert chain.cypher_generation_chain.prompt == CYPHER_GENERATION_PROMPT
@@ -87,6 +89,7 @@ def test_graph_cypher_qa_chain_prompt_selection_3() -> None:
return_intermediate_steps=False,
cypher_llm_kwargs={"memory": readonlymemory},
qa_llm_kwargs={"memory": readonlymemory},
allow_dangerous_requests=True,
)
assert chain.qa_chain.prompt == CYPHER_QA_PROMPT # type: ignore[union-attr]
assert chain.cypher_generation_chain.prompt == CYPHER_GENERATION_PROMPT
@@ -107,6 +110,7 @@ def test_graph_cypher_qa_chain_prompt_selection_4() -> None:
return_intermediate_steps=False,
cypher_llm_kwargs={"prompt": cypher_prompt, "memory": readonlymemory},
qa_llm_kwargs={"prompt": qa_prompt, "memory": readonlymemory},
allow_dangerous_requests=True,
)
assert chain.qa_chain.prompt == qa_prompt # type: ignore[union-attr]
assert chain.cypher_generation_chain.prompt == cypher_prompt
@@ -130,6 +134,7 @@ def test_graph_cypher_qa_chain_prompt_selection_5() -> None:
cypher_prompt=cypher_prompt,
cypher_llm_kwargs={"memory": readonlymemory},
qa_llm_kwargs={"memory": readonlymemory},
allow_dangerous_requests=True,
)
assert False
except ValueError:
@@ -181,6 +186,7 @@ def test_graph_cypher_qa_chain() -> None:
return_intermediate_steps=False,
cypher_llm_kwargs={"prompt": prompt, "memory": readonlymemory},
memory=memory,
allow_dangerous_requests=True,
)
chain.run("Test question")
chain.run("Test new question")