Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Initial chatcall implementation #606

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[WIP] Initial chatcall implementation #606

wants to merge 1 commit into from

Conversation

markpollack
Copy link
Member

ChatCall encapsulates the steps of using ChatClient into an object named ChatCall. The ChatCall is created using a fluent-api, often registered as a Spring @Bean and then calling an execute method with some runtime parameters, such as the variables to substitute into the prompt.

Similar to Spring's RdbmsOperation interface, which models RDBMS operations as objects with the SqlCall implementation handling SQL-based calls like stored procedures or functions, and akin to JdbcClient offering a fluent API for JDBC operations, we introduce a helper class named ChatCall.

This class aims to streamline the process of gathering all necessary parameters for making calls to an AI model. It provides an easily shareable object encapsulating various options for calling an AI model and also helping to more easily chaining multiple calls to the model.

ChatCall chatCall = new ChatCall.Builder().
                                    .withChatClient(chatClient)
                                    .withSystemMessage("you are a helpful assistant") // not likely to change
                                    .withSystemMap(Map.of)  // likely to change at runtime
                                    .withUserMessage("tell me a joke")  // not likely to change
                                    .withUserMap(Map.of)  // likely to change at runtime
)                                   .withChatResponseMapper(chatResponseMapper) // not likely to change
                                    .withChatOptions(chatOptions)  // only likely to change during development
                                    .build()

String result = chatCall.execute(Map.of)  //User map
String result = chatCall.execute(Map.of, Map.of)  //User and System map
String result = chatCall.execute("user message", Map.of);
String result = chatCall.execute("user message", Map.of, "system message", Map.of);
<T> T result  = chatCall.execute("user message", Map.of, Class<T> returnType)
<T> T result  = chatCall.execute("user message", Map.of, Class<T> returnType, "system message", Map.of)

ChatResponse chatResponse = chatOperation.call()

open issues

  • Change execute signature to have T... as last parameter so don't have to specify MyDomainObject.class
  • Ensure support for returning collections of objects, need to use ParameterizedTypeReference

@markpollack markpollack changed the title Initial chatcall implementation [WIP] Initial chatcall implementation Apr 19, 2024
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.

None yet

1 participant