Add reviewed OpenWebUI quick actions
This commit is contained in:
@@ -31,6 +31,7 @@ fake_pydantic.Field = lambda default=None, **kwargs: default
|
||||
sys.modules.setdefault("pydantic", fake_pydantic)
|
||||
|
||||
FILTER_DIR = Path(__file__).parents[1] / "platform" / "openwebui" / "filters"
|
||||
ACTION_DIR = Path(__file__).parents[1] / "platform" / "openwebui" / "actions"
|
||||
|
||||
|
||||
def _load(name: str):
|
||||
@@ -41,6 +42,14 @@ def _load(name: str):
|
||||
return module
|
||||
|
||||
|
||||
def _load_action(name: str):
|
||||
spec = importlib.util.spec_from_file_location(name, ACTION_DIR / f"{name}.py")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class StabilityGuardTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def asyncSetUp(self):
|
||||
self.module = _load("stability_guard")
|
||||
@@ -167,5 +176,57 @@ class SecretRedactionTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertNotIn("abcdefghijklmnopqrstuvwxyz", result["messages"][0]["content"])
|
||||
|
||||
|
||||
class QuickActionTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def asyncSetUp(self):
|
||||
self.module = _load_action("quick_actions")
|
||||
self.action = self.module.Action()
|
||||
self.body = {
|
||||
"id": "assistant-1",
|
||||
"model": "qwen-fast",
|
||||
"messages": [
|
||||
{"id": "user-1", "role": "user", "content": "Frage"},
|
||||
{"id": "assistant-1", "role": "assistant", "content": "Lange Antwort"},
|
||||
],
|
||||
}
|
||||
|
||||
async def test_summary_appends_to_selected_message(self):
|
||||
async def fake_completion(*args, **kwargs):
|
||||
return "- Kurze Antwort"
|
||||
|
||||
self.action._completion = fake_completion
|
||||
result = await self.action.action(self.body, "summary")
|
||||
self.assertEqual(result["messages"][0]["id"], "assistant-1")
|
||||
self.assertIn("### Kurzfassung", result["messages"][0]["content"])
|
||||
self.assertIn("Kurze Antwort", result["messages"][0]["content"])
|
||||
|
||||
async def test_source_check_uses_web_evidence(self):
|
||||
completions = iter(["Qwen Fakten", "Bestätigt: Aussage [https://example.invalid]"])
|
||||
|
||||
async def fake_completion(*args, **kwargs):
|
||||
return next(completions)
|
||||
|
||||
async def fake_web(query):
|
||||
self.assertEqual(query, "Qwen Fakten")
|
||||
return '{"sources":[{"url":"https://example.invalid"}]}'
|
||||
|
||||
self.action._completion = fake_completion
|
||||
self.action._web_research = fake_web
|
||||
result = await self.action.action(self.body, "sources")
|
||||
self.assertIn("### Quellenprüfung", result["messages"][0]["content"])
|
||||
self.assertIn("example.invalid", result["messages"][0]["content"])
|
||||
|
||||
async def test_markdown_copy_uses_browser_clipboard(self):
|
||||
calls = []
|
||||
|
||||
async def event_call(event):
|
||||
calls.append(event)
|
||||
return True
|
||||
|
||||
await self.action.action(self.body, "copy_markdown", __event_call__=event_call)
|
||||
self.assertEqual(calls[0]["type"], "execute")
|
||||
self.assertIn("navigator.clipboard.writeText", calls[0]["data"]["code"])
|
||||
self.assertIn("Lange Antwort", calls[0]["data"]["code"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user