Skip to content
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: Bug: While using AzureChatCompletion FunctionChoiceBehavior.Auto() returns error #10113

Closed
masterzdran opened this issue Jan 7, 2025 · 4 comments
Assignees
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel

Comments

@masterzdran
Copy link

Describe the bug
While calling chat_completion.get_chat_message_content(...) returns the following error:

 File "C:\root\playground\semantic-kernel\python\.venv\Lib\site-packages\semantic_kernel\connectors\ai\open_ai\services\open_ai_handler.py", line 99, in _send_completion_request    
    raise ServiceResponseException(
semantic_kernel.exceptions.service_exceptions.ServiceResponseException: ("<class 'semantic_kernel.connectors.ai.open_ai.services.azure_chat_completion.AzureChatCompletion'> service failed to complete the prompt", BadRequestError("Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: parallel_tool_calls', 'type': 'invalid_request_error', 'param': None, 'code': None}}"))

To Reproduce
from MS Learn example: https://learn.microsoft.com/en-us/semantic-kernel/get-started/quick-start-guide?pivots=programming-language-python

I have this code

async def main():
    # Initialize the kernel
    kernel = Kernel()

    # Add Azure OpenAI chat completion
    service_id = "default"
    kernel.add_service(
        AzureChatCompletion(
            service_id=service_id,
        ),
    )

    # Set the logging level for  semantic_kernel.kernel to DEBUG.
    setup_logging()
    logging.getLogger("kernel").setLevel(logging.DEBUG)

    # Add a plugin (the LightsPlugin class is defined below)
    plugin = kernel.add_plugin(parent_directory="./plugins/", plugin_name="LightsPlugin")

    execution_settings = AzureChatPromptExecutionSettings(
            function_choice_behavior=FunctionChoiceBehavior.Auto()
        )

    # Create a history of the conversation
    history = ChatHistory()

    # Initiate a back-and-forth chat
    userInput = None
    while True:
        # Collect user input
        userInput = input("User > ")

        # Terminate the loop if the user says "exit"
        if userInput == "exit":
            break

        # Add user input to the history
        history.add_user_message(userInput)
        chat_completion : AzureChatCompletion = kernel.get_service(type=ChatCompletionClientBase)

        # Get the response from the AI
        result = await chat_completion.get_chat_message_content(
            chat_history=history,
            settings=execution_settings,
            kernel=kernel,
            kernel_arguments=KernelArguments()
        )

        # Print the results
        print("Assistant > " + str(result))

        # Add the message from the agent to the chat history
        history.add_message(result)

# Run the main function
if __name__ == "__main__":
    asyncio.run(main())

Expected behavior
My expectation was to get a response from the "assistant" similar to the c# version.

Screenshots
If applicable, add screenshots to help explain your problem.

Platform

  • OS: Windows
  • IDE: VS Code
  • Language: Python
  • Source: Semantic Kernel 1.17.1, Python 3.11.9

Additional context

@masterzdran masterzdran added the bug Something isn't working label Jan 7, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel triage labels Jan 7, 2025
@github-actions github-actions bot changed the title Bug: While using AzureChatCompletion FunctionChoiceBehavior.Auto() returns error .Net: Bug: While using AzureChatCompletion FunctionChoiceBehavior.Auto() returns error Jan 7, 2025
@github-actions github-actions bot changed the title .Net: Bug: While using AzureChatCompletion FunctionChoiceBehavior.Auto() returns error Python: Bug: While using AzureChatCompletion FunctionChoiceBehavior.Auto() returns error Jan 7, 2025
@moonbox3 moonbox3 self-assigned this Jan 8, 2025
@moonbox3 moonbox3 removed .NET Issue or Pull requests regarding .NET code triage labels Jan 8, 2025
@moonbox3
Copy link
Contributor

moonbox3 commented Jan 8, 2025

Hi @masterzdran, you'll need to use an api version greater than 2024-09-01-preview (for context see: https://learn.microsoft.com/en-us/azure/ai-services/openai/api-version-deprecation#changes-between-2024-09-01-preview-and-2024-08-01-preview). Since Azure OpenAI's latest GA api version is 2024-10-21 is the latest (newer than our default). I created an issue to handle it on our side, so the default api version will work properly with parallel_tool_calls. #10117

@moonbox3
Copy link
Contributor

moonbox3 commented Jan 8, 2025

Here's a PR to upgrade the API VERSION. Please do try passing in (or configuring your .env file) to use this API version. #10118

Our tests are passing still with this update.

@masterzdran
Copy link
Author

@moonbox3

I appreaciate your feedback. I added the 2024-09-01-preview and it has the expected behaviour.

thanks!

@moonbox3
Copy link
Contributor

moonbox3 commented Jan 9, 2025

Closing issue.

@moonbox3 moonbox3 closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel
Projects
Status: No status
Development

No branches or pull requests

3 participants