Skip to content

feat: [OpenAI] Full Tool call Convenience#396

Merged
rpanackal merged 38 commits intomainfrom
feat/openai/tool-call-execute
Apr 3, 2025
Merged

feat: [OpenAI] Full Tool call Convenience#396
rpanackal merged 38 commits intomainfrom
feat/openai/tool-call-execute

Conversation

@rpanackal
Copy link
Member

@rpanackal rpanackal commented Mar 26, 2025

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()

  • Motivation
    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).
  • Proposal: Abstract away toolCalls as a content item content will be OpenAiMessageContent with an empty.

Feature scope:

  • Get assistant message from chat response (OpenAiChatCompletionResponse) with getMessage()
  • New class to capture Function type tool calls suggested by LLM - OpenAiFunctionCall
  • Assistant messages has a new field for toolCalls
  • OpenAiChatCompletionRequest(List<OpenAiMessage>) added for better request creation with externally managed message list

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Aligned changes with the JavaScript SDK
  • Documentation updated
  • Release notes updated

@rpanackal rpanackal self-assigned this Mar 27, 2025
@rpanackal rpanackal changed the base branch from main to test/openai/tool-call-execute March 27, 2025 14:25
…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
@rpanackal rpanackal added the please-review Request to review a pull-request label Mar 31, 2025
rpanackal and others added 2 commits April 1, 2025 10:02
…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>
@rpanackal rpanackal removed the please-review Request to review a pull-request label Apr 1, 2025
@rpanackal rpanackal added the please-review Request to review a pull-request label Apr 1, 2025
@rpanackal rpanackal added please-review Request to review a pull-request and removed please-review Request to review a pull-request labels Apr 1, 2025
@Nonnull String name;

/** The arguments for the function call, encoded as a JSON string. */
@Nonnull String arguments;
Copy link
Contributor

@newtork newtork Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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?

Copy link
Member Author

@rpanackal rpanackal Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

@rpanackal rpanackal Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we would provide additional convenience in a separate PR.

@rpanackal rpanackal merged commit f7ebcad into main Apr 3, 2025
6 checks passed
@rpanackal rpanackal deleted the feat/openai/tool-call-execute branch April 3, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

please-review Request to review a pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants