add anthropic api key and remove tavily use

This commit is contained in:
Zishan
2025-02-12 14:40:57 +01:00
parent 89da7aadab
commit 86895c61ce
5 changed files with 16 additions and 17 deletions
+1
View File
@@ -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
-1
View File
@@ -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()
+1
View File
@@ -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 $@
}
@@ -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"))
+11 -15
View File
@@ -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 <some-api-key>"},
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 youre 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