Skip to content

Function calling - FunctionCallingOptions doesn't work with OpenAiChatClient/AzureOpenAiChatClient #624

@tha2015

Description

@tha2015

Bug description
Function calling doesn't happen when using FunctionCallingOptions with OpenAiChatClient/AzureOpenAiChatClient

Environment
spring-ai-core-1.0.0-20240420.063719-118.jar
spring-ai-openai-1.0.0-20240420.063719-101.jar
spring-ai-azure-openai-1.0.0-20240420.063719-112.jar

Steps to reproduce

    // kotlin code
    val functionOptions = FunctionCallingOptions.builder()
        .withFunction("weatherFunction")
        .build()

    val response: ChatResponse = chatClient.call(
        Prompt(
            listOf(UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?")),
            functionOptions
        )
    )

    println(response.result.output.content)

OpenAiChatClient:

Sorry, as an AI, I don't have real-time capabilities to provide current weather updates. Please check a reliable weather forecasting website or app for the most accurate and up-to-date information.

AzureOpenAiChatClient:

Sorry, as an AI, I don't have real-time capabilities to provide current weather updates. Please check a reliable weather forecasting website or app for this information.

Expected behavior
Function calling should happen and response should contain function call result.

Analysis
AzureOpenAiChatClient.toAzureChatCompletionsOptions and OpenAiChatClient.createRequest don't use FunctionCallingOptions.getFunctions() for building the request, so function call didn't happen.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions