Skip to content

Commit

Permalink
fix cli models and logs (#196)
Browse files Browse the repository at this point in the history
* removing unnecessar setup.py files

* updated the cli for debug and access logs

* ran the pre-commit locally to fix pull request

* fixed bug where if archgw_process is None we didn't handle it gracefully

* Apply suggestions from code review

Co-authored-by: Adil Hafeez <[email protected]>

* fixed changes based on PR

* fixed version not found message

* fixed message based on PR feedback

* adding poetry lock

* fixed pre-commit

---------

Co-authored-by: Salman Paracha <[email protected]>
Co-authored-by: Adil Hafeez <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2024
1 parent 6cd0557 commit 6fb6351
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 276 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Engineered with purpose-built LLMs, Arch handles the critical but undifferentiat
To get in touch with us, please join our [discord server](https://discord.gg/rSRQ9fv7). We will be monitoring that actively and offering support there.

## Demos
* [Function Calling](demos/function_calling/README.md) - Walk through of critical function calling capabilities
* [Insurance Agent](demos/insurance_agent/README.md) - Build a full insurance agent with arch
* [Network Agent](demos/network_agent/README.md) - Build a networking co-pilot/agent agent with arch
* [Function Calling](demos/function_calling/README.md) - Walk through of the core function calling capabilities Arch offers
* [Insurance Agent](demos/insurance_agent/README.md) - Build a full insurance agent with Arch
* [Network Agent](demos/network_agent/README.md) - Build a networking co-pilot/agent agent with Arch

## Quickstart

Expand Down Expand Up @@ -111,9 +111,9 @@ Make outbound calls via Arch
import openai

# Set the OpenAI API base URL to the Arch gateway endpoint
openai.api_base = "http://127.0.0.1:51001/v1"

# No need to set openai.api_key since it's configured in Arch's gateway
openai.api_base = "http://127.0.0.1:12000/v1"
# No need to set a specific openai.api_key since it's configured in Arch's gateway
openai.api_key = "null"

# Use the OpenAI client as usual
response = openai.Completion.create(
Expand Down
3 changes: 0 additions & 3 deletions arch/tools/MANIFEST.in

This file was deleted.

10 changes: 10 additions & 0 deletions arch/tools/cli/consts.py
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
KATANEMO_DOCKERHUB_REPO = "katanemo/archgw"
KATANEMO_LOCAL_MODEL_LIST = [
"katanemo/Arch-Guard-cpu",
"katanemo/Arch-Guard",
"katanemo/bge-large-en-v1.5",
]
SERVICE_NAME_ARCHGW = "archgw"
SERVICE_NAME_MODEL_SERVER = "model_server"
SERVICE_ALL = "all"
MODEL_SERVER_LOG_FILE = "~/archgw_logs/modelserver.log"
ACCESS_LOG_FILES = "~/archgw_logs/access*"
54 changes: 53 additions & 1 deletion arch/tools/cli/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
import time
import pkg_resources
import select
import sys
import glob
from cli.utils import run_docker_compose_ps, print_service_status, check_services_state
from cli.utils import getLogger
import sys
from cli.consts import (
KATANEMO_LOCAL_MODEL_LIST,
MODEL_SERVER_LOG_FILE,
ACCESS_LOG_FILES,
)
from huggingface_hub import snapshot_download

log = getLogger(__name__)

Expand Down Expand Up @@ -37,6 +44,45 @@ def stream_gateway_logs(follow):
log.info(f"Failed to stream logs: {str(e)}")


def stream_model_server_logs(follow):
"""
Get the model server logs, check if the user wants to follow/tail them.
"""
log_file_expanded = os.path.expanduser(MODEL_SERVER_LOG_FILE)

stream_command = ["tail"]
if follow:
stream_command.append("-f")

stream_command.append(log_file_expanded)
subprocess.run(
stream_command,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
)


def stream_access_logs(follow):
"""
Get the archgw access logs
"""
log_file_pattern_expanded = os.path.expanduser(ACCESS_LOG_FILES)
log_files = glob.glob(log_file_pattern_expanded)

stream_command = ["tail"]
if follow:
stream_command.append("-f")

stream_command.extend(log_files)
subprocess.run(
stream_command,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
)


def start_arch(arch_config_file, env, log_timeout=120):
"""
Start Docker Compose in detached mode and stream logs until services are healthy.
Expand Down Expand Up @@ -164,6 +210,12 @@ def stop_arch():
log.info(f"Failed to shut down services: {str(e)}")


def download_models_from_hf():
for model in KATANEMO_LOCAL_MODEL_LIST:
log.info(f"Downloading model: {model}")
snapshot_download(repo_id=model)


def start_arch_modelserver():
"""
Start the model server. This assumes that the archgw_modelserver package is installed locally
Expand Down
Loading

0 comments on commit 6fb6351

Please sign in to comment.