mirror of
https://github.com/invariantlabs-ai/invariant-gateway.git
synced 2026-07-07 11:27:50 +02:00
Merge branch 'main' into anthropic-implement
This commit is contained in:
@@ -1 +1,11 @@
|
||||
INVARIANT_API_URL=https://explorer.invariantlabs.ai
|
||||
INVARIANT_API_URL=https://explorer.invariantlabs.ai
|
||||
|
||||
# For the testing stack only
|
||||
# TODO: Check if these can be removed.
|
||||
# Currently we rely on the `invariant explorer` command
|
||||
# to setup a local instance of explorer to test the proxy.
|
||||
# That requires these variables to be set in the .env file.
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=postgres
|
||||
POSTGRES_DB=invariantmonitor
|
||||
POSTGRES_HOST=database
|
||||
@@ -2,6 +2,7 @@
|
||||
__pycache__/
|
||||
.pytest_cache/
|
||||
.py[oc]
|
||||
data/
|
||||
|
||||
# Coverage and build artifacts
|
||||
.coverage
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
# **Explorer Proxy**
|
||||
# **Invariant Proxy**
|
||||
|
||||
Explorer Proxy is a lightweight Docker service that acts as an intermediary between AI Agents and LLM providers (such as OpenAI and Anthropic). It captures and forwards agent interactions to the [Invariant Explorer](https://explorer.invariantlabs.ai/), enabling seamless visualization and exploration of traces.
|
||||
Invariant Proxy is a lightweight Docker service that acts as an intermediary between AI Agents and LLM providers (such as OpenAI and Anthropic). It captures and forwards agent interactions to the [Invariant Explorer](https://explorer.invariantlabs.ai/), enabling seamless debugging, visualization and exploration of traces.
|
||||
|
||||
## **Why Use Explorer Proxy?**
|
||||

|
||||
|
||||
## **Why Use Invariant Proxy?**
|
||||
- ✅ **Intercept AI interactions** for better debugging and analysis.
|
||||
- ✅ **Seamlessly forward API requests** to OpenAI, Anthropic, and other LLM providers.
|
||||
- ✅ **Automatically store and organize traces** in Invariant Explorer.
|
||||
- ✅ **Seamlessly forward API requests** to OpenAI, Anthropic, and other LLM providers (**supports streaming responses too**).
|
||||
- ✅ **Automatically store and organize traces** in the Invariant Explorer.
|
||||
|
||||
## **Getting Started**
|
||||
To integrate Explorer Proxy with your AI agent, you’ll need to modify how your client interacts with LLM providers.
|
||||
To integrate the Proxy with your AI agent, you’ll need to modify how your client interacts with LLM providers.
|
||||
|
||||
### **🔹 OpenAI Integration**
|
||||
1. **Get an API Key**
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
@@ -20,6 +20,27 @@ down() {
|
||||
docker compose -f docker-compose.local.yml down
|
||||
}
|
||||
|
||||
|
||||
tests() {
|
||||
# Run tests
|
||||
pip install invariant-ai
|
||||
invariant explorer up -d --build
|
||||
|
||||
until curl -X GET -I http://127.0.0.1/api/v1 --fail --silent --output /dev/null; do
|
||||
echo "Backend API not available yet - checking health..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Backend API is available. Running tests..."
|
||||
|
||||
docker build -t 'explorer-proxy-test' -f ./tests/Dockerfile.test ./tests
|
||||
|
||||
docker run \
|
||||
--mount type=bind,source=./tests,target=/tests \
|
||||
--network host \
|
||||
explorer-proxy-test $@
|
||||
}
|
||||
|
||||
# -----------------------------
|
||||
# Command dispatcher
|
||||
# -----------------------------
|
||||
@@ -36,4 +57,12 @@ case "$1" in
|
||||
"logs")
|
||||
docker compose -f docker-compose.local.yml logs -f
|
||||
;;
|
||||
"tests")
|
||||
shift
|
||||
tests $@
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [up|build|down|logs|tests]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,8 @@
|
||||
FROM mcr.microsoft.com/playwright/python:v1.50.0-noble
|
||||
|
||||
RUN mkdir -p /tests
|
||||
COPY ./requirements.txt /tests/requirements.txt
|
||||
WORKDIR /tests
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
ENTRYPOINT ["pytest", "-s", "-vv"]
|
||||
@@ -0,0 +1,22 @@
|
||||
"""Test the chat completions proxy calls without tool calling."""
|
||||
|
||||
import os
|
||||
|
||||
# add tests folder (parent) to sys.path
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from util import * # needed for pytest fixtures
|
||||
|
||||
pytest_plugins = ("pytest_asyncio",)
|
||||
|
||||
|
||||
async def test_hello_world(context, url):
|
||||
"""Demo test"""
|
||||
response = await context.request.get(
|
||||
f"{url}/api/v1/dataset/byuser/developer/Welcome-to-Explorer"
|
||||
)
|
||||
dataset = await response.json()
|
||||
assert dataset["name"] == "Welcome-to-Explorer"
|
||||
assert dataset["user"]["username"] == "developer"
|
||||
@@ -0,0 +1,2 @@
|
||||
[pytest]
|
||||
asyncio_mode = auto
|
||||
@@ -0,0 +1,4 @@
|
||||
openai
|
||||
pytest
|
||||
pytest-asyncio
|
||||
pytest-playwright
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Util functions for tests"""
|
||||
|
||||
import pytest
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def url():
|
||||
return "http://127.0.0.1"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def playwright(scope="session"):
|
||||
async with async_playwright() as playwright_instance:
|
||||
yield playwright_instance
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def browser(playwright, scope="session"):
|
||||
browser = await playwright.firefox.launch(headless=True)
|
||||
yield browser
|
||||
await browser.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def context(browser):
|
||||
context = await browser.new_context(ignore_https_errors=True)
|
||||
yield context
|
||||
await context.close()
|
||||
Reference in New Issue
Block a user