diff --git a/.github/workflows/tests_ci.yml b/.github/workflows/tests_ci.yml index fa97fb5..f5c135a 100644 --- a/.github/workflows/tests_ci.yml +++ b/.github/workflows/tests_ci.yml @@ -19,4 +19,5 @@ jobs: - name: Run tests env: OPENAI_API_KEY: ${{ secrets.INVARIANT_TESTING_OPENAI_KEY }} + ANTHROPIC_API_KEY: ${{ secrets.INVARIANT_TESTING_ANTHROPIC_KEY}} run: ./run.sh tests -s -vv diff --git a/proxy/routes/anthropic.py b/proxy/routes/anthropic.py index d6c5671..a7f8173 100644 --- a/proxy/routes/anthropic.py +++ b/proxy/routes/anthropic.py @@ -6,7 +6,6 @@ import httpx from typing import Any from utils.explorer import push_trace from starlette.responses import StreamingResponse -# from .open_ai import push_to_explorer proxy = APIRouter() diff --git a/run.sh b/run.sh index 7b7a251..0815f14 100755 --- a/run.sh +++ b/run.sh @@ -68,6 +68,7 @@ tests() { --mount type=bind,source=./tests,target=/tests \ --network invariant-proxy-web-test \ -e OPENAI_API_KEY="$OPENAI_API_KEY" \ + -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" --env-file ./tests/.env.test \ explorer-proxy-test $@ } diff --git a/tests/anthropic/test_claude_agent_streaming.py b/tests/anthropic/test_claude_agent_streaming.py index 38eae7a..cc77249 100644 --- a/tests/anthropic/test_claude_agent_streaming.py +++ b/tests/anthropic/test_claude_agent_streaming.py @@ -5,7 +5,9 @@ from httpx import Client import os # from invariant import testing import datetime - +import pytest + +@pytest.mark.skipif(not os.getenv("ANTHROPIC_API_KEY"),reason="Anthropic API keys not set") def test_streaming_response_without_toolcall(): # Example queries dataset_name = "claude_streaming_agent_test" + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) diff --git a/tests/anthropic/test_claude_weather_agent.py b/tests/anthropic/test_claude_weather_agent.py index 9315225..0792636 100644 --- a/tests/anthropic/test_claude_weather_agent.py +++ b/tests/anthropic/test_claude_weather_agent.py @@ -5,24 +5,23 @@ from typing import Dict import anthropic import pytest from httpx import Client -from tavily import TavilyClient class WeatherAgent: - def __init__(self, api_key: str): - self.tavily_client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY")) + def __init__(self): dataset_name = "claude_weather_agent_test" + str( datetime.datetime.now().strftime("%Y%m%d%H%M%S") ) + invariant_api_key = os.environ.get("INVARIANT_API_KEY") self.client = anthropic.Anthropic( http_client=Client( - headers={"Invariant-Authorization": "Bearer "}, + headers={"Invariant-Authorization": f"Bearer {invariant_api_key}"}, ), base_url=f"http://localhost/api/v1/proxy/{dataset_name}/anthropic", ) self.get_weather_function = { "name": "get_weather", - "description": "Get the current weather in a given location", + "description": "Get the current weather in a given locatiofn", "input_schema": { "type": "object", "properties": { @@ -81,21 +80,17 @@ class WeatherAgent: def get_weather(self, location: str): """Get the current weather in a given location using latitude and longitude.""" - query = f"What is the weather in {location}?" - response = self.tavily_client.search(query) - response_content = response["results"][0]["content"] - return response["results"][0]["title"] + ":\n" + response_content + response = f'''Weather in {location}: + Good morning! Expect overcast skies with intermittent showers throughout the day. Temperatures will range from a cool 15°C in the early hours to around 19°C by mid-afternoon. Light winds from the northeast at about 10 km/h will keep conditions mild. It might be a good idea to carry an umbrella if you’re heading out. Stay dry and have a great day! + ''' + return response -@pytest.mark.skipif( - not os.getenv("ANTHROPIC_API_KEY") or not os.getenv("TAVILY_API_KEY"), - reason="API keys not set", -) +@pytest.mark.skipif(not os.getenv("ANTHROPIC_API_KEY"),reason="Anthropic API keys not set") def test_proxy_response(): """Test the proxy response for the weather agent.""" # Initialize agent with Anthropic API key - anthropic_api_key = os.getenv("ANTHROPIC_API_KEY") - weather_agent = WeatherAgent(anthropic_api_key) + weather_agent = WeatherAgent() # Example queries queries = [ @@ -107,5 +102,6 @@ def test_proxy_response(): # Process each query for index, query in enumerate(queries): response = weather_agent.get_response(query) + print("response:",response) assert response is not None assert cities[index] in response