Contribute an Adapter
What is an adapter?
In the Unstract code, every LLM / Embedding / VectorDB / X2Text provider is termed as an adapter. Navigating through the adapters code, there are categorisations for adapters like LLM, Embedding, VectorDB, X2Text etc. Each category has the supported adapter providers nested under it. One can see, for example, support for Azure OpenAI here.
What can one contribute here?
There could be cases where a user will need support for a new adapter in the Unstract system. In such cases, one can contribute the support for the same and begin to use it for their use-cases.
Easy steps to start contributing a new adapter
- Choose the category of adapter (LLM, Embedding, VectorDB, X2Text, etc.)
- Duplicate an existing provider under that category and give it an appropriate name.
- Each provider folder has a src folder which contains the relevant code to support an adapter.
- The static folder under this contains the json_schema which will define the required fields that should show up in the UI when user chooses to configure this adapter.
- Also, there is a Python class for each adapter which implements the base class depending on the category of adapter. Make sure to put in all the configuration and instantiation logic in this class.
- Make sure to generate a new UUID for the adapter that is being added.
- The new adapter will also need a logo. Make sure to copy an appropriate icon for the same in the Unstract repo so that it shows up appropriately in UI
- The newly added adapter can be subjected to unit testing by a simple test. The unit test uses a env file similar to this sample.
Once this is done, the new adapter should be ready to use. At this stage, a PR can be raised for the above-mentioned changes post incrementing the version.
Things to keep in mind
- The existing LLM, Embedding and VectorDB adapters supported in Unstract are using the LlamaIndex framework underneath. So while adding a new adapter, one can always check for the support of this adapter in LlamaIndex. This will keep the functionality of this new adapter intact with other existing ones.
- Some of the Llama-index functions for LLM like complete and stream_complete are wrapped by Unstract functions. While contributing, it is good to be mindful of the same and make suitable changes accordingly
- In order to see the adapters in action across the platform, the SDK needs to be built and published in pypi with a new version. Once that is done, the dependent modules/services can use the same in order to pull the latetst changes.