-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: Yield FunctionResultContent in streaming chat completion path. Update tests. #9974
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
markwallace-microsoft
added
the
python
Pull requests for the Python Semantic Kernel
label
Dec 14, 2024
python/semantic_kernel/functions/kernel_function_from_prompt.py
Outdated
Show resolved
Hide resolved
Python Test Coverage Report •
Python Unit Test Overview
|
TaoChenOSU
reviewed
Dec 16, 2024
python/semantic_kernel/functions/kernel_function_from_prompt.py
Outdated
Show resolved
Hide resolved
...ts/unit/connectors/ai/azure_ai_inference/services/test_azure_ai_inference_chat_completion.py
Show resolved
Hide resolved
python/tests/unit/connectors/ai/google/google_ai/services/test_google_ai_chat_completion.py
Show resolved
Hide resolved
python/tests/unit/connectors/ai/google/vertex_ai/services/test_vertex_ai_chat_completion.py
Show resolved
Hide resolved
…tic-kernel into yield-func-result-content
TaoChenOSU
reviewed
Dec 17, 2024
python/samples/concepts/auto_function_calling/chat_gpt_api_function_calling.py
Show resolved
Hide resolved
eavanvalkenburg
approved these changes
Dec 17, 2024
TaoChenOSU
approved these changes
Dec 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Currently, if using SK's Python streaming chat completion path, we only yield the following content types:
StreamingChatMessageContent
andFunctionCallContent
. We are not yieldingFunctionResultContent
which is valuable for some use cases.Description
This PR updates the code to yield
FunctionResultContent
if it exists in the streaming chat completion path. When we merge the function call result content together into aStreamingChatMessageContent
type, we check if that message has items (which are of typeFunctionResultContent
) and if so, we yield them. The filter path still works because once they're yielded, we break out of the function calling loop.We need to include the
ai_model_id
if it exists for the current PromptExecutionSettings because if performing areduce
operation to add two streaming chat message chunks together, theStreamingChatMessageContent
that has the function results will break if theai_model_id
is not set (the error is thrown in the__add__
override for theStreamingChatMessageContent
.Some unit tests that cover function calling were also updated -- during the test, the test JSON function args were breaking in the
json.loads
call because they contained single quotes and not double. We're now sanitizing the args, just in case, so we don't break there.This PR fixes:
Contribution Checklist