jerpint commited on
Commit
1696c32
1 Parent(s): 1571e29

Add simple chatbot test (#61)

Browse files

* Add simple chatbot test

* Give access to secrets

.github/workflows/tests.yaml CHANGED
@@ -5,6 +5,7 @@ on: [push, pull_request]
5
  jobs:
6
  tests:
7
  runs-on: ubuntu-latest
 
8
  steps:
9
  - name: Check out repository code
10
  uses: actions/checkout@v3
@@ -17,6 +18,8 @@ jobs:
17
  pip install isort
18
  isort --profile black --check-only .
19
  - name: unit tests
 
 
20
  run: |
21
  python3 -m pip install --upgrade pip
22
  pip install -e .
5
  jobs:
6
  tests:
7
  runs-on: ubuntu-latest
8
+ environment: secrets
9
  steps:
10
  - name: Check out repository code
11
  uses: actions/checkout@v3
18
  pip install isort
19
  isort --profile black --check-only .
20
  - name: unit tests
21
+ env:
22
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
23
  run: |
24
  python3 -m pip install --upgrade pip
25
  pip install -e .
tests/data/document_embeddings_huggingface_subset.tar.gz ADDED
Binary file (129 kB). View file
tests/test_chatbot.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path
3
+
4
+ from buster.chatbot import Chatbot, ChatbotConfig
5
+
6
+ TEST_DATA_DIR = Path(__file__).resolve().parent / "data"
7
+ DOCUMENTS_FILE = os.path.join(str(TEST_DATA_DIR), "document_embeddings_huggingface_subset.tar.gz")
8
+
9
+
10
+ def test_chatbot_simple():
11
+ hf_transformers_cfg = ChatbotConfig(
12
+ documents_file=DOCUMENTS_FILE,
13
+ unknown_prompt="This doesn't seem to be related to the huggingface library. I am not sure how to answer.",
14
+ embedding_model="text-embedding-ada-002",
15
+ top_k=3,
16
+ thresh=0.7,
17
+ max_words=3000,
18
+ completion_kwargs={
19
+ "temperature": 0,
20
+ "engine": "text-davinci-003",
21
+ "max_tokens": 100,
22
+ },
23
+ response_format="slack",
24
+ text_before_prompt=(
25
+ """You are a slack chatbot assistant answering technical questions about huggingface transformers, a library to train transformers in python.\n"""
26
+ """Make sure to format your answers in Markdown format, including code block and snippets.\n"""
27
+ """Do not include any links to urls or hyperlinks in your answers.\n\n"""
28
+ """Now answer the following question:\n"""
29
+ ),
30
+ )
31
+ chatbot = Chatbot(hf_transformers_cfg)
32
+ answer = chatbot.process_input("What is a transformer?")
33
+ assert isinstance(answer, str)