You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 2.4 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import autogen
  2. from autogen.agentchat.contrib.web_surfer import WebSurferAgent
  3. from autogen.browser_utils import RequestsMarkdownBrowser, BingMarkdownSearch
  4. from autogen.agentchat.contrib.orchestrator import Orchestrator
  5. from config_manager import ConfigManager
  6. from misc_utils import response_preparer
  7. # setup LLM config and clients
  8. config_manager = ConfigManager()
  9. config_manager.initialize()
  10. assistant = autogen.AssistantAgent(
  11. "assistant",
  12. is_termination_msg=lambda x: x.get("content", "").rstrip().find("TERMINATE") >= 0,
  13. code_execution_config=False,
  14. llm_config=config_manager.llm_config,
  15. )
  16. user_proxy_name = "computer_terminal"
  17. user_proxy = autogen.UserProxyAgent(
  18. user_proxy_name,
  19. human_input_mode="NEVER",
  20. description="A computer terminal that performs no other action than running Python scripts (provided to it quoted in ```python code blocks), or sh shell scripts (provided to it quoted in ```sh code blocks)",
  21. is_termination_msg=lambda x: x.get("content", "").rstrip().find("TERMINATE") >= 0,
  22. code_execution_config={
  23. "work_dir": "coding",
  24. "use_docker": False,
  25. },
  26. default_auto_reply=f'Invalid {user_proxy_name} input: no code block detected.\nPlease provide {user_proxy_name} a complete Python script or a shell (sh) script to run. Scripts should appear in code blocks beginning "```python" or "```sh" respectively.',
  27. max_consecutive_auto_reply=15,
  28. )
  29. browser = RequestsMarkdownBrowser(
  30. viewport_size=1024 * 5,
  31. downloads_folder="coding",
  32. search_engine=BingMarkdownSearch(bing_api_key=config_manager.bing_api_key, interleave_results=False),
  33. )
  34. web_surfer = WebSurferAgent(
  35. "web_surfer",
  36. llm_config=config_manager.llm_config,
  37. summarizer_llm_config=config_manager.llm_config,
  38. is_termination_msg=lambda x: x.get("content", "").rstrip().find("TERMINATE") >= 0,
  39. code_execution_config=False,
  40. browser=browser,
  41. )
  42. maestro = Orchestrator(
  43. "orchestrator",
  44. agents=[assistant, user_proxy, web_surfer],
  45. llm_config=config_manager.llm_config,
  46. )
  47. # read the task from standard input
  48. task = input("Enter the task: ")
  49. # task = "Find 10 highest cited publications written by Gagan Bansal"
  50. user_proxy.initiate_chat(maestro, message=task, clear_history=True)
  51. final_response = response_preparer(
  52. inner_messages=maestro.chat_messages[user_proxy],
  53. PROMPT=task,
  54. client=assistant.client,
  55. )
  56. print(final_response)