Skip to content

Commit

Permalink
Updating notebook testing workflow (#343)
Browse files Browse the repository at this point in the history
* Renaming job action and updating notebook

* Testing new notebook

* Standardizing notebooks

* More updating more testing

* More standardizing

* Updating more notebooks

* Testing all ipynb directly under examples

* Standardizing notebooks

* Updating notebooks

* adding branch to action

* typo

* Updating Action to read agentops.log for each notebook. Fixing recording-events.ipynb

* Fixing Action to save agentops.log

* Fixing Action

* iterating workflow

* Should continue executing notebooks when one fails

* Workflow now for all ipynb. Fixing lots of notebooks

* Fixing notebooks

* Adding multion key

* workflow finishing touches

* adding excluded notebooks

* Fixed job_posting example

* Adding markdown_validator notebook
  • Loading branch information
HowieG authored Aug 9, 2024
1 parent 1b15c77 commit c572344
Show file tree
Hide file tree
Showing 22 changed files with 2,334 additions and 1,057 deletions.
82 changes: 57 additions & 25 deletions .github/workflows/test-notebooks.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,91 @@
name: Run Notebook and Check Logs

name: Test Notebooks
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
run-notebook-and-check-logs:
test-notebooks:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8']
python-version: ['3.11']
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U jupyter
- name: Create .env file
run: |
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "AGENTOPS_API_KEY=${{ secrets.AGENTOPS_API_KEY }}" >> .env
echo "CO_API_KEY=${{ secrets.CO_API_KEY }}" >> .env
- name: Run notebook
echo "GROQ_API_KEY=${{ secrets.GROQ_API_KEY }}" >> .env
echo "MULTION_API_KEY=${{ secrets.MULTION_API_KEY }}" >> .env
echo "SERPER_API_KEY=${{ secrets.SERPER_API_KEY }}" >> .env
- name: Run notebooks and check for errors
run: |
jupyter execute examples/openai-gpt.ipynb
mkdir -p logs
exit_code=0
- name: Check for errors and warnings
run: |
if [ -f agentops.log ]; then
if grep -E "ERROR|WARNING" agentops.log; then
echo "Errors or warnings found in agentops.log for Python ${{ matrix.python-version }}"
exit 1
exclude_notebooks=(
"./examples/crew/job_posting.ipynb"
)
for notebook in $(find . -name '*.ipynb'); do
skip=false
for excluded in "${exclude_notebooks[@]}"; do
if [[ "$notebook" == "$excluded" ]]; then
skip=true
echo "Skipping excluded notebook: $notebook"
break
fi
done
$skip && continue
notebook_name=$(basename "$notebook" .ipynb)
notebook_path=$(realpath "$notebook")
notebook_dir=$(dirname "$notebook_path")
# Run the notebook
jupyter execute "$notebook_path" || true
# Check if agentops.log was created
if [ -f "${notebook_dir}/agentops.log" ]; then
dest_log="logs/agentops-${notebook_name}.log"
mv "${notebook_dir}/agentops.log" "$dest_log"
# Check agentops log for errors or warnings
if grep -E "ERROR|WARNING" "$dest_log"; then
echo "Errors or warnings found in $dest_log for Python ${{ matrix.python-version }}"
exit_code=1
else
echo "No errors or warnings found in $dest_log for Python ${{ matrix.python-version }}"
fi
else
echo "No errors or warnings found in agentops.log for Python ${{ matrix.python-version }}"
echo "No agentops.log generated for $notebook_name"
fi
else
echo "agentops.log file not found. Assuming successful execution without logging."
done
# Check if any logs were found
if [ $(find logs -name 'agentops-*.log' | wc -l) -eq 0 ]; then
echo "No agentops.log files were generated for any notebook"
fi
- name: Upload log as artifact (if exists)
exit $exit_code
- name: Upload logs as artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: agentops-log-${{ matrix.python-version }}
path: agentops.log
if-no-files-found: ignore
name: notebook-logs-${{ matrix.python-version }}
path: logs/agentops-*.log
if-no-files-found: warn
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ <h1>Step Stream</h1>
<div class="sourceCode" id="cb4"><pre
class="sourceCode python"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> os</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>os.environ[<span class="st">&quot;MULTION_API_KEY&quot;</span>] <span class="op">=</span> <span class="st">&quot;e8cbbd0f8fa042f49f267a44bf97425c&quot;</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>os.environ[<span class="st">&quot;AGENTOPS_API_KEY&quot;</span>] <span class="op">=</span> <span class="st">&quot;a640373b-30ae-4655-a1f3-5caa882a8721&quot;</span></span></code></pre></div>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>os.environ[<span class="st">&quot;MULTION_API_KEY&quot;</span>] <span class="op">=</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>os.environ[<span class="st">&quot;AGENTOPS_API_KEY&quot;</span>] <span class="op">=</span></span></code></pre></div>
</div>
<div class="cell code" data-scrolled="true">
<div class="sourceCode" id="cb5"><pre
Expand Down
176 changes: 72 additions & 104 deletions examples/autogen/AgentChat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,76 @@
"AgentOps automatically configures itself when it's initialized meaning your agent run data will be tracked and logged to your AgentOps account right away."
]
},
{
"cell_type": "markdown",
"id": "87626697",
"metadata": {},
"source": [
"First let's install the required packages"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d93f2339-7b99-4cf1-9232-c24faba49c7b",
"execution_count": null,
"id": "9599cf93",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=24c5d9f6-fb82-41e6-a468-2dc74a5318a3\u001b[0m\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AgentOps is now running. You can view your session in the link above\n"
]
}
],
"outputs": [],
"source": [
"%pip install -U pyautogen\n",
"%pip install -U agentops\n",
"%pip install -U python-dotenv"
]
},
{
"cell_type": "markdown",
"id": "3506f401",
"metadata": {},
"source": [
"Then import them"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b5c8b7b",
"metadata": {},
"outputs": [],
"source": [
"import agentops\n",
"\n",
"from autogen import ConversableAgent, UserProxyAgent\n",
"\n",
"import agentops\n",
"import os\n",
"from dotenv import load_dotenv"
]
},
{
"cell_type": "markdown",
"id": "70b502a2",
"metadata": {},
"source": [
"Next, we'll grab our API keys. You can use dotenv like below or however else you like to load environment variables"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ae4152d",
"metadata": {},
"outputs": [],
"source": [
"load_dotenv()\n",
"OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\") or \"<your_openai_key>\"\n",
"AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"<your_agentops_key>\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d93f2339-7b99-4cf1-9232-c24faba49c7b",
"metadata": {},
"outputs": [],
"source": [
"# When initializing AgentOps, you can pass in optional tags to help filter sessions\n",
"agentops.init(api_key=\"...\", tags=[\"simple-autogen-example\"])\n",
"agentops.init(AGENTOPS_API_KEY, default_tags=[\"simple-autogen-example\"])\n",
"\n",
"print(\"AgentOps is now running. You can view your session in the link above\")"
]
Expand All @@ -63,103 +105,37 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"id": "2962d990-f7ef-43d8-ba09-d29bd8356d9f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33magent\u001b[0m (to user):\n",
"\n",
"How can I help you today?\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Provide feedback to agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: Tell me a joke about AgentOps\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33muser\u001b[0m (to agent):\n",
"\n",
"Tell me a joke about AgentOps\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33magent\u001b[0m (to user):\n",
"\n",
"Why don't AgentOps teams ever play hide and seek?\n",
"\n",
"Because good luck hiding when they always know where everyone is supposed to be!\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Provide feedback to agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: Another\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33muser\u001b[0m (to agent):\n",
"\n",
"Another\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33magent\u001b[0m (to user):\n",
"\n",
"Why did the AgentOps team bring a ladder to work?\n",
"\n",
"Because they’re always reaching for high-level optimizations!\n",
"It seems there might still be an issue. If you need assistance or have questions later on, don't hesitate to reach out. I'm here to help whenever you're ready!\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Provide feedback to agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: exit\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"🖇 AgentOps: This run's cost $0.001080\n",
"🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=24c5d9f6-fb82-41e6-a468-2dc74a5318a3\u001b[0m\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success! Visit your AgentOps dashboard to see the replay\n"
]
}
],
"source": [
"# Define an openai api key for the agent configurations\n",
"openai_api_key = \"...\"\n",
"# Define model, openai api key, tags, etc in the agent configuration\n",
"config_list = [\n",
" {\"model\": \"gpt-4-turbo\", \"api_key\": openai_api_key, \"tags\": [\"gpt-4\", \"tool\"]}\n",
" {\"model\": \"gpt-4-turbo\", \"api_key\": OPENAI_API_KEY, \"tags\": [\"gpt-4\", \"tool\"]}\n",
"]\n",
"\n",
"# Create the agent that uses the LLM.\n",
Expand All @@ -185,14 +161,6 @@
"\n",
"The dashboard will display LLM events for each message sent by each agent, including those made by the human user."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72993a75-1031-4874-aa26-0ef816a3256c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -211,7 +179,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit c572344

Please sign in to comment.