Skip to content

Commit e00acdd

Browse files
Added test-on-pr.yml to run tests when a PR targets main branch (#63)
* Version bump to 10.5 * Added yml file to automatically run tests when a PR is opened, synchronized (updated), or reopened that targets the branch * Updated pip install packages * pip install . * Uncommenting API Key env var * Ignoring obsolete and low level tests * Added descriptive logging to tests * Debugging yml file and requirements modified for streamlit chatbot example * Adjusted streamlit chatbot to be compatible with IA2
1 parent d30b25a commit e00acdd

File tree

3 files changed

+63
-13
lines changed

3 files changed

+63
-13
lines changed

.github/workflows/test-on-pr.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test on Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install .
25+
pip install pytest
26+
27+
- name: Debug env var
28+
env:
29+
AIMON_API_KEY: ${{ secrets.AIMON_API_KEY }}
30+
run: |
31+
echo "API KEY LENGTH: ${#AIMON_API_KEY}"
32+
33+
- name: Run tests
34+
env:
35+
AIMON_API_KEY: ${{ secrets.AIMON_API_KEY }}
36+
run: |
37+
38+
## Run only two test files
39+
# pytest tests/test_detect.py tests/test_evaluate.py
40+
41+
## Ignore some files and run without descriptive logging
42+
# pytest tests/ --ignore=tests/obsolete/ --ignore=tests/test_low_level_api.py -v
43+
44+
## Ignore some files and run with descriptive logging
45+
pytest tests/ --ignore=tests/obsolete/ --ignore=tests/test_low_level_api.py -v --log-cli-level=INFO

examples/streamlit_apps/chatbot/aimon_chatbot_demo.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def load_data():
4343
system_prompt="""You are an expert on
4444
answering questions on Essays and your
4545
job is to answer questions related to this domain. Your answers should be based on
46-
facts do not hallucinate features.""",
46+
facts - do not hallucinate features.""",
4747
)
4848
logging.info("Finished creating OpenAI LLM...")
4949
Settings.chunk_size = 256
@@ -107,10 +107,12 @@ def execute():
107107
openai_api_key = os.getenv("OPENAI_API_KEY")
108108

109109
openai.api_key = openai_api_key
110-
instructions = st.text_input(
111-
"Instructions for the chatbot. Ex: Answer the user's question in a professional tone.",
112-
value="Answer the user's question in a professional tone."
110+
raw_instructions = st.text_input(
111+
"Instructions for the chatbot (comma-separated). Ex: Answer professionally, Be concise",
112+
value="Answer professionally, Be concise"
113113
)
114+
instructions = [instr.strip() for instr in raw_instructions.split(',') if instr.strip()]
115+
114116
st.title("Ask questions on Paul Graham's Work Experience")
115117

116118
if "messages" not in st.session_state.keys(): # Initialize the chat messages history
@@ -125,16 +127,19 @@ def execute():
125127
memory = ChatMemoryBuffer.from_defaults(token_limit=1200)
126128

127129
if "chat_engine" not in st.session_state.keys(): # Initialize the chat engine
130+
formatted_instructions = "; ".join(instructions) if instructions else "Respond helpfully."
131+
132+
context_prompt = (
133+
"You are a chatbot, able to answer questions on an essay about Paul Graham's Work experience. "
134+
"Here are the relevant documents for the context:\n"
135+
"{context_str}\n\n"
136+
f"Instruction: Use the previous chat history, or the context above, to interact and help the user. {formatted_instructions}"
137+
)
138+
128139
st.session_state.chat_engine = index.as_chat_engine(
129140
chat_mode="condense_plus_context",
130141
memory=memory,
131-
context_prompt=(
132-
"You are a chatbot, able to answer questions on an essay about Paul Graham's Work experience."
133-
"Here are the relevant documents for the context:\n"
134-
"{context_str}"
135-
"\nInstruction: Use the previous chat history, or the context above, to interact and help the user. " +
136-
"{}".format(instructions if instructions else "")
137-
),
142+
context_prompt=context_prompt,
138143
verbose=False,
139144
similarity_top_k=4,
140145
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
llama-index
22
llama-index-readers-web
33
streamlit
4-
aimon>=0.5.0
5-
4+
aimon>=0.10.0
5+
httpx<0.28.1

0 commit comments

Comments
 (0)