mirror of
https://github.com/microsoft/autogen.git
synced 2025-10-05 21:17:04 +00:00

* Core CAP components + Autogen adapter + Demo * Cleanup Readme * C# folder * Cleanup readme * summary_method bug fix * CAN -> CAP * pre-commit fixes * pre-commit fixes * modification of sys path should ignore E402 * fix pre-commit check issues * Updated docs * Clean up docs * more refactoring * better packaging refactor * Refactoring for package changes * Run demo app without autogencap installed or in the path * Remove debug related sleep() * removed CAP in some class names * Investigate a logging framework that supports color in windows * added type hints * remove circular dependency * fixed pre-commit issues * pre-commit ruff issues * removed circular definition * pre-commit fixes * Fix pre-commit issues * pre-commit fixes * updated for _prepare_chat signature changes * Better instructions for demo and some minor refactoring * Added details that explain CAP * Reformat Readme * More ReadMe Formatting * Readme edits * Agent -> Actor * Broker can startup on it's own * Remote AutoGen Agents * Updated docs * 1) StandaloneBroker in demo 2) Removed Autogen only demo options * 1) Agent -> Actor refactor 2) init broker as early * rename user_proxy -> user_proxy_conn * Add DirectorySvc * Standalone demo refactor * Get ActorInfo from DirectorySvc when searching for Actor * Broker cleanup * Proper cleanup and remove debug sleep() * Run one directory service only. * fix paths to run demo apps from command line * Handle keyboard interrupt * Wait for Broker and Directory to start up * Move Terminate AGActor * Accept input from the user in UserProxy * Move sleeps close to operations that bind or connect * Comments * Created an encapsulated CAP Pair for AutoGen pair communication * pre-commit checks * fix pre-commit * Pair should not make assumptions about who is first and who is second * Use task passed into InitiateChat * Standalone directory svc * Fix broken LFS files * Long running DirectorySvc * DirectorySvc does not have a status * Exit DirectorySvc Loop * Debugging Remoting * Reduce frequency of status messages * Debugging remote Actor * roll back git-lfs updates * rollback git-lfs changes * Debug network connectivity * pre-commit fixes * Create a group chat interface familiar to AutoGen GroupChat users * pre-commit fixes
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
import threading
|
|
import datetime
|
|
from autogencap.Config import LOG_LEVEL, IGNORED_LOG_CONTEXTS
|
|
from termcolor import colored
|
|
|
|
# Define log levels as constants
|
|
DEBUG = 0
|
|
INFO = 1
|
|
WARN = 2
|
|
ERROR = 3
|
|
|
|
# Map log levels to their names
|
|
LEVEL_NAMES = ["DBG", "INF", "WRN", "ERR"]
|
|
LEVEL_COLOR = ["dark_grey", "green", "yellow", "red"]
|
|
|
|
console_lock = threading.Lock()
|
|
|
|
|
|
def Log(level, context, msg):
|
|
# Check if the current level meets the threshold
|
|
if level >= LOG_LEVEL: # Use the LOG_LEVEL from the Config module
|
|
# Check if the context is in the list of ignored contexts
|
|
if context in IGNORED_LOG_CONTEXTS:
|
|
return
|
|
with console_lock:
|
|
timestamp = colored(datetime.datetime.now().strftime("%m/%d/%y %H:%M:%S"), "dark_grey")
|
|
# Translate level number to name and color
|
|
level_name = colored(LEVEL_NAMES[level], LEVEL_COLOR[level])
|
|
# Center justify the context and color it blue
|
|
context = colored(context.ljust(14), "blue")
|
|
# color the msg based on the level
|
|
msg = colored(msg, LEVEL_COLOR[level])
|
|
print(f"{threading.get_ident()} {timestamp} {level_name}: [{context}] {msg}")
|
|
|
|
|
|
def Debug(context, message):
|
|
Log(DEBUG, context, message)
|
|
|
|
|
|
def Info(context, message):
|
|
Log(INFO, context, message)
|
|
|
|
|
|
def Warn(context, message):
|
|
Log(WARN, context, message)
|
|
|
|
|
|
def Error(context, message):
|
|
Log(ERROR, context, message)
|
|
|
|
|
|
def shorten(msg, num_parts=5, max_len=100):
|
|
# Remove new lines
|
|
msg = msg.replace("\n", " ")
|
|
|
|
# If the message is shorter than or equal to max_len characters, return it as is
|
|
if len(msg) <= max_len:
|
|
return msg
|
|
|
|
# Calculate the length of each part
|
|
part_len = max_len // num_parts
|
|
|
|
# Create a list to store the parts
|
|
parts = []
|
|
|
|
# Get the parts from the message
|
|
for i in range(num_parts):
|
|
start = i * part_len
|
|
end = start + part_len
|
|
parts.append(msg[start:end])
|
|
|
|
# Join the parts with '...' and return the result
|
|
return "...".join(parts)
|