From 249beac1f87b1d813815ab14d3a0498389d50df6 Mon Sep 17 00:00:00 2001 From: Wenshansilvia Date: Mon, 5 Feb 2024 15:43:38 +0800 Subject: [PATCH] initialize framework and rewriter module --- .github/workflows/makefile.yml | 31 +++++++++++++++++++ README.md | 20 +++++++++++- gomate/modules/components/HyDE_rewriter.py | 8 +++-- gomate/modules/components/__init__.py | 2 +- gomate/modules/rewriter.py | 19 +++++++----- tests/{build.py => test_build.py} | 7 ++--- ...ery_rewriter.py => test_query_rewriter.py} | 3 +- 7 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/makefile.yml rename tests/{build.py => test_build.py} (56%) rename tests/units/{query_rewriter.py => test_query_rewriter.py} (87%) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..9db9dbc --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,31 @@ +name: Makefile CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Python version + uses: actions/setup-python@v1 + with: + python-version: 3.8.18 + + - name: Install requirements + run: make init + + - name: Run check + run: make test + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index 72814db..dc69dbb 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# GoMate \ No newline at end of file +# GoMate + +RAG Framework with configurable modules. + +[![python](https://img.shields.io/badge/Python-3.8.18-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org) +![workflow status](https://github.com/gomate-community/rageval/actions/workflows/makefile.yml/badge.svg) +[![pydocstyle](https://img.shields.io/badge/pydocstyle-enabled-AD4CD3)](http://www.pydocstyle.org/en/stable/) +[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/) + +## Installation + +``` +git clone https://github.com/gomate-community/GoMate.git +``` +## Usage + +``` +git install ... +``` \ No newline at end of file diff --git a/gomate/modules/components/HyDE_rewriter.py b/gomate/modules/components/HyDE_rewriter.py index 26ba05a..b09c607 100644 --- a/gomate/modules/components/HyDE_rewriter.py +++ b/gomate/modules/components/HyDE_rewriter.py @@ -1,10 +1,14 @@ class HyDE_rewriter(): + """This is HyDE rewriter.""" + def __init__(self): + """Init the hyde rewriter model""" pass - def run(query, temperature): + def run(self, query, temperature): + """Get rewrited querys in runtime""" # TODO answer = [['改写后的回答']] - return(answer) \ No newline at end of file + return answer diff --git a/gomate/modules/components/__init__.py b/gomate/modules/components/__init__.py index c6d5de4..8d4c0a1 100644 --- a/gomate/modules/components/__init__.py +++ b/gomate/modules/components/__init__.py @@ -1 +1 @@ -from HyDE_rewriter import HyDE_rewriter \ No newline at end of file +from .HyDE_rewriter import HyDE_rewriter \ No newline at end of file diff --git a/gomate/modules/rewriter.py b/gomate/modules/rewriter.py index eec8573..4decae0 100644 --- a/gomate/modules/rewriter.py +++ b/gomate/modules/rewriter.py @@ -1,19 +1,24 @@ from .components import HyDE_rewriter -rewriter_list = ['hyde'] class Rewriter(): - ''' - 改写模块,用于理解和优化用户的原始问题。实现包括: + """改写模块,用于理解和优化用户的原始问题。 + + 实现包括 1. HyDE。用生成式大模型预回答,返回生成的假定答案。 2. ... - ''' + + """ + def __init__(self, component_name=None): - assert component_name in rewriter_list + """Init required rewriter according to component name.""" + self.rewriter_list = ['hyde'] + assert component_name in self.rewriter_list if component_name == 'hyde': self.rewriter = HyDE_rewriter() - + def run(self, query, temperature=1e-10): + """Run the required rewriter""" if query is None: raise ValueError('原始问题不能为空') - return(self.rewriter.run(query, temperature = temperature)) \ No newline at end of file + return self.rewriter.run(query, temperature) diff --git a/tests/build.py b/tests/test_build.py similarity index 56% rename from tests/build.py rename to tests/test_build.py index ffd8a70..29fb0f3 100644 --- a/tests/build.py +++ b/tests/test_build.py @@ -1,12 +1,9 @@ """Test building RAG system.""" - -import sys -sys.path.insert(0, '../src') import pytest -@pytest.mark.cron +@pytest.mark.skip def test_build(): ''' xx ''' - pass + return diff --git a/tests/units/query_rewriter.py b/tests/units/test_query_rewriter.py similarity index 87% rename from tests/units/query_rewriter.py rename to tests/units/test_query_rewriter.py index 33ebd34..6c85dda 100644 --- a/tests/units/query_rewriter.py +++ b/tests/units/test_query_rewriter.py @@ -1,3 +1,4 @@ +import pytest from gomate.modules import Rewriter # import os @@ -5,7 +6,7 @@ def test_rewriter(): component_name = 'hyde' model = Rewriter(component_name = component_name) query = ['gomate是哪天发布的?','gomate是做什么的?'] - answer = model(query) + answer = model.run(query) assert answer is not None if __name__ == '__main__':