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.

test_group_chat_endpoint.py 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import os
  2. import pytest
  3. from autogen_agentchat.agents import AssistantAgent
  4. from autogen_agentchat.teams import SelectorGroupChat
  5. from autogen_agentchat.ui import Console
  6. from autogen_core.models import ChatCompletionClient
  7. from autogen_ext.models.openai import OpenAIChatCompletionClient
  8. async def _test_selector_group_chat(model_client: ChatCompletionClient) -> None:
  9. assistant = AssistantAgent(
  10. "assistant",
  11. description="A helpful assistant agent.",
  12. model_client=model_client,
  13. system_message="You are a helpful assistant.",
  14. )
  15. critic = AssistantAgent(
  16. "critic",
  17. description="A critic agent to provide feedback.",
  18. model_client=model_client,
  19. system_message="Provide feedback.",
  20. )
  21. team = SelectorGroupChat([assistant, critic], model_client=model_client, max_turns=2)
  22. await Console(team.run_stream(task="Draft a short email about organizing a holiday party for new year."))
  23. @pytest.mark.asyncio
  24. async def test_selector_group_chat_gemini() -> None:
  25. try:
  26. api_key = os.environ["GEMINI_API_KEY"]
  27. except KeyError:
  28. pytest.skip("GEMINI_API_KEY not set in environment variables.")
  29. model_client = OpenAIChatCompletionClient(
  30. model="gemini-1.5-flash",
  31. api_key=api_key,
  32. )
  33. await _test_selector_group_chat(model_client)
  34. @pytest.mark.asyncio
  35. async def test_selector_group_chat_openai() -> None:
  36. try:
  37. api_key = os.environ["OPENAI_API_KEY"]
  38. except KeyError:
  39. pytest.skip("OPENAI_API_KEY not set in environment variables.")
  40. model_client = OpenAIChatCompletionClient(
  41. model="gpt-4o-mini",
  42. api_key=api_key,
  43. )
  44. await _test_selector_group_chat(model_client)