Closed
Description
Hi,
I am using openAI and registered a function for setting SQL parameters. When I ask a related question such as : "draw a chart of top selling products" I can clearly see that, the function is being called. And I can see that expected parameters are also being set. But inside chatresponse object I can't see the values that I return from method.
import java.util.Arrays;
import java.util.function.Function;
public class GraphService implements Function<GraphService.Request, String> {
public record Request(String[] measure, String[] aggregation) {}
public String apply(Request request) {
System.out.println("function call");
StringBuffer sb = new StringBuffer();
sb.append("graph(");
sb.append(Arrays.toString(request.measure));
sb.append(Arrays.toString(request.aggregation));
sb.append(")");
return sb.toString();
}
}
Controller Class:
GetMapping("/ai/generate3")
public Map generate3(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
UserMessage userMessage = new UserMessage(message);
Prompt prompt = new Prompt(List.of(userMessage),OpenAiChatOptions
.builder().withFunctionCallbacks(List.of(new FunctionCallbackWrapper<>(
"DrawGraph", // name
"Draws graph by defining measure fields and aggregation fields."
+ " Possible fields are: AMOUNT which has id of 1, CREATE_BY which has id of 2,EMAIL "
+ " which has id of 3,LOCATION which has id of 4,ORDER_DATE which has id of 5,PRODUCT "
+ " which has id of 6,YEAR which has id of 7,LOCATION which has id of 8."
+ " I want you to pass the field ids only.", // function description
new GraphService()))).build());
ChatResponse resp = chatClient.call(prompt);
return Map.of("response", resp.getResult().getOutput().getContent());
}