add k8s demo for api server

This commit is contained in:
Adil Hafeez 2025-02-20 12:07:22 -08:00
parent 1bbc5d2233
commit 7a7288314a
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
4 changed files with 166 additions and 0 deletions

View file

@ -0,0 +1,26 @@
This demo shows how you can use a publicly hosted rest api and interact it using arch gateway.
# How to run this demo.
Before staring make sure you have completed the pre-requisites [here](https://github.com/katanemo/archgw?tab=readme-ov-file#prerequisites)
In separate window start 1) model server, 2) arch gateway 3) docker container for UI and for debugging 4) tail access logs
1. start model server
```
archgw up --service model_server --foreground
```
1. start arch gateway
```
archgw up --service archgw --foreground
```
1. start docker container for ui
```
docker compose up
```
1. tail access logs
```
tail -F ~/archgw_logs/access_*
```

View file

@ -0,0 +1,72 @@
version: v0.1
listeners:
ingress_traffic:
address: 0.0.0.0
port: 10000
message_format: openai
timeout: 30s
overrides:
optimize_context_window: true
llm_providers:
- name: gpt-4o
access_key: $OPENAI_API_KEY
provider_interface: openai
model: gpt-4o
endpoints:
k8s_api_gateway:
endpoint: host.docker.internal:8001
http_host: localhost
system_prompt: |
You are a helpful assistant.
prompt_guards:
input_guards:
jailbreak:
on_exception:
message: Looks like you're curious about my abilities, but I can only provide assistance for currency exchange.
prompt_targets:
- name: list_namespaces
description: List all namespaces in the cluster
endpoint:
name: k8s_api_gateway
path: /api/v1/namespaces
system_prompt: |
You are a helpful k8s assistant. Show status of each namespace as well in each line.
- name: show_namespace_details
description: Show details of a specific namespace
endpoint:
name: k8s_api_gateway
path: /api/v1/namespaces/{namespace}
parameters:
- name: namespace
description: namespace to show details
required: true
type: str
in_path: true
system_prompt: |
You are a helpful k8s assistant. Please show high level details of the namespace.
- name: get_pods_for_namespace
description: Get all pods in a specific namespace
endpoint:
name: k8s_api_gateway
path: /api/v1/namespaces/{namespace}/pods
parameters:
- name: namespace
description: namespace to show details
required: true
type: str
in_path: true
system_prompt: |
You are a helpful k8s assistant. Please only show high level details of each pod.
tracing:
random_sampling: 100
trace_arch_internal: true

View file

@ -0,0 +1,21 @@
services:
chatbot_ui:
build:
context: ../../shared/chatbot_ui
ports:
- "18080:8080"
environment:
# this is only because we are running the sample app in the same docker container environemtn as archgw
- CHAT_COMPLETION_ENDPOINT=http://host.docker.internal:10000/v1
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ./arch_config.yaml:/app/arch_config.yaml
jaeger:
build:
context: ../../shared/jaeger
ports:
- "16686:16686"
- "4317:4317"
- "4318:4318"

View file

@ -0,0 +1,47 @@
#!/bin/bash
set -e
# Function to start the demo
start_demo() {
# Step 1: Check if .env file exists
if [ -f ".env" ]; then
echo ".env file already exists. Skipping creation."
else
# Step 2: Create `.env` file and set OpenAI key
if [ -z "$OPENAI_API_KEY" ]; then
echo "Error: OPENAI_API_KEY environment variable is not set for the demo."
exit 1
fi
echo "Creating .env file..."
echo "OPENAI_API_KEY=$OPENAI_API_KEY" > .env
echo ".env file created with OPENAI_API_KEY."
fi
# Step 3: Start Arch
echo "Starting Arch with arch_config.yaml..."
archgw up arch_config.yaml
# Step 4: Start developer services
echo "Starting Agent using Docker Compose..."
docker compose up -d # Run in detached mode
}
# Function to stop the demo
stop_demo() {
# Step 1: Stop Docker Compose services
echo "Stopping Agent using Docker Compose..."
docker compose down
# Step 2: Stop Arch
echo "Stopping Arch..."
archgw down
}
# Main script logic
if [ "$1" == "down" ]; then
stop_demo
else
# Default action is to bring the demo up
start_demo
fi