minor logic fix

This commit is contained in:
Zishan
2025-02-07 10:16:16 +01:00
parent 6eecb1510a
commit 87fc58e4de
3 changed files with 18 additions and 21 deletions
+1 -3
View File
@@ -38,6 +38,4 @@ To integrate the Proxy with your AI agent, youll need to modify how your clie
Coming Soon!
### Run
docker compose -f docker-compose.local.yml down
&& docker compose -f docker-compose.local.yml up -d --build
&& docker logs explorer-proxy-explorer-proxy-1 -f
./run.sh up
+15 -17
View File
@@ -89,18 +89,14 @@ async def push_to_explorer(
"""Pushes the full trace to the Invariant Explorer"""
# Combine the messages from the request body and Anthropic response
messages = request_body.get("messages", [])
if merged_response is not list:
merged_response = [merged_response]
messages += merged_response
messages += [merged_response]
# Only push the trace to explorer if the last message is an end turn message
if messages[-1].get("stop_reason") in END_REASONS:
messages = anthropic_to_invariant_messages(messages)
_ = await push_trace(
dataset_name=dataset_name,
messages=[messages],
invariant_authorization=invariant_authorization,
)
messages = anthropic_to_invariant_messages(messages)
_ = await push_trace(
dataset_name=dataset_name,
messages=[messages],
invariant_authorization=invariant_authorization,
)
async def handle_non_streaming_response(
response: httpx.Response,
@@ -110,12 +106,14 @@ async def handle_non_streaming_response(
):
"""Handles non-streaming Anthropic responses"""
json_response = response.json()
await push_to_explorer(
dataset_name,
json_response,
request_body_json,
invariant_authorization,
)
# Only push the trace to explorer if the last message is an end turn message
if json_response.get("stop_reason") in END_REASONS:
await push_to_explorer(
dataset_name,
json_response,
request_body_json,
invariant_authorization,
)
def anthropic_to_invariant_messages(
messages: list[dict], keep_empty_tool_response: bool = False
+2 -1
View File
@@ -7,10 +7,11 @@ from httpx import Client
import os
# from invariant import testing
tavily_client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
import datetime
class WeatherAgent:
def __init__(self, api_key: str):
dataset_name = "claude_weather_agent_test7"
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(