diff --git a/docs/swarms/utils/phoenix_tracer.md b/docs/swarms/utils/phoenix_tracer.md deleted file mode 100644 index 97ed422a..00000000 --- a/docs/swarms/utils/phoenix_tracer.md +++ /dev/null @@ -1,128 +0,0 @@ -# Phoenix Trace Decorator Documentation - -## Introduction - -Welcome to the documentation for the `phoenix_trace_decorator` module. This module provides a convenient decorator for tracing Python functions and capturing exceptions using Phoenix, a versatile tracing and monitoring tool. Phoenix allows you to gain insights into the execution of your code, capture errors, and monitor performance. - -## Table of Contents - -1. [Installation](#installation) -2. [Getting Started](#getting-started) -3. [Decorator Usage](#decorator-usage) -4. [Examples](#examples) -5. [Best Practices](#best-practices) -6. [References](#references) - -## 1. Installation - -Before using the `phoenix_trace_decorator`, you need to install the Swarms library. You can install Phoenix using pip: - -```bash -pip install swarms -``` - -## 2. Getting Started - -Phoenix is a powerful tracing and monitoring tool, and the `phoenix_trace_decorator` simplifies the process of tracing functions and capturing exceptions within your Python code. To begin, ensure that Phoenix is installed, and then import the `phoenix_trace_decorator` module into your Python script. - -```python -from swarms import phoenix_trace_decorator -``` - -## 3. Decorator Usage - -The `phoenix_trace_decorator` module provides a decorator, `phoenix_trace_decorator`, which can be applied to functions you want to trace. The decorator takes a single argument, a docstring that describes the purpose of the function being traced. - -Here is the basic structure of using the decorator: - -```python -@phoenix_trace_decorator("Description of the function") -def my_function(param1, param2): - # Function implementation - pass -``` - -## 4. Examples - -Let's explore some practical examples of using the `phoenix_trace_decorator` in your code. - -### Example 1: Basic Tracing - -In this example, we'll trace a simple function and print a message. - -```python -@phoenix_trace_decorator("Tracing a basic function") -def hello_world(): - print("Hello, World!") - -# Call the decorated function -hello_world() -``` - -### Example 2: Tracing a Function with Parameters - -You can use the decorator with functions that have parameters. - -```python -@phoenix_trace_decorator("Tracing a function with parameters") -def add_numbers(a, b): - result = a + b - print(f"Result: {result}") - -# Call the decorated function with parameters -add_numbers(2, 3) -``` - -### Example 3: Tracing Nested Calls - -The decorator can also trace nested function calls. - -```python -@phoenix_trace_decorator("Outer function") -def outer_function(): - print("Outer function") - - @phoenix_trace_decorator("Inner function") - def inner_function(): - print("Inner function") - - inner_function() - -# Call the decorated functions -outer_function() -``` - -### Example 4: Exception Handling - -Phoenix can capture exceptions and provide detailed information about them. - -```python -@phoenix_trace_decorator("Function with exception handling") -def divide(a, b): - try: - result = a / b - except ZeroDivisionError as e: - raise ValueError("Division by zero") from e - -# Call the decorated function with an exception -try: - divide(5, 0) -except ValueError as e: - print(f"Error: {e}") -``` - -## 5. Best Practices - -When using the `phoenix_trace_decorator`, consider the following best practices: - -- Use meaningful docstrings to describe the purpose of the traced functions. -- Keep your tracing focused on critical parts of your code. -- Make sure Phoenix is properly configured and running before using the decorator. - -## 6. References - -For more information on Phoenix and advanced usage, please refer to the [Phoenix Documentation](https://phoenix-docs.readthedocs.io/en/latest/). - ---- - -By following this documentation, you can effectively use the `phoenix_trace_decorator` to trace your Python functions, capture exceptions, and gain insights into the execution of your code. This tool is valuable for debugging, performance optimization, and monitoring the health of your applications. \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index de263ac6..fa2f6955 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -111,7 +111,6 @@ nav: - PGVectorStore: "swarms/memory/pg.md" - ShortTermMemory: "swarms/memory/short_term_memory.md" - swarms.utils: - - phoenix_trace_decorator: "swarms/utils/phoenix_tracer.md" - math_eval: "swarms/utils/math_eval.md" - Guides: - Overview: "examples/index.md" diff --git a/playground/demos/logistics/logistics.py b/playground/demos/logistics/logistics.py index 0e09f910..108ec702 100644 --- a/playground/demos/logistics/logistics.py +++ b/playground/demos/logistics/logistics.py @@ -12,7 +12,6 @@ from swarms.prompts.logistics import ( Efficiency_Agent_Prompt, ) -# from swarms.utils.phoenix_handler import phoenix_trace_decorator # from swarms.utils.banana_wrapper import banana load_dotenv() @@ -26,7 +25,6 @@ llm = GPT4VisionAPI(openai_api_key=api_key) factory_image = "factory_image1.jpg" # Initialize agents with respective prompts -# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") health_security_agent = Agent( llm=llm, sop=Health_Security_Agent_Prompt, @@ -34,7 +32,6 @@ health_security_agent = Agent( multi_modal=True, ) -# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") quality_control_agent = Agent( llm=llm, sop=Quality_Control_Agent_Prompt, @@ -42,7 +39,6 @@ quality_control_agent = Agent( multi_modal=True, ) -# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") productivity_agent = Agent( llm=llm, sop=Productivity_Agent_Prompt, @@ -50,17 +46,14 @@ productivity_agent = Agent( multi_modal=True, ) -# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") safety_agent = Agent( llm=llm, sop=Safety_Agent_Prompt, max_loops=1, multi_modal=True ) -# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") security_agent = Agent( llm=llm, sop=Security_Agent_Prompt, max_loops=1, multi_modal=True ) -# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") sustainability_agent = Agent( llm=llm, sop=Sustainability_Agent_Prompt, @@ -68,7 +61,6 @@ sustainability_agent = Agent( multi_modal=True, ) -# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.") efficiency_agent = Agent( llm=llm, sop=Efficiency_Agent_Prompt, diff --git a/playground/demos/optimize_llm_stack/vortex.py b/playground/demos/optimize_llm_stack/vortex.py index a40c29b9..5badb2fd 100644 --- a/playground/demos/optimize_llm_stack/vortex.py +++ b/playground/demos/optimize_llm_stack/vortex.py @@ -5,7 +5,6 @@ from dotenv import load_dotenv from swarms.models import OpenAIChat from swarms.structs import Agent -# from swarms.utils.phoenix_handler import phoenix_trace_decorator # import modal load_dotenv() @@ -22,9 +21,6 @@ llm = OpenAIChat( # Agent -# @phoenix_trace_decorator( -# "This function is an agent and is traced by Phoenix." -# ) # @stub.function(gpu="any") agent = Agent( llm=llm, diff --git a/swarms/utils/phoenix_handler.py b/swarms/utils/phoenix_handler.py deleted file mode 100644 index 329d3f2a..00000000 --- a/swarms/utils/phoenix_handler.py +++ /dev/null @@ -1,52 +0,0 @@ -import functools -import traceback -import phoenix as px - - -def phoenix_trace_decorator(doc_string): - """Phoenix trace decorator. - - - Args: - doc_string (_type_): doc string for the function - - - Example: - >>> @phoenix_trace_decorator( - >>> "This is a doc string" - >>> ) - >>> def test_function(): - >>> print("Hello world") - >>> - >>> test_function() - - - # Example of using the decorator - @phoenix_trace_decorator("This function does XYZ and is traced by Phoenix.") - def my_function(param1, param2): - # Function implementation - pass - """ - - def decorator(func): - @functools.wraps(func) - def wrapper(*args, **kwargs): - # Start phoenix session for tracing - session = px.active_session() or px.launch_app() - - try: - # Attempt to execute the function - result = func(*args, **kwargs) - return result - except Exception as error: - error_info = traceback.format_exc() - session.trace_exception( - exception=error, error_info=error_info - ) - raise - - # Atteach docs to wrapper func - wrapper.__doc__ = doc_string - return wrapper - - return decorator