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.

browser_chat.py 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. from autogen import UserProxyAgent, config_list_from_json
  3. from autogen.browser_utils import (
  4. RequestsMarkdownBrowser,
  5. PlaywrightMarkdownBrowser,
  6. SeleniumMarkdownBrowser,
  7. BingMarkdownSearch,
  8. )
  9. from autogen.agentchat.contrib.web_surfer import WebSurferAgent
  10. def main():
  11. # Load LLM inference endpoints from an env variable or a file
  12. # See https://microsoft.github.io/autogen/docs/FAQ#set-your-api-endpoints
  13. # and OAI_CONFIG_LIST_sample.
  14. # For example, if you have created a OAI_CONFIG_LIST file in the current working directory, that file will be used.
  15. config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
  16. browser = RequestsMarkdownBrowser(
  17. # PlaywrightMarkdownBrowser(
  18. viewport_size=1024 * 3,
  19. downloads_folder=os.getcwd(),
  20. search_engine=BingMarkdownSearch(bing_api_key=os.environ["BING_API_KEY"]),
  21. # launch_args={"channel": "msedge", "headless": False},
  22. )
  23. web_surfer = WebSurferAgent(
  24. "web_surfer",
  25. llm_config={"config_list": config_list},
  26. summarizer_llm_config={"config_list": config_list},
  27. is_termination_msg=lambda x: x.get("content", "").rstrip().find("TERMINATE") >= 0,
  28. code_execution_config=False,
  29. browser=browser,
  30. )
  31. # Create the agent that represents the user in the conversation.
  32. user_proxy = UserProxyAgent("user", code_execution_config=False)
  33. # Let the assistant start the conversation. It will end when the user types exit.
  34. web_surfer.initiate_chat(user_proxy, message="How can I help you today?")
  35. if __name__ == "__main__":
  36. main()