You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In C#, GetStreamingChatMessageContentsAsync generates a IAsncEnumerable of StreamingChatMessageContent
// Invoke the chat completion serviceIChatCompletionServicechatCompletionService= kernel.GetRequiredService<IChatCompletionService>();varresults= chatCompletionService.GetStreamingChatMessageContentsAsync(
chatHistory: chatHistory,
executionSettings:new OpenAIPromptExecutionSettings(){// Allows the AI to automatically choose and invoke functions from the kernel's pluginsToolCallBehavior= ToolCallBehavior.AutoInvokeKernelFunctions
},
kernel: kernel
);// Return the results as a streamvarcompleteMessage=new StringBuilder();awaitforeach(var result in results){
completeMessage.Append(result);// Send the message events to the clientvarevents= assistantEventStreamUtility.CreateMessageEvent(run.Id, result);foreach(var messageEvent in events){yieldreturnmessageEvent;}}
Python, however, creates a AsyncGenerator[list[StreamingChatMessageContent], which makes the code less obvious to write because you always have to get the first index [0].
# Invoke the chat completion servicechatCompletion: ChatCompletionClientBase=kernel.get_service(type=ChatCompletionClientBase)
results=chatCompletion.complete_chat_stream(
chat_history=history,
settings=OpenAIChatPromptExecutionSettings(
# function_call_behavior=FunctionCallBehavior()
),
kernel=kernel
)
# Return the results as a stream completeMessage=""asyncforresultinresults:
completeMessage+=result[0].content# Send the message events to the clientevents=event_stream_utility.create_message_event(run.id, result[0])
foreventinevents:
yieldevent
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
Cardinality difference between C# and Python on StreamingChatMessageContent
.Net: Cardinality difference between C# and Python on StreamingChatMessageContent
May 12, 2024
github-actionsbot
changed the title
.Net: Cardinality difference between C# and Python on StreamingChatMessageContent
Python: Cardinality difference between C# and Python on StreamingChatMessageContent
May 12, 2024
matthewbolanos
changed the title
Python: Cardinality difference between C# and Python on StreamingChatMessageContent
Python: Cardinality difference between C# and Python on GetStreamingChatMessageContentsAsync and complete_chat_stream
May 12, 2024
In C#,
GetStreamingChatMessageContentsAsync
generates aIAsncEnumerable
ofStreamingChatMessageContent
Python, however, creates a
AsyncGenerator[list[StreamingChatMessageContent]
, which makes the code less obvious to write because you always have to get the first index[0]
.The text was updated successfully, but these errors were encountered: