chatgpt-spring-boot-starter icon indicating copy to clipboard operation
chatgpt-spring-boot-starter copied to clipboard

Can you change your code, let model name as function parameter?

Open princepride opened this issue 1 year ago • 1 comments

For example: `@Autowired private ChatgptService chatgptService;

public void testMultiChat(){ List<MultiChatMessage> messages = Arrays.asList( new MultiChatMessage("system","You are a helpful assistant."), new MultiChatMessage("user","Who won the world series in 2020?"), new MultiChatMessage("assistant","The Los Angeles Dodgers won the World Series in 2020."), new MultiChatMessage("user","Where was it played?")); String model = "gpt-4"; String responseMessage = chatgptService.multiChat(messages, model); System.out.print(responseMessage); //The 2020 World Series was played at Globe Life Field in Arlington, Texas. }`

princepride avatar Nov 03 '23 02:11 princepride

chatgpt-spring-boot-starter-1.0.4.zip

implementation files('chatgpt-spring-boot-starter-1.0.4.jar')

I have only updated the multichat component for now, but I've built one myself while waiting for the author to update the codes.

Minor adjustments include using ChatRole for defining roles, such as ChatRole.SYSTEM, ChatRole.USER, and ChatRole.ASSISTANT.

    public String generate(String yay) {
        var multiChatRequest = MultiChatRequest.builder()
                .maxTokens(128)
                .model("gpt-3.5-turbo-1106")
                .responseFormat("json_object")
                .build();

        var messages = List.of(
                new MultiChatMessage(ChatRole.SYSTEM, "Return as json, bark"),
                new MultiChatMessage(ChatRole.ASSISTANT, "woof?"),
                new MultiChatMessage(ChatRole.USER, yay));

        return chatgptService.multiChat(messages, multiChatRequest);
    }

Alfex4936 avatar Nov 22 '23 14:11 Alfex4936