Closed RikJux closed 4 days ago
Thanks for reporting this issue. The function calling APIs have been recently refactored and improved. The changes should have handled both points you reported.
ChatCompletionMessage
in the OpenAiApi
class accepts both toolCallId
and toolCalls
. See: https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java#L519MessageType
enum uses tool
as the role name instead of function
. See: https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/chat/messages/MessageType.java#L51Can you confirm this issue is fixed?
@RikJux please let us know if this is resolved. Will close in 7 days if no response. Thank you.
Closing for now.
Description
There are two main issues with the current implementation of the
createRequest
method (see additional context below) in theOpenAiChatModel
class:Inability to Pass
tool_calls
ortool_call_id
: TheChatCompletionMessage
constructor called in thecreateRequest
method does not allow passingtool_calls
ortool_call_id
. These are always initialized asnull
.Discrepancy in Message Roles: There is a discrepancy between the
MessageType
enum inAbstractMessage
and theRole
enum in OpenAI messages.MessageType
inAbstractMessage
:Role
in OpenAI messages:This results in in an
java.lang.IllegalArgumentException
Steps to Reproduce
Passing a
FunctionMessage
in a prompt results in an error:Error:
Expected Behavior
The current implementation of the
createRequest
method does not cover all possible prompts that a user could define. The expected behavior should be as follows:Support for Tool Calls:
createRequest
method should allow passingtool_calls
andtool_call_id
to theChatCompletionMessage
constructor. This will enable the proper handling of tool calls within the chat prompt.Consistent Message Roles:
MessageType
enum inAbstractMessage
should be aligned with theRole
enum in OpenAI messages. Alternatively, a mapping should be provided to ensure that all message types are correctly translated and no errors occur due to missing enum constants.Additional Context
Here is the current implementation of the
createRequest
method: