Skip to content

Commit

Permalink
Add MagenticOne CLI (#4788)
Browse files Browse the repository at this point in the history
* Add MagenticOne CLI script for task execution with OpenAI GPT-4o integration

* Fix argument parsing in MagenticOne CLI to require a single task input

* Add docstring to main function in MagenticOne CLI for improved usage clarity

* Fix example usage in docstring of MagenticOne CLI for correct argument order

* Refactor argument parsing in MagenticOne CLI for improved clarity and consistency
  • Loading branch information
gagb authored Dec 23, 2024
1 parent ccae7f2 commit b173691
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/packages/autogen-ext/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies = [
"autogen-core==0.4.0.dev11",
]

[project.scripts]
m1 = "autogen_ext.teams.magentic_one_cli:main"

[project.optional-dependencies]
langchain = ["langchain_core~= 0.3.3"]
Expand Down Expand Up @@ -59,7 +61,6 @@ dev-dependencies = [
"autogen_test_utils"
]


[tool.ruff]
extend = "../../pyproject.toml"
include = ["src/**", "tests/*.py"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import argparse
import asyncio

from autogen_agentchat.ui import Console

from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.teams.magentic_one import MagenticOne


def main():
"""
Command-line interface for running a complex task using MagenticOne.
This script accepts a single task string and an optional flag to disable
human-in-the-loop mode. It initializes the necessary clients and runs the
task using the MagenticOne class.
Arguments:
task (str): The task to be executed by MagenticOne.
--no-hil: Optional flag to disable human-in-the-loop mode.
Example usage:
python magentic_one_cli.py "example task"
python magentic_one_cli.py --no-hil "example task"
"""
parser = argparse.ArgumentParser(
description=(
"Run a complex task using MagenticOne.\n\n"
"For more information, refer to the following paper: https://arxiv.org/abs/2411.04468"
)
)
parser.add_argument("task", type=str, nargs=1, help="The task to be executed by MagenticOne.")
parser.add_argument("--no-hil", action="store_true", help="Disable human-in-the-loop mode.")
args = parser.parse_args()

async def run_task(task, hil_mode):
client = OpenAIChatCompletionClient(model="gpt-4o")
m1 = MagenticOne(client=client, hil_mode=hil_mode)
await Console(m1.run_stream(task=task))

task = args.task[0]
asyncio.run(run_task(task, not args.no_hil))


if __name__ == "__main__":
main()

0 comments on commit b173691

Please sign in to comment.