Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding support for external chat format contribution #1716

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

axel7083
Copy link

@axel7083 axel7083 commented Aug 29, 2024

Description 📖

This PR aims to allow external python package to contribute to the LlamaChatCompletionHandlerRegistry.

Fixes #1715

Security 🔒

This feature is enabled by default, but we could disable it, the idea is to give some control to the users.

Example 🔍

Package outside llama-cpp-python can declare an entrypoint such as bellow

let's say you have a packaged called timmins-plugin-fancy. You can declare an entrypoint as followed

[project.entry-points."llama_cpp_python.register_chat_format"]
load = "timmins-plugin-fancy.llama_cpp_python:load"

Then when the server would start they would receive a LlamaChatCompletionHandlerRegistry instance, which can be used to register custom chat format handler.

Inside your timmins-plugin-fancy package you could have the following

timmins-plugin-fancy
├── pyproject.toml        # and/or setup.cfg, setup.py
└── llama_cpp_python
    └── timmins_plugin_fancy
        └── __init__.py

Here is what the __init__.py could look likes.

import llama_cpp.llama as llama
from llama_cpp.llama_chat_format import LlamaChatCompletionHandlerRegistry

def load(registry: LlamaChatCompletionHandlerRegistry):
    registry.register_chat_completion_handler('timmins-chat', timmins_new_chat_handler, overwrite=True)

@axel7083 axel7083 marked this pull request as ready for review August 30, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow python packages to contribute to LlamaChatCompletionHandlerRegistry
1 participant