feat: [OpenAI] Full Tool call Convenience#396
Merged
Conversation
…nai/tool-call-execute
- Mostly tested - API design complete - Function Call as message content item - Non nullability of `Message.content()`
…nai/tool-call-execute
…nai/tool-call-execute
6 tasks
...dels/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiAssistantMessage.java
Show resolved
Hide resolved
...openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionRequest.java
Outdated
Show resolved
Hide resolved
...penai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionResponse.java
Show resolved
Hide resolved
sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java
Outdated
Show resolved
Hide resolved
sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java
Outdated
Show resolved
Hide resolved
sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java
Outdated
Show resolved
Hide resolved
sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java
Outdated
Show resolved
Hide resolved
sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OpenAiV2Test.java
Outdated
Show resolved
Hide resolved
…nai/tool-call-execute # Conflicts: # sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java
- OpenAiAssistantMessage().content() may contain empty list
- final keyword - remove redundant assertion - variable naming
…nai/tool-call-execute # Conflicts: # sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java
- final keyword - variable naming
CharlesDuboisSAP
requested changes
Apr 1, 2025
...penai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionResponse.java
Outdated
Show resolved
Hide resolved
...penai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionResponse.java
Outdated
Show resolved
Hide resolved
...on-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiToolMessage.java
Outdated
Show resolved
Hide resolved
...on-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiToolMessage.java
Outdated
Show resolved
Hide resolved
...on-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAIMessageTest.java
Outdated
Show resolved
Hide resolved
...ion-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java
Outdated
Show resolved
Hide resolved
...ion-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java
Outdated
Show resolved
Hide resolved
...ion-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java
Show resolved
Hide resolved
...dels/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiAssistantMessage.java
Outdated
Show resolved
Hide resolved
...dels/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiAssistantMessage.java
Show resolved
Hide resolved
...penai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionResponse.java
Outdated
Show resolved
Hide resolved
...n-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiFunctionCall.java
Outdated
Show resolved
Hide resolved
...dation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiMessage.java
Outdated
Show resolved
Hide resolved
...ation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiToolCall.java
Outdated
Show resolved
Hide resolved
…onmodels/openai/OpenAiChatCompletionResponse.java Co-authored-by: Charles Dubois <103174266+CharlesDuboisSAP@users.noreply.github.com>
javadoc and naming Co-authored-by: Charles Dubois <103174266+CharlesDuboisSAP@users.noreply.github.com>
...s/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientGeneratedTest.java
Outdated
Show resolved
Hide resolved
...s/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientGeneratedTest.java
Outdated
Show resolved
Hide resolved
CharlesDuboisSAP
approved these changes
Apr 3, 2025
newtork
reviewed
Apr 3, 2025
| @Nonnull String name; | ||
|
|
||
| /** The arguments for the function call, encoded as a JSON string. */ | ||
| @Nonnull String arguments; |
Contributor
There was a problem hiding this comment.
(Question)
I'm not sure. Is this supposed to be a convenience class? If yes, how is "String" convenient to access arguments "encoded as a JSON"? Or is it not expected to be consumed by users?
Member
Author
There was a problem hiding this comment.
I had only considered deserializing directly into the corresponding user provided model class. I ruled out this convenience because we don't have guarantees on their deserializability.
But, it is a possibility to parse it into a json object. We could provide this convenience. Is that what you are pointing at?
Member
Author
There was a problem hiding this comment.
As discussed, we would provide additional convenience in a separate PR.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
AI/ai-sdk-java-backlog#214.
Previously, ~70 lines of code needed to send tool message to OpenAi models.
Non-nullability guarantee of
OpenAiAssistantMessage().content()According to the spec, content in the LLM response is nullable. But our messaging convenience promise non-nullability.
The spec file contains a comment that informs content maybe null when tool calls are not (no mutual exclusivity).
Abstract away toolCalls as a content itemcontent will be OpenAiMessageContent with an empty.Feature scope:
OpenAiChatCompletionResponse) withgetMessage()OpenAiFunctionCalltoolCallsOpenAiChatCompletionRequest(List<OpenAiMessage>)added for better request creation with externally managed message listDefinition of Done
Error handling created / updated & covered by the tests aboveAligned changes with the JavaScript SDK