Before contributing to GPT Cache, it is recommended to read the system design article.
In the process of contributing, pay attention to the parameter type, because there is currently no type restriction added.
First check which part you want to contribute:
- Add a scalar store type
- Add a vector store type
- Add a vector index type
- Add a new data manager
- Add a embedding function
- Add a similarity evaluation function
- Add a method to post-process the cache answer list
- Add a new process in handling chatgpt requests
For newly added third-party dependencies, lazy import and automatic installation are required. Implementation consists of the following steps:
- Lazy import
# The __init__.py file of the same directory under the new file
__all__ = ['Milvus']
from gptcache.util.lazy_import import LazyImport
milvus = LazyImport('milvus', globals(), 'gptcache.cache.vector_data.milvus')
def Milvus(**kwargs):
return milvus.Milvus(**kwargs)
- Automatic installation
# 2.1 Add the import method
# add new method to util/__init__.py
__all__ = ['import_pymilvus']
from .dependency_control import prompt_install
def import_pymilvus():
try:
# pylint: disable=unused-import
import pymilvus
except ModuleNotFoundError as e: # pragma: no cover
prompt_install('pymilvus')
import pymilvus # pylint: disable=ungrouped-imports
# 2.2 use the import method in your file
from gptcache.util import import_pymilvus
import_pymilvus()
refer to the implementation of sqlite.
- Implement the ScalarStore interface
- Make sure the newly added third-party libraries are lazy imported and automatic installation
- Add the new store to the _get_scalar_store method
- Add a usage example to example directory and add the corresponding content to example.md README.md
refer to the implementation of milvus.
- Implement the VectorStore interface
- Make sure the newly added third-party libraries are lazy imported and automatic installation
- Add the new store to the get_ss_data_manager method
- Add a usage example to example directory and add the corresponding content to example.md README.md
refer to the implementation of faiss.
- Implement the VectorIndex interface
- Make sure the newly added third-party libraries are lazy imported and automatic installation
- Add the new store to the get_si_data_manager method
- Add a usage example to example directory and add the corresponding content to example.md README.md
refer to the implementation of MapDataManager, SSDataManager or SIDataManager.
- Implement the DataManager interface
- Add the new store to the get_data_manager method
- Add a usage example to example directory and add the corresponding content to example.md README.md
refer to the implementation of towhee or openai.
- Add a new python file to embedding directory
- Make sure the newly added third-party libraries are lazy imported and automatic installation
- Implement the embedding function and make sure your output dimension
- Add a usage example to example directory and add the corresponding content to example.md README.md
refer to the implementation of pair_evaluation or towhee
- Make sure the input params, you can learn more about in the user view model
rank = chat_cache.evaluation_func({
"question": pre_embedding_data,
"embedding": embedding_data,
}, {
"question": cache_question,
"answer": cache_answer,
"search_result": cache_data,
}, extra_param=context.get('evaluation', None))
- Make sure the newly added third-party libraries are lazy imported and automatic installation
- Implement the similarity evaluation function
- Add a usage example to example directory and add the corresponding content to example.md README.md
refer to the implementation of first or random_one
- Make sure the input params, you can learn more about in the user view model
- Make sure the newly added third-party libraries are lazy imported and automatic installation
- Implement the post method
- Add a usage example to example directory and add the corresponding content to example.md README.md
- Need to have a clear understanding of the current process, refer to the user view model
- Add a new process
- Make sure all examples work properly