diff --git a/.github/workflows/test-on-pr.yml b/.github/workflows/test-on-pr.yml new file mode 100644 index 0000000..9a72962 --- /dev/null +++ b/.github/workflows/test-on-pr.yml @@ -0,0 +1,45 @@ +name: Test on Pull Request + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + pip install pytest + + - name: Debug env var + env: + AIMON_API_KEY: ${{ secrets.AIMON_API_KEY }} + run: | + echo "API KEY LENGTH: ${#AIMON_API_KEY}" + + - name: Run tests + env: + AIMON_API_KEY: ${{ secrets.AIMON_API_KEY }} + run: | + + ## Run only two test files + # pytest tests/test_detect.py tests/test_evaluate.py + + ## Ignore some files and run without descriptive logging + # pytest tests/ --ignore=tests/obsolete/ --ignore=tests/test_low_level_api.py -v + + ## Ignore some files and run with descriptive logging + pytest tests/ --ignore=tests/obsolete/ --ignore=tests/test_low_level_api.py -v --log-cli-level=INFO diff --git a/examples/streamlit_apps/chatbot/aimon_chatbot_demo.py b/examples/streamlit_apps/chatbot/aimon_chatbot_demo.py index 8b1a6dc..e8c49a1 100644 --- a/examples/streamlit_apps/chatbot/aimon_chatbot_demo.py +++ b/examples/streamlit_apps/chatbot/aimon_chatbot_demo.py @@ -43,7 +43,7 @@ def load_data(): system_prompt="""You are an expert on answering questions on Essays and your job is to answer questions related to this domain. Your answers should be based on - facts – do not hallucinate features.""", + facts - do not hallucinate features.""", ) logging.info("Finished creating OpenAI LLM...") Settings.chunk_size = 256 @@ -107,10 +107,12 @@ def execute(): openai_api_key = os.getenv("OPENAI_API_KEY") openai.api_key = openai_api_key - instructions = st.text_input( - "Instructions for the chatbot. Ex: Answer the user's question in a professional tone.", - value="Answer the user's question in a professional tone." + raw_instructions = st.text_input( + "Instructions for the chatbot (comma-separated). Ex: Answer professionally, Be concise", + value="Answer professionally, Be concise" ) + instructions = [instr.strip() for instr in raw_instructions.split(',') if instr.strip()] + st.title("Ask questions on Paul Graham's Work Experience") if "messages" not in st.session_state.keys(): # Initialize the chat messages history @@ -125,16 +127,19 @@ def execute(): memory = ChatMemoryBuffer.from_defaults(token_limit=1200) if "chat_engine" not in st.session_state.keys(): # Initialize the chat engine + formatted_instructions = "; ".join(instructions) if instructions else "Respond helpfully." + + context_prompt = ( + "You are a chatbot, able to answer questions on an essay about Paul Graham's Work experience. " + "Here are the relevant documents for the context:\n" + "{context_str}\n\n" + f"Instruction: Use the previous chat history, or the context above, to interact and help the user. {formatted_instructions}" + ) + st.session_state.chat_engine = index.as_chat_engine( chat_mode="condense_plus_context", memory=memory, - context_prompt=( - "You are a chatbot, able to answer questions on an essay about Paul Graham's Work experience." - "Here are the relevant documents for the context:\n" - "{context_str}" - "\nInstruction: Use the previous chat history, or the context above, to interact and help the user. " + - "{}".format(instructions if instructions else "") - ), + context_prompt=context_prompt, verbose=False, similarity_top_k=4, ) diff --git a/examples/streamlit_apps/chatbot/requirements.txt b/examples/streamlit_apps/chatbot/requirements.txt index 5665f53..46d3b2c 100644 --- a/examples/streamlit_apps/chatbot/requirements.txt +++ b/examples/streamlit_apps/chatbot/requirements.txt @@ -1,5 +1,5 @@ llama-index llama-index-readers-web streamlit -aimon>=0.5.0 - +aimon>=0.10.0 +httpx<0.28.1 \ No newline at end of file