Skip to content

Commit

Permalink
Fixed anthropic example automation
Browse files Browse the repository at this point in the history
  • Loading branch information
HowieG committed Sep 4, 2024
1 parent a6e9ded commit 148b780
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ jobs:
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 "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "ANTHROPIC_API_KEY=${{ secrets.ANTHROPIC_API_KEY }}" >> .env
echo "CO_API_KEY=${{ secrets.CO_API_KEY }}" >> .env
echo "GROQ_API_KEY=${{ secrets.GROQ_API_KEY }}" >> .env
echo "MULTION_API_KEY=${{ secrets.MULTION_API_KEY }}" >> .env
Expand Down
165 changes: 147 additions & 18 deletions examples/anthropic/anthropic_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,58 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: anthropic in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (0.34.2)\n",
"Requirement already satisfied: anyio<5,>=3.5.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (4.4.0)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (1.9.0)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (0.27.0)\n",
"Requirement already satisfied: jiter<1,>=0.4.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (0.5.0)\n",
"Requirement already satisfied: pydantic<3,>=1.9.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (2.8.2)\n",
"Requirement already satisfied: sniffio in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (1.3.1)\n",
"Requirement already satisfied: tokenizers>=0.13.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (0.20.0)\n",
"Requirement already satisfied: typing-extensions<5,>=4.7 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anthropic) (4.12.2)\n",
"Requirement already satisfied: idna>=2.8 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from anyio<5,>=3.5.0->anthropic) (3.7)\n",
"Requirement already satisfied: certifi in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from httpx<1,>=0.23.0->anthropic) (2024.7.4)\n",
"Requirement already satisfied: httpcore==1.* in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from httpx<1,>=0.23.0->anthropic) (1.0.5)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->anthropic) (0.14.0)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->anthropic) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.20.1 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->anthropic) (2.20.1)\n",
"Requirement already satisfied: huggingface-hub<1.0,>=0.16.4 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from tokenizers>=0.13.0->anthropic) (0.24.6)\n",
"Requirement already satisfied: filelock in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (3.15.4)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2024.9.0)\n",
"Requirement already satisfied: packaging>=20.9 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (23.2)\n",
"Requirement already satisfied: pyyaml>=5.1 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (6.0.1)\n",
"Requirement already satisfied: requests in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2.31.0)\n",
"Requirement already satisfied: tqdm>=4.42.1 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (4.66.5)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from requests->huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (3.3.2)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from requests->huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2.2.2)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"Requirement already satisfied: agentops in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (0.3.10)\n",
"Requirement already satisfied: requests==2.31.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from agentops) (2.31.0)\n",
"Requirement already satisfied: psutil==5.9.8 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from agentops) (5.9.8)\n",
"Requirement already satisfied: packaging==23.2 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from agentops) (23.2)\n",
"Requirement already satisfied: termcolor==2.4.0 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from agentops) (2.4.0)\n",
"Requirement already satisfied: PyYAML==6.0.1 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from agentops) (6.0.1)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from requests==2.31.0->agentops) (3.3.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from requests==2.31.0->agentops) (3.7)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from requests==2.31.0->agentops) (2.2.2)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /Users/howardgil/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages (from requests==2.31.0->agentops) (2024.7.4)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install -U anthropic\n",
"%pip install -U agentops"
Expand All @@ -33,7 +82,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -52,7 +101,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -63,9 +112,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=9b32cad5-1899-4cd8-bb3a-11edc0888132\u001b[0m\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"<agentops.session.Session at 0x1053864b0>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"agentops.init(AGENTOPS_API_KEY, default_tags=[\"anthropic-example\"])"
]
Expand All @@ -80,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -89,17 +156,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2+2 = 4\n",
"\n",
"This is one of the most basic addition problems. It's often used as an example when teaching young children basic arithmetic.\n"
]
}
],
"source": [
"stream = client.messages.create(\n",
" max_tokens=1024,\n",
" model=\"claude-3-5-sonnet-20240620\",\n",
" messages=[\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"What is 2+2?\",\n",
" \"content\": \"How much wood could a wood chuck chuck if a wood chuck could chuck wood?\",\n",
" }\n",
" ],\n",
" stream=True,\n",
Expand All @@ -123,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -132,9 +209,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I apologize, but there seems to be some confusion here. There isn't a single, widely recognized equation in mathematics or physics known specifically as \"the Leibniz Equation.\" Gottfried Wilhelm Leibniz was a prominent mathematician and philosopher who made significant contributions to various fields, including calculus, but there isn't one equation that bears his name exclusively.\n",
"\n",
"However, Leibniz is associated with several important mathematical concepts and notations. Here are some key areas where Leibniz made significant contributions:\n",
"\n",
"1. Differential and Integral Calculus:\n",
" Leibniz developed notation for calculus that is still widely used today. For example:\n",
" - dy/dx for the derivative\n",
" - ∫ for the integral sign\n",
"\n",
"2. Leibniz's Rule:\n",
" This rule is used for differentiating under the integral sign. It's sometimes called the \"Leibniz integral rule.\"\n",
"\n",
"3. Leibniz Formula for π:\n",
" A series representation of π/4 = 1 - 1/3 + 1/5 - 1/7 + ...\n",
"\n",
"4. Product Rule:\n",
" While not exclusively attributed to Leibniz, he contributed to the development of the product rule in calculus.\n",
"\n",
"5. Chain Rule:\n",
" Again, while not solely his work, Leibniz contributed to the development of the chain rule.\n",
"\n",
"6. Leibniz's Notation for Differentials:\n",
" d(xy) = xdy + ydx\n",
"\n",
"7. Principle of Sufficient Reason:\n",
" While this is more of a philosophical principle than an equation, it states that for every fact, there must be an explanation of why it is so and not otherwise.\n",
"\n",
"If you're referring to a specific equation or concept related to Leibniz, it would be helpful to provide more context or details about the particular area of study or application you're interested in. This would allow for a more accurate and targeted explanation.\n"
]
}
],
"source": [
"async def main() -> None:\n",
" message = await aclient.messages.create(\n",
Expand Down Expand Up @@ -163,9 +275,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"stream = client.messages.create(\n",
" max_tokens=1024,\n",
Expand Down Expand Up @@ -203,9 +323,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"🖇 AgentOps: This run's cost $0.00\n",
"🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=9b32cad5-1899-4cd8-bb3a-11edc0888132\u001b[0m\u001b[0m\n"
]
}
],
"source": [
"agentops.end_session(\"Success\")"
]
Expand All @@ -227,7 +356,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.19"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 148b780

Please sign in to comment.