mirror of
https://github.com/microsoft/autogen.git
synced 2026-04-20 03:02:16 -04:00
Add Console function to stream result to pretty print console output (#4115)
This commit is contained in:
@@ -35,18 +35,31 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"source='user' models_usage=None content='What is the weather in New York?'\n",
|
||||
"source='weather_agent' models_usage=RequestUsage(prompt_tokens=79, completion_tokens=15) content=[FunctionCall(id='call_CntvzLVL7iYJwPP2WWeBKNHc', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",
|
||||
"source='weather_agent' models_usage=None content=[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_CntvzLVL7iYJwPP2WWeBKNHc')]\n",
|
||||
"source='weather_agent' models_usage=RequestUsage(prompt_tokens=90, completion_tokens=14) content='The weather in New York is currently 73 degrees and sunny.'\n",
|
||||
"source='weather_agent' models_usage=RequestUsage(prompt_tokens=137, completion_tokens=4) content='TERMINATE'\n",
|
||||
"TaskResult(messages=[TextMessage(source='user', models_usage=None, content='What is the weather in New York?'), ToolCallMessage(source='weather_agent', models_usage=RequestUsage(prompt_tokens=79, completion_tokens=15), content=[FunctionCall(id='call_CntvzLVL7iYJwPP2WWeBKNHc', arguments='{\"city\":\"New York\"}', name='get_weather')]), ToolCallResultMessage(source='weather_agent', models_usage=None, content=[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_CntvzLVL7iYJwPP2WWeBKNHc')]), TextMessage(source='weather_agent', models_usage=RequestUsage(prompt_tokens=90, completion_tokens=14), content='The weather in New York is currently 73 degrees and sunny.'), TextMessage(source='weather_agent', models_usage=RequestUsage(prompt_tokens=137, completion_tokens=4), content='TERMINATE')], stop_reason=\"Text 'TERMINATE' mentioned\")\n"
|
||||
"---------- user ----------\n",
|
||||
"What is the weather in New York?\n",
|
||||
"---------- weather_agent ----------\n",
|
||||
"[FunctionCall(id='call_AhTZ2q3TNL8x0qs00e3wIZ7y', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",
|
||||
"[Prompt tokens: 79, Completion tokens: 15]\n",
|
||||
"---------- weather_agent ----------\n",
|
||||
"[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_AhTZ2q3TNL8x0qs00e3wIZ7y')]\n",
|
||||
"---------- weather_agent ----------\n",
|
||||
"The weather in New York is currently 73 degrees and sunny.\n",
|
||||
"[Prompt tokens: 90, Completion tokens: 14]\n",
|
||||
"---------- weather_agent ----------\n",
|
||||
"TERMINATE\n",
|
||||
"[Prompt tokens: 137, Completion tokens: 4]\n",
|
||||
"---------- Summary ----------\n",
|
||||
"Number of messages: 5\n",
|
||||
"Finish reason: Text 'TERMINATE' mentioned\n",
|
||||
"Total prompt tokens: 306\n",
|
||||
"Total completion tokens: 33\n",
|
||||
"Duration: 1.43 seconds\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from autogen_agentchat.agents import AssistantAgent\n",
|
||||
"from autogen_agentchat.task import TextMentionTermination\n",
|
||||
"from autogen_agentchat.task import Console, TextMentionTermination\n",
|
||||
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
|
||||
"from autogen_ext.models import OpenAIChatCompletionClient\n",
|
||||
"\n",
|
||||
@@ -72,8 +85,7 @@
|
||||
"\n",
|
||||
" # Run the team and stream messages\n",
|
||||
" stream = agent_team.run_stream(task=\"What is the weather in New York?\")\n",
|
||||
" async for response in stream:\n",
|
||||
" print(response)\n",
|
||||
" await Console(stream)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n",
|
||||
@@ -114,7 +126,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.6"
|
||||
"version": "3.11.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user