Skip to content

Commit

Permalink
fix: library documentation for registering callback handler is incorr…
Browse files Browse the repository at this point in the history
…ect (#57)

* 💡 update error message

* 📝 update docs

* ➕ add new sphinx extensions

* 🔧 add new make recipe
  • Loading branch information
ajndkr authored May 22, 2023
1 parent 517248c commit 7d9cd02
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ coverage: ## run unit tests with coverage

pre-commit: ## run pre-commit hooks
poetry run pre-commit run --all-files

build-docs: ## build documentation
poetry run sphinx-autobuild -b html --host 0.0.0.0 --port 8000 docs docs/_build/html
8 changes: 6 additions & 2 deletions docs/advanced/custom_callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ Let's first create a custom chain called ``ConversationalRetrievalWithSourcesCha
result[self.sources_output_key] = sources
return result
Next, we will define a new callback handler and add it to the registry:
Next, we will define a new streaming callback handler and add it to the registry:

.. code-block:: python
from lanarky.register import register_callback
from lanarky.register import register_streaming_callback
@register_streaming_callback("ConversationalRetrievalWithSourcesChain")
class AsyncConversationalRetrievalWithSourcesChainStreamingCallback(
AsyncConversationalRetrievalChainStreamingCallback
Expand All @@ -77,3 +78,6 @@ Next, we will define a new callback handler and add it to the registry:
Once your callback handler is registered, Lanarky will automatically detect it using your custom chain when
you use the ``StreamingResponse`` class in your FastAPI application.

For more register functions, check out the ``lanarky.register`` module
`reference <https://lanarky.readthedocs.io/en/latest/lanarky/lanarky.register.html>`_.
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"sphinx.ext.napoleon",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"myst_parser",
"sphinx_copybutton",
"sphinxcontrib.autodoc_pydantic",
]

# autodoc: Default to members and undoc-members
Expand Down
6 changes: 5 additions & 1 deletion lanarky/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
"AsyncAgentsWebsocketCallback",
]

ERROR_MESSAGE = """Error! Chain type '{chain_type}' is not currently supported by '{callable_name}'."""
ERROR_MESSAGE = """Error! Chain type '{chain_type}' is not currently supported by '{callable_name}'.
To use a custom chain type, you must register a new callback handler.
See the documentation for more details: https://lanarky.readthedocs.io/en/latest/advanced/custom_callbacks.html
"""


def get_streaming_callback(
Expand Down
4 changes: 2 additions & 2 deletions lanarky/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _register_cls(cls: Any, required_kwargs: Optional[List] = None) -> Any:


def register_streaming_callback(key: str) -> Callable:
"""Register an streaming callback handler."""
"""Register a streaming callback handler."""

def _register_cls(cls: Any) -> Callable:
register(key, STREAMING_CALLBACKS)(cls=cls)
Expand All @@ -33,7 +33,7 @@ def _register_cls(cls: Any) -> Callable:


def register_websocket_callback(key: str) -> Callable:
"""Register an websocket callback handler."""
"""Register a websocket callback handler."""

def _register_cls(cls: Any) -> Callable:
register(key, WEBSOCKET_CALLBACKS)(cls=cls)
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pre-commit = "^3.3.1"
[tool.poetry.group.docs.dependencies]
furo = "^2023.3.27"
sphinx-autobuild = "^2021.3.14"
myst-parser = "^1.0.0"
sphinx-copybutton = "^0.5.2"
autodoc-pydantic = "^1.8.0"


[tool.poetry.group.tests.dependencies]
Expand Down

0 comments on commit 7d9cd02

Please sign in to comment.