refactor demos (#398)

This commit is contained in:
Salman Paracha 2025-02-07 18:45:42 -08:00 committed by GitHub
parent 2bd61d628c
commit b3c95a6698
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
93 changed files with 338 additions and 1042 deletions

View file

@ -0,0 +1,19 @@
FROM python:3.12 AS base
FROM base AS builder
WORKDIR /src
COPY requirements.txt /src/
RUN pip install --prefix=/runtime --force-reinstall -r requirements.txt
COPY . /src
FROM python:3.12-slim AS output
COPY --from=builder /runtime /usr/local
COPY . /app
WORKDIR /app
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80", "--log-level", "info"]

View file

@ -0,0 +1,22 @@
# Multi-Turn Agentic Demo (RAG)
This demo showcases how the **Arch** can be used to build accurate multi-turn RAG agent by just writing simple APIs.
![Example of Multi-turn Interaction](mutli-turn-example.png)
### Energy Source Q/A
Provides information about various energy sources and considerations.
- **Endpoint**: `/agent/energy_source`
- **Parameters**:
- `energy_source` (`str`, **required**): A source of energy (e.g., `renewable`, `fossil`).
- `consideration` (`str`, *optional*): A specific type of consideration for an energy source (e.g., `cost`, `economic`, `technology`).
# Starting the demo
1. Please make sure the [pre-requisites](https://github.com/katanemo/arch/?tab=readme-ov-file#prerequisites) are installed correctly
2. Start Arch
```sh
sh run_demo.sh
```
3. Navigate to http://localhost:18080
4. Ask "give me information about renewable energy sources"

View file

@ -0,0 +1,59 @@
version: v0.1
listener:
address: 127.0.0.1
port: 10000
message_format: huggingface
connect_timeout: 0.005s
endpoints:
rag_energy_source_agent:
endpoint: host.docker.internal:18083
connect_timeout: 0.005s
llm_providers:
- name: gpt-4o-mini
access_key: $OPENAI_API_KEY
provider_interface: openai
model: gpt-4o-mini
default: true
system_prompt: |
You are a helpful assistant and can offer information about energy sources.
You will get a JSON object with energy_source and consideration fields. Focus on answering the querstion using those fields.
Keep your responses to just three main points to make it easy for the reader to digest the information
prompt_targets:
- name: get_info_for_energy_source
description: get information about an energy source
parameters:
- name: energy_source
type: str
description: a source of energy
required: true
enum: [renewable, fossil]
- name: consideration
type: str
description: a specific type of consideration for an energy source
enum: [cost, economic, technology]
endpoint:
name: rag_energy_source_agent
path: /agent/energy_source_info
http_method: POST
- name: default_target
default: true
description: This is the default target for all unmatched prompts.
endpoint:
name: rag_energy_source_agent
path: /default_target
http_method: POST
system_prompt: |
You are a helpful assistant! Summarize the user's request and provide a helpful response.
# if it is set to false arch will send response that it received from this prompt target to the user
# if true arch will forward the response to the default LLM
auto_llm_dispatch_on_response: false
tracing:
random_sampling: 100
trace_arch_internal: true

View file

@ -0,0 +1,24 @@
services:
rag_energy_source_agent:
build:
context: .
dockerfile: Dockerfile
ports:
- "18083:80"
healthcheck:
test: ["CMD", "curl" ,"http://localhost:80/healthz"]
interval: 5s
retries: 20
chatbot_ui:
build:
context: ../../shared/chatbot_ui
dockerfile: Dockerfile
ports:
- "18080:8080"
environment:
- CHAT_COMPLETION_ENDPOINT=http://host.docker.internal:10000/v1
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ./arch_config.yaml:/app/arch_config.yaml

View file

@ -0,0 +1,42 @@
import os
import gradio as gr
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Optional
from openai import OpenAI
app = FastAPI()
# Define the request model
class EnergySourceRequest(BaseModel):
energy_source: str
consideration: Optional[str] = None
class EnergySourceResponse(BaseModel):
energy_source: str
consideration: Optional[str] = None
# Post method for device summary
@app.post("/agent/energy_source_info")
def get_workforce(request: EnergySourceRequest):
"""
Endpoint to get details about energy source
"""
considertion = "You don't have any specific consideration. Feel free to talk in a more open ended fashion"
if request.consideration is not None:
considertion = f"Add specific focus on the following consideration when you summarize the content for the energy source: {request.consideration}"
response = {
"energy_source": request.energy_source,
"consideration": considertion,
}
return response
if __name__ == "__main__":
app.run(debug=True)

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 KiB

View file

@ -0,0 +1,12 @@
fastapi
uvicorn
typing
pandas
gradio==5.3.0
async_timeout==4.0.3
loguru==0.7.2
asyncio==3.4.3
httpx==0.27.0
python-dotenv==1.0.1
pydantic==2.8.2
openai==1.51.0

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 Network Agent
echo "Starting HR 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 HR Agent using Docker Compose..."
docker compose down -v
# 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