diff --git a/docs/examples/guide/plugin_methods/example1.py b/docs/examples/guide/plugin_methods/example1.py new file mode 100644 index 0000000..190f8f1 --- /dev/null +++ b/docs/examples/guide/plugin_methods/example1.py @@ -0,0 +1,24 @@ +from pyflowlauncher import Plugin, Result, send_results +from pyflowlauncher.result import ResultResponse + +plugin = Plugin() + + +@plugin.on_method +def query(query: str) -> ResultResponse: + r = Result( + Title="This is a title!", + SubTitle="This is the subtitle!", + JsonRPCAction={"method": "action", "parameters": []} + ) + return send_results([r]) + + +@plugin.on_method +def action(params: list[str]): + pass + # Do stuff here + # ... + + +plugin.run() diff --git a/docs/examples/guide/plugin_methods/example2.py b/docs/examples/guide/plugin_methods/example2.py new file mode 100644 index 0000000..023cd65 --- /dev/null +++ b/docs/examples/guide/plugin_methods/example2.py @@ -0,0 +1,23 @@ +from pyflowlauncher import Plugin, Result, send_results +from pyflowlauncher.result import ResultResponse + +plugin = Plugin() + + +@plugin.on_method +def query(query: str) -> ResultResponse: + r = Result( + Title="This is a title!", + SubTitle="This is the subtitle!", + JsonRPCAction=plugin.action(action, ["stuff"]) + ) + return send_results([r]) + + +def action(params: list[str]): + pass + # Do stuff here + # ... + + +plugin.run() diff --git a/docs/examples/guide/scoring_results/example1.py b/docs/examples/guide/scoring_results/example1.py new file mode 100644 index 0000000..38bf7be --- /dev/null +++ b/docs/examples/guide/scoring_results/example1.py @@ -0,0 +1,20 @@ +from pyflowlauncher import Plugin, Result, send_results +from pyflowlauncher.result import ResultResponse +from pyflowlauncher.utils import score_results + +plugin = Plugin() + + +@plugin.on_method +def query(query: str) -> ResultResponse: + results = [] + for _ in range(100): + r = Result( + Title="This is a title!", + SubTitle="This is the subtitle!", + ) + results.append(r) + return send_results(score_results(query, results)) + + +plugin.run() diff --git a/docs/guide/Plugin methods.md b/docs/guide/Plugin methods.md new file mode 100644 index 0000000..009f231 --- /dev/null +++ b/docs/guide/Plugin methods.md @@ -0,0 +1,19 @@ +# Triggering Plugin methods + +Flow Launcher can call custom methods created by your plugin as well. To do so simply register the method with your plugin. + +You can register any Function by using the `on_method` decorator or by using the `add_method` method from `Plugin`. + +## Example 1 + +```py +--8<-- "docs/examples/guide/plugin_methods/example1.py" +``` + +Alternativley you can register and add the Method to a Result in one line by using `action` method. + +## Example 2 + +```py +--8<-- "docs/examples/guide/plugin_methods/example2.py" +``` diff --git a/docs/guide/scoring_results.md b/docs/guide/scoring_results.md new file mode 100644 index 0000000..db9b47e --- /dev/null +++ b/docs/guide/scoring_results.md @@ -0,0 +1,9 @@ +# Score results + +PyFlowLauncher comes with a handy utility to help score your results in a similar manner to how Flow Launcher does internally. + +## Example + +```py +--8<-- "docs/examples/guide/scoring_results/example1.py" +```