From e83de5d0082cf3f2446cfdcbad0bebf76191d621 Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Sat, 10 Feb 2024 21:56:05 -0800 Subject: [PATCH] add long context handling notebook (#1618) * add long context handling notebook * remove compression notebook --- autogen/coding/base.py | 20 +++++++++---------- .../coding/embedded_ipython_code_executor.py | 14 ++++++------- autogen/coding/factory.py | 4 ++-- .../coding/local_commandline_code_executor.py | 10 +++++----- autogen/coding/markdown_code_extractor.py | 4 ++-- autogen/oai/client.py | 6 +----- autogen/version.py | 2 +- website/docs/Examples.md | 3 ++- 8 files changed, 30 insertions(+), 33 deletions(-) diff --git a/autogen/coding/base.py b/autogen/coding/base.py index 13e84da8cf5e..936d3ee25366 100644 --- a/autogen/coding/base.py +++ b/autogen/coding/base.py @@ -8,7 +8,7 @@ class CodeBlock(BaseModel): - """A class that represents a code block.""" + """(Experimental) A class that represents a code block.""" code: str = Field(description="The code to execute.") @@ -16,7 +16,7 @@ class CodeBlock(BaseModel): class CodeResult(BaseModel): - """A class that represents the result of a code execution.""" + """(Experimental) A class that represents the result of a code execution.""" exit_code: int = Field(description="The exit code of the code execution.") @@ -24,10 +24,10 @@ class CodeResult(BaseModel): class CodeExtractor(Protocol): - """A code extractor class that extracts code blocks from a message.""" + """(Experimental) A code extractor class that extracts code blocks from a message.""" def extract_code_blocks(self, message: Union[str, List[Dict[str, Any]], None]) -> List[CodeBlock]: - """Extract code blocks from a message. + """(Experimental) Extract code blocks from a message. Args: message (str): The message to extract code blocks from. @@ -40,17 +40,17 @@ def extract_code_blocks(self, message: Union[str, List[Dict[str, Any]], None]) - @runtime_checkable class CodeExecutor(Protocol): - """A code executor class that executes code blocks and returns the result.""" + """(Experimental) A code executor class that executes code blocks and returns the result.""" class UserCapability(Protocol): - """An AgentCapability class that gives agent ability use this code executor.""" + """(Experimental) An AgentCapability class that gives agent ability use this code executor.""" def add_to_agent(self, agent: LLMAgent) -> None: ... # pragma: no cover @property def user_capability(self) -> "CodeExecutor.UserCapability": - """Capability to use this code executor. + """(Experimental) Capability to use this code executor. The exported capability can be added to an agent to allow it to use this code executor: @@ -68,11 +68,11 @@ def user_capability(self) -> "CodeExecutor.UserCapability": @property def code_extractor(self) -> CodeExtractor: - """The code extractor used by this code executor.""" + """(Experimental) The code extractor used by this code executor.""" ... # pragma: no cover def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CodeResult: - """Execute code blocks and return the result. + """(Experimental) Execute code blocks and return the result. This method should be implemented by the code executor. @@ -85,7 +85,7 @@ def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CodeResult: ... # pragma: no cover def restart(self) -> None: - """Restart the code executor. + """(Experimental) Restart the code executor. This method should be implemented by the code executor. diff --git a/autogen/coding/embedded_ipython_code_executor.py b/autogen/coding/embedded_ipython_code_executor.py index 3232c12e3114..01a640015dd6 100644 --- a/autogen/coding/embedded_ipython_code_executor.py +++ b/autogen/coding/embedded_ipython_code_executor.py @@ -18,7 +18,7 @@ class IPythonCodeResult(CodeResult): - """A code result class for IPython code executor.""" + """(Experimental) A code result class for IPython code executor.""" output_files: List[str] = Field( default_factory=list, @@ -27,7 +27,7 @@ class IPythonCodeResult(CodeResult): class EmbeddedIPythonCodeExecutor(BaseModel): - """A code executor class that executes code statefully using an embedded + """(Experimental) A code executor class that executes code statefully using an embedded IPython kernel managed by this class. **This will execute LLM generated code on the local machine.** @@ -85,7 +85,7 @@ class EmbeddedIPythonCodeExecutor(BaseModel): ) class UserCapability: - """An AgentCapability class that gives agent ability use a stateful + """(Experimental) An AgentCapability class that gives agent ability use a stateful IPython code executor. This capability can be added to an agent using the `add_to_agent` method which append a system message update to the agent's system message.""" @@ -129,17 +129,17 @@ def __init__(self, **kwargs: Any): @property def user_capability(self) -> "EmbeddedIPythonCodeExecutor.UserCapability": - """Export a user capability for this executor that can be added to + """(Experimental) Export a user capability for this executor that can be added to an agent using the `add_to_agent` method.""" return EmbeddedIPythonCodeExecutor.UserCapability(self.system_message_update) @property def code_extractor(self) -> CodeExtractor: - """Export a code extractor that can be used by an agent.""" + """(Experimental) Export a code extractor that can be used by an agent.""" return MarkdownCodeExtractor() def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> IPythonCodeResult: - """Execute a list of code blocks and return the result. + """(Experimental) Execute a list of code blocks and return the result. This method executes a list of code blocks as cells in an IPython kernel managed by this class. @@ -204,7 +204,7 @@ def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> IPythonCodeResult ) def restart(self) -> None: - """Restart a new session.""" + """(Experimental) Restart a new session.""" self._kernel_client.stop_channels() self._kernel_manager.shutdown_kernel() self._kernel_manager = KernelManager(kernel_name=self.kernel_name) diff --git a/autogen/coding/factory.py b/autogen/coding/factory.py index 65149b5a8c77..953de5906dd1 100644 --- a/autogen/coding/factory.py +++ b/autogen/coding/factory.py @@ -6,11 +6,11 @@ class CodeExecutorFactory: - """A factory class for creating code executors.""" + """(Experimental) A factory class for creating code executors.""" @staticmethod def create(code_execution_config: Dict[str, Any]) -> CodeExecutor: - """Get a code executor based on the code execution config. + """(Experimental) Get a code executor based on the code execution config. Args: code_execution_config (Dict): The code execution config, diff --git a/autogen/coding/local_commandline_code_executor.py b/autogen/coding/local_commandline_code_executor.py index 252c57376778..5989e940d7bc 100644 --- a/autogen/coding/local_commandline_code_executor.py +++ b/autogen/coding/local_commandline_code_executor.py @@ -25,7 +25,7 @@ def colored(x: Any, *args: Any, **kwargs: Any) -> str: # type: ignore[misc] class CommandlineCodeResult(CodeResult): - """A code result class for command line code executor.""" + """(Experimental) A code result class for command line code executor.""" code_file: Optional[str] = Field( default=None, @@ -34,7 +34,7 @@ class CommandlineCodeResult(CodeResult): class LocalCommandlineCodeExecutor(BaseModel): - """A code executor class that executes code through a local command line + """(Experimental) A code executor class that executes code through a local command line environment. **This will execute LLM generated code on the local machine.** @@ -105,11 +105,11 @@ def user_capability(self) -> "LocalCommandlineCodeExecutor.UserCapability": @property def code_extractor(self) -> CodeExtractor: - """Export a code extractor that can be used by an agent.""" + """(Experimental) Export a code extractor that can be used by an agent.""" return MarkdownCodeExtractor() def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CommandlineCodeResult: - """Execute the code blocks and return the result. + """(Experimental) Execute the code blocks and return the result. Args: code_blocks (List[CodeBlock]): The code blocks to execute. @@ -158,5 +158,5 @@ def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CommandlineCodeRe return CommandlineCodeResult(exit_code=exitcode, output=logs_all, code_file=code_filename) def restart(self) -> None: - """Restart the code executor.""" + """(Experimental) Restart the code executor.""" warnings.warn("Restarting local command line code executor is not supported. No action is taken.") diff --git a/autogen/coding/markdown_code_extractor.py b/autogen/coding/markdown_code_extractor.py index 73a1e03e6692..cee107fdb6ab 100644 --- a/autogen/coding/markdown_code_extractor.py +++ b/autogen/coding/markdown_code_extractor.py @@ -8,10 +8,10 @@ class MarkdownCodeExtractor: - """A class that extracts code blocks from a message using Markdown syntax.""" + """(Experimental) A class that extracts code blocks from a message using Markdown syntax.""" def extract_code_blocks(self, message: Union[str, List[Dict[str, Any]], None]) -> List[CodeBlock]: - """Extract code blocks from a message. If no code blocks are found, + """(Experimental) Extract code blocks from a message. If no code blocks are found, return an empty list. Args: diff --git a/autogen/oai/client.py b/autogen/oai/client.py index 12dc9e8c3878..1c46a01e87fd 100644 --- a/autogen/oai/client.py +++ b/autogen/oai/client.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os import sys from typing import Any, List, Optional, Dict, Callable, Tuple, Union import logging @@ -11,11 +10,8 @@ from typing import Protocol from autogen.cache.cache import Cache -from autogen.oai import completion - -from autogen.oai.openai_utils import DEFAULT_AZURE_API_VERSION, get_key, OAI_PRICE1K +from autogen.oai.openai_utils import get_key, OAI_PRICE1K from autogen.token_count_utils import count_token -from autogen._pydantic import model_dump TOOL_ENABLED = False try: diff --git a/autogen/version.py b/autogen/version.py index b5c9b6cb7114..11ef09286813 100644 --- a/autogen/version.py +++ b/autogen/version.py @@ -1 +1 @@ -__version__ = "0.2.12" +__version__ = "0.2.13" diff --git a/website/docs/Examples.md b/website/docs/Examples.md index db317310b4a4..4401fe084181 100644 --- a/website/docs/Examples.md +++ b/website/docs/Examples.md @@ -74,7 +74,8 @@ Links to notebook examples: 1. **Long Context Handling** - - Conversations with Chat History Compression Enabled - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_compression.ipynb) + + - Long Context Handling as A Capability - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_capability_long_context_handling.ipynb) 1. **Evaluation and Assessment**