Skip to content

Commit 18b05d7

Browse files
Copilothiyouga
andcommitted
Refactor test_tracer and rename webui to playground with CLI support
Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com>
1 parent ba37ecf commit 18b05d7

5 files changed

Lines changed: 46 additions & 31 deletions

File tree

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
"""
17-
Web UI for interacting with LLMs.
17+
Playground for interacting with LLMs.
1818
1919
This module provides a web interface for chatting with language models,
2020
with support for config editing, streaming responses, and message cards
@@ -83,7 +83,7 @@ def create_chat_app() -> Flask:
8383
<!DOCTYPE html>
8484
<html>
8585
<head>
86-
<title>Chat with LLMs</title>
86+
<title>LLM Playground</title>
8787
<meta charset="utf-8">
8888
<meta name="viewport" content="width=device-width, initial-scale=1">
8989
<style>
@@ -297,7 +297,7 @@ def create_chat_app() -> Flask:
297297
</head>
298298
<body>
299299
<div class="header">
300-
<h1>🤖 Chat with LLMs</h1>
300+
<h1>🤖 LLM Playground</h1>
301301
<button class="config-toggle" onclick="toggleConfig()">⚙️ Config</button>
302302
</div>
303303
@@ -748,19 +748,28 @@ def clear() -> Response:
748748
return app
749749

750750

751-
def start_chat_server(host: str = "127.0.0.1", port: int = 5001, debug: bool = False) -> None:
751+
def start_playground_server(host: str = "127.0.0.1", port: int = 5001, debug: bool = False) -> None:
752752
"""
753-
Start the chat web server.
753+
Start the playground web server.
754754
755755
Args:
756756
host: Host address to bind to
757757
port: Port number to listen on
758758
debug: Enable debug mode
759759
"""
760760
app = create_chat_app()
761-
print(f"Starting Chat with LLMs at http://{host}:{port}")
761+
print(f"Starting LLM Playground at http://{host}:{port}")
762762
app.run(host=host, port=port, debug=debug)
763763

764764

765765
if __name__ == "__main__":
766-
start_chat_server()
766+
import argparse
767+
768+
parser = argparse.ArgumentParser(description="Start the LLM Playground web server")
769+
parser.add_argument("--host", type=str, default="127.0.0.1", help="Host address to bind to")
770+
parser.add_argument("--port", type=int, default=5001, help="Port number to listen on")
771+
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
772+
773+
args = parser.parse_args()
774+
775+
start_playground_server(host=args.host, port=args.port, debug=args.debug)

src_py/agenthub/integration/tracer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,3 +725,18 @@ def start_web_server(self, host: str = "127.0.0.1", port: int = 5000, debug: boo
725725
print(f"Starting tracer web server at http://{host}:{port}")
726726
print(f"Cache directory: {self.cache_dir.resolve()}")
727727
app.run(host=host, port=port, debug=debug)
728+
729+
730+
if __name__ == "__main__":
731+
import argparse
732+
733+
parser = argparse.ArgumentParser(description="Start the Tracer web server for browsing conversation files")
734+
parser.add_argument("--cache_dir", type=str, default=None, help="Directory to store conversation history files")
735+
parser.add_argument("--host", type=str, default="127.0.0.1", help="Host address to bind to")
736+
parser.add_argument("--port", type=int, default=5000, help="Port number to listen on")
737+
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
738+
739+
args = parser.parse_args()
740+
741+
tracer = Tracer(cache_dir=args.cache_dir)
742+
tracer.start_web_server(host=args.host, port=args.port, debug=args.debug)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
# limitations under the License.
1414

1515
"""
16-
Example demonstrating the AgentHub Chat Web UI.
16+
Example demonstrating the AgentHub Playground.
1717
18-
This example shows how to start the web UI server for interactive
19-
chat with LLMs. The web UI supports:
18+
This example shows how to start the playground server for interactive
19+
chat with LLMs. The playground supports:
2020
- Config editing (model, temperature, max_tokens)
2121
- Streaming chat responses
2222
- Message cards with token usage and finish reasons
2323
"""
2424

25-
from agenthub.integration.web_ui import start_chat_server
25+
from agenthub.integration.playground import start_playground_server
2626

2727

2828
if __name__ == "__main__":
2929
print("=" * 60)
30-
print("AgentHub Chat Web UI")
30+
print("AgentHub LLM Playground")
3131
print("=" * 60)
3232
print("\nStarting web server...")
3333
print("\nOpen http://127.0.0.1:5001 in your browser to start chatting!")
3434
print("Press Ctrl+C to stop the server.\n")
3535

36-
start_chat_server(host="127.0.0.1", port=5001, debug=False)
36+
start_playground_server(host="127.0.0.1", port=5001, debug=False)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from flask import Flask
1616

17-
from agenthub.integration.web_ui import create_chat_app
17+
from agenthub.integration.playground import create_chat_app
1818

1919

2020
def test_create_chat_app():
@@ -31,7 +31,7 @@ def test_chat_app_index_route():
3131
with app.test_client() as client:
3232
response = client.get("/")
3333
assert response.status_code == 200
34-
assert b"Chat with LLMs" in response.data
34+
assert b"LLM Playground" in response.data
3535
assert b"messagesContainer" in response.data
3636
assert b"messageInput" in response.data
3737

src_py/tests/test_tracer.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@
2424
from agenthub.integration.tracer import Tracer
2525

2626

27-
AVAILABLE_MODELS = []
28-
29-
if os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY"):
30-
AVAILABLE_MODELS.append("gemini-3-flash-preview")
31-
32-
if os.getenv("ANTHROPIC_API_KEY"):
33-
AVAILABLE_MODELS.append("claude-sonnet-4-5-20250929")
34-
35-
if os.getenv("GLM_API_KEY"):
36-
AVAILABLE_MODELS.append(pytest.param("glm-4.7", marks=pytest.mark.xfail(reason="API rate limit")))
27+
GEMINI_AVAILABLE = bool(os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY"))
3728

3829

3930
@pytest.fixture
@@ -243,12 +234,12 @@ def test_web_app_nonexistent_path(temp_cache_dir):
243234

244235

245236
@pytest.mark.asyncio
246-
@pytest.mark.parametrize("model", AVAILABLE_MODELS)
247-
async def test_monitoring_integration(model, temp_cache_dir):
237+
@pytest.mark.skipif(not GEMINI_AVAILABLE, reason="Gemini API key not available")
238+
async def test_monitoring_integration(temp_cache_dir):
248239
"""Test monitoring integration with AutoLLMClient."""
249240

250241
os.environ["AGENTHUB_CACHE_DIR"] = temp_cache_dir
251-
client = AutoLLMClient(model=model)
242+
client = AutoLLMClient(model="gemini-3-flash-preview")
252243
config = {"trace_id": "integration_test/conversation.txt"}
253244

254245
message = {"role": "user", "content_items": [{"type": "text", "text": "Say hello"}]}
@@ -267,12 +258,12 @@ async def test_monitoring_integration(model, temp_cache_dir):
267258

268259

269260
@pytest.mark.asyncio
270-
@pytest.mark.parametrize("model", AVAILABLE_MODELS)
271-
async def test_monitoring_updates_on_multiple_messages(model, temp_cache_dir):
261+
@pytest.mark.skipif(not GEMINI_AVAILABLE, reason="Gemini API key not available")
262+
async def test_monitoring_updates_on_multiple_messages(temp_cache_dir):
272263
"""Test that monitoring file is updated with each new message."""
273264

274265
os.environ["AGENTHUB_CACHE_DIR"] = temp_cache_dir
275-
client = AutoLLMClient(model=model)
266+
client = AutoLLMClient(model="gemini-3-flash-preview")
276267
config = {"trace_id": "multi_message_test/conversation.txt"}
277268

278269
# First message

0 commit comments

Comments
 (0)