Skip to content

Conversation

@rpanackal
Copy link
Member

@rpanackal rpanackal commented Apr 7, 2025

Context

AI/ai-sdk-java-backlog#214.

  • quirky: PR num reversal of Ticket num

Feature scope:

  • New convenience class for tool definition OpenAiFunctionTool
  • Convenience for parsing arguments in OpenAiFunctionCall - getArgumentsAsObject() and more...
  • New setter for tools in request class - withOpenAiTools

Definition of Done

@rpanackal rpanackal self-assigned this Apr 7, 2025
@rpanackal rpanackal requested a review from Copilot April 7, 2025 16:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • foundation-models/openai/pom.xml: Language not supported
Comments suppressed due to low confidence (2)

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java:100

  • The new functionality for defining and using OpenAiFunctionTool is introduced here, but there are no corresponding tests to verify its integration into the chat completion request. Please add test cases that exercise this functionality.
final var openAiTool = new OpenAiFunctionTool("weather", WeatherMethod.Request.class)

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionRequest.java:308

  • [nitpick] The Javadoc comment includes extraneous text ('tool.getClass().getName()); }') that should be removed to improve clarity and professionalism.
tool.getClass().getName()); } Converts the request to a generated model class CreateChatCompletionRequest.

…verage for OpenAiFunctionCall and OpenAiFunctionTool
…nhance type safety

- OpenAiFunctionTool getter package private
- introduce getArgumentsAsObject(OpenAiFunctionTool)
@rpanackal rpanackal added the please-review Request to review a pull-request label Apr 8, 2025
Comment on lines +110 to +117
// 3. Execute the function
final OpenAiToolCall toolCall = assistantMessage.toolCalls().get(0);
if (!(toolCall instanceof OpenAiFunctionCall functionCall)) {
throw new IllegalArgumentException(
"Expected a function call, but got: %s".formatted(assistantMessage));
}
final WeatherMethod.Request arguments = functionCall.getArgumentsAsObject(weatherFunction);
final WeatherMethod.Response currentWeather = WeatherMethod.getCurrentWeather(arguments);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could put all of this into a convenience function of OpenAiChatCompletionResponse.
Because the client already has the reference to the OpenAiFunctionTool

// Send back the results, and the model will incorporate them into its final response.
// 4. Send back the results, and the model will incorporate them into its final response.
messages.add(assistantMessage);
messages.add(OpenAiMessage.tool(currentWeather.toString(), functionCall.getId()));
Copy link
Contributor

Choose a reason for hiding this comment

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

OpenAiMessage.tool(currentWeather.toString(), functionCall.getId()) could also be a convenience so th customer doesn't have to build it.

// 1. Define the function
final var weatherFunction =
new OpenAiFunctionTool("weather", WeatherMethod.Request.class)
.withDescription("Get the weather for the given location");
Copy link
Contributor

Choose a reason for hiding this comment

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

The is no use-case for OpenAiFunctionTool to be immutable.
Also, is there ever going to be another OpenAiTool that is not OpenAiFunctionTool?

@rpanackal rpanackal force-pushed the feat/openai/tool-definition-and-call-parsing branch from 36b0189 to 88aa9de Compare April 15, 2025 13:14
@rpanackal rpanackal removed the please-review Request to review a pull-request label Apr 15, 2025
@newtork newtork closed this Apr 17, 2025
@newtork
Copy link
Contributor

newtork commented Apr 17, 2025

closed in favor of #418

@CharlesDuboisSAP CharlesDuboisSAP deleted the feat/openai/tool-definition-and-call-parsing branch May 5, 2025 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants