mirror of https://github.com/microsoft/autogen.git
add long context handling notebook (#1618)
* add long context handling notebook * remove compression notebook
This commit is contained in:
parent
80890588ca
commit
e83de5d008
|
@ -8,7 +8,7 @@ __all__ = ("CodeBlock", "CodeResult", "CodeExtractor", "CodeExecutor")
|
|||
|
||||
|
||||
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 @@ class CodeExtractor(Protocol):
|
|||
|
||||
@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 @@ class CodeExecutor(Protocol):
|
|||
|
||||
@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 @@ class CodeExecutor(Protocol):
|
|||
... # 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.
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ __all__ = ("EmbeddedIPythonCodeExecutor",)
|
|||
|
||||
|
||||
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 @@ the output will be a path to the image instead of the image itself.
|
|||
)
|
||||
|
||||
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 @@ the output will be a path to the image instead of the image itself.
|
|||
|
||||
@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 @@ the output will be a path to the image instead of the image itself.
|
|||
)
|
||||
|
||||
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)
|
||||
|
|
|
@ -6,11 +6,11 @@ __all__ = ("CodeExecutorFactory",)
|
|||
|
||||
|
||||
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,
|
||||
|
|
|
@ -25,7 +25,7 @@ __all__ = (
|
|||
|
||||
|
||||
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 @@ If you want the user to save the code in a file before executing it, put # filen
|
|||
|
||||
@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 @@ If you want the user to save the code in a file before executing it, put # filen
|
|||
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.")
|
||||
|
|
|
@ -8,10 +8,10 @@ __all__ = ("MarkdownCodeExtractor",)
|
|||
|
||||
|
||||
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:
|
||||
|
|
|
@ -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 pydantic import BaseModel
|
|||
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:
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.2.12"
|
||||
__version__ = "0.2.13"
|
||||
|
|
|
@ -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)
|
||||
<!-- - 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**
|
||||
|
||||
|
|
Loading…
Reference in New Issue