mirror of
https://github.com/microsoft/autogen.git
synced 2025-08-07 08:11:58 +00:00

* support groupchat, other QOL fixes * remove gallery success toast * Update website/blog/2023-12-01-AutoGenStudio/index.mdx Co-authored-by: Chi Wang <wang.chi@microsoft.com> --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com>
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
import json
|
|
import time
|
|
from typing import List
|
|
from .datamodel import AgentWorkFlowConfig, Message
|
|
from .utils import extract_successful_code_blocks, get_default_agent_config, get_modified_files
|
|
from .workflowmanager import AutoGenWorkFlowManager
|
|
import os
|
|
|
|
|
|
class AutoGenChatManager:
|
|
def __init__(self) -> None:
|
|
pass
|
|
|
|
def chat(self, message: Message, history: List, flow_config: AgentWorkFlowConfig = None, **kwargs) -> None:
|
|
work_dir = kwargs.get("work_dir", None)
|
|
scratch_dir = os.path.join(work_dir, "scratch")
|
|
|
|
# if no flow config is provided, use the default
|
|
if flow_config is None:
|
|
flow_config = get_default_agent_config(scratch_dir)
|
|
|
|
flow = AutoGenWorkFlowManager(config=flow_config, history=history, work_dir=scratch_dir)
|
|
message_text = message.content.strip()
|
|
|
|
output = ""
|
|
start_time = time.time()
|
|
|
|
metadata = {}
|
|
flow.run(message=f"{message_text}", clear_history=False)
|
|
|
|
metadata["messages"] = flow.agent_history
|
|
|
|
output = ""
|
|
|
|
if flow_config.summary_method == "last":
|
|
successful_code_blocks = extract_successful_code_blocks(flow.agent_history)
|
|
last_message = flow.agent_history[-1]["message"]["content"]
|
|
successful_code_blocks = "\n\n".join(successful_code_blocks)
|
|
output = (last_message + "\n" + successful_code_blocks) if successful_code_blocks else last_message
|
|
elif flow_config.summary_method == "llm":
|
|
output = ""
|
|
elif flow_config.summary_method == "none":
|
|
output = ""
|
|
|
|
metadata["code"] = ""
|
|
end_time = time.time()
|
|
metadata["time"] = end_time - start_time
|
|
modified_files = get_modified_files(start_time, end_time, scratch_dir, dest_dir=work_dir)
|
|
metadata["files"] = modified_files
|
|
|
|
print("Modified files: ", len(modified_files))
|
|
|
|
output_message = Message(
|
|
user_id=message.user_id,
|
|
root_msg_id=message.root_msg_id,
|
|
role="assistant",
|
|
content=output,
|
|
metadata=json.dumps(metadata),
|
|
session_id=message.session_id,
|
|
)
|
|
|
|
return output_message
|