Skip to content

Commit

Permalink
add tests and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ILSparkle committed Jun 3, 2024
1 parent 802d20e commit 6f471ae
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,54 @@ jobs:
- name: Check quality
run: |
make style && make quality
tests:
needs: check_code_quality

env:
OPENAI_BASE_URL=http://localhost:8010/v1
OPENAI_API_KEY=0
EMBED_MODEL=text-embedding-ada-002
CHAT_MODEL=gpt-3.5-turbo
TOKENIZER_PATH=01-ai/Yi-6B-Chat
CHUNK_SIZE=200
CHUNK_OVERLAP=30
STORAGE=redis
SEARCH_TARGET=content
REDIS_URI=redis://localhost:6379
ELASTICSEARCH_URI=http://localhost:9001
VECTORSTORE=chroma
CHROMA_PATH=./chroma
MILVUS_URI=http://localhost:19530
MILVUS_TOKEN=0

services:
redis:
image: redis
ports:
- 6379: 6379

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
os: ["ubuntu-latest", "windows-latest"]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "setup.py"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# cpu version of pytorch
pip install -e .
pip install -r requirements-dev.txt
- name: Test with pytest
run: |
make test
14 changes: 14 additions & 0 deletions tests/collector/test_msg_collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#from dotenv import load_dotenv
#load_dotenv()

from cardinal.collector import MsgCollector
from cardinal.common import HumanMessage, AssistantMessage

def test_msg_collector():
collector = MsgCollector(storage_name="test", drop_old=True)
messages = [HumanMessage(content="hi"), AssistantMessage(content="hi there")]
collector.collect(messages)
messages = [HumanMessage(content="foo"), AssistantMessage(content="foo too")]
collector.collect(messages)
res = "[[HumanMessage(content='hi', role=<Role.USER: 'user'>), AssistantMessage(content='hi there', role=<Role.ASSISTANT: 'assistant'>)], [HumanMessage(content='foo', role=<Role.USER: 'user'>), AssistantMessage(content='foo too', role=<Role.ASSISTANT: 'assistant'>)]]"
assert(str(collector.dump()) == res)
11 changes: 11 additions & 0 deletions tests/model/test_chat_openai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from cardinal.common import HumanMessage
from cardinal.model import ChatOpenAI
import pytest


@pytest.mark.skip(reason='todo')
def test_chat_openai():
chat_openai = ChatOpenAI()
messages = [HumanMessage(content="Say this is a test")]
print(chat_openai.chat(messages))

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added tests/storage/test_redis.py
Empty file.
Empty file.
Empty file.

0 comments on commit 6f471ae

Please sign in to comment.