Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
remove requirements
reibsd359e78420ec
diff --git a/pyproject.toml b/pyproject.tomlindex 9fb695dd..e6bc8eac 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -18,13 +18,18 @@ classifiers = ["Operating System :: OS Independent",]dependencies = [- "requests",- "pydantic"+ "requests==2.31.0",+ "pydantic==2.4.2",+ "packaging==23.1"][project.optional-dependencies]dev = [- "pytest",- "requests_mock"+ "pytest==7.4.0",+ "requests_mock==1.11.0"+]+[project.optional-dependencies]+langchain = [+ "langchain==0.0.350"][project.urls]diff --git a/requirements.txt b/requirements.txtdeleted file mode 100644index e76c4e5e..00000000--- a/requirements.txt+++ /dev/null@@ -1,6 +0,0 @@-pytest==7.4.0-requests==2.31.0-requests-mock==1.11.0-pydantic==2.4.2-packaging==23.1-langchain==0.0.350diff --git a/tests/openai_handlers/test_handler_openai_v0.py b/tests/openai_handlers/test_handler_openai_v0.pynew file mode 100644index 00000000..c1ed32fa--- /dev/null+++ b/tests/openai_handlers/test_handler_openai_v0.py@@ -0,0 +1,64 @@++import openai+import agentops+import asyncio+import os++print('Running OpenAI <v1.0.0')+++ao_client = agentops.Client(tags=['mock tests'])++openai.api_key = os.environ['OPENAI_API_KEY']+++async def stream_achat():+ message = [{"role": "user", "content": "stream achat test"}]++ res = await openai.ChatCompletion.acreate(+ model='gpt-3.5-turbo', messages=message, temperature=0.5, stream=True)+ async for r in res:+ print(r)+ print('*'*100)+++def stream_chat():+ message = [{"role": "user", "content": "stream chat test"}]+ res = openai.ChatCompletion.create(+ model='gpt-3.5-turbo', messages=message, temperature=0.5, stream=True)+ for r in res:+ print(r)+ print('*'*100)+++async def achat():+ message = [{"role": "user", "content": "achat test"}]+ res = await openai.ChatCompletion.acreate(+ model='gpt-3.5-turbo', messages=message, temperature=0.5)+ print(res)++ print('*'*100)+++def chat():+ message = [{"role": "user", "content": "chat test"}]+ res = openai.ChatCompletion.create(+ model='gpt-3.5-turbo', messages=message, temperature=0.5)+ print(res)++ print('*'*100)+++print('running async stream')+asyncio.run(stream_achat())++print('running sync stream')+stream_chat()++print('running async chat')+asyncio.run(achat())++print('running sync chat')+chat()++ao_client.end_session('Success')diff --git a/tests/openai_handlers/test_handler_openai_v1.py b/tests/openai_handlers/test_handler_openai_v1.pynew file mode 100644index 00000000..39c3212f--- /dev/null+++ b/tests/openai_handlers/test_handler_openai_v1.py@@ -0,0 +1,97 @@+import time+from openai.resources.chat import completions+import openai+from openai import OpenAI, AsyncOpenAI+import agentops+import asyncio+from dotenv import load_dotenv+load_dotenv()+client = OpenAI()+++async_client = AsyncOpenAI()+++print('Running OpenAI v1.0.0+')+++# Assuming that instantiating agentops.Client will trigger the LlmTracker to override methods+ao_client = agentops.Client(tags=['mock agent'])+++# Now the client.chat.completions.create should be the overridden method+print('Chat completion')+chat_completion = client.chat.completions.create(+ messages=[+ {+ "role": "user",+ "content": "Say this is a test",+ }+ ],+ model="gpt-3.5-turbo",+)++# test streaming+print('Chat completion streaming')+chat_completion = client.chat.completions.create(+ messages=[+ {+ "role": "user",+ "content": "Say this is a test",+ }+ ],+ model="gpt-3.5-turbo",+ stream=True+)+start_time = time.time()++collected_chunks = []+collected_messages = []++print(chat_completion)++for chunk in chat_completion:+ chunk_time = time.time() - start_time # calculate the time delay of the chunk+ collected_chunks.append(chunk) # save the event response+ chunk_message = chunk.choices[0].delta.content # extract the message+ collected_messages.append(chunk_message) # save the message+ # print the delay and text+ print(+ f"Message received {chunk_time:.2f} seconds after request: {chunk_message}")+++# # Test the async version of client.chat.completions.create++async def test_async_chat_completion():+ return await async_client.chat.completions.create(+ messages=[+ {+ "role": "user",+ "content": "Say this is an async test",+ }+ ],+ model="gpt-3.5-turbo",+ )+++async def test_async_chat_completion_stream():+ chat_completion_stream = await async_client.chat.completions.create(+ messages=[+ {+ "role": "user",+ "content": "Say this is an async test",+ }+ ],+ model="gpt-3.5-turbo",+ stream=True+ )+ async for chunk in chat_completion_stream:+ print(chunk)+++print('Running async tests')+asyncio.run(test_async_chat_completion())+print('Running async streaming test')+asyncio.run(test_async_chat_completion_stream())++ao_client.end_session('Success')