1:创建springgoot项目,将添加chatgpt依赖    

        <dependency>
            <groupId>com.unfbx</groupId>
            <artifactId>chatgpt-java</artifactId>
            <version>1.0.12</version>
        </dependency>

2:创建连接参数

        log.info("prompt:{}",prompt);
        OpenAiService service = MyOpenAiService.getInstance();
        CompletionRequest.CompletionRequestBuilder builder = CompletionRequest.builder()
                .model(openAi.getModel())
                .prompt(prompt)
                .temperature(openAi.getTemperature())
                .maxTokens(1000)
                .topP(openAi.getTopP())
                .frequencyPenalty(openAi.getFrequencyPenalty())
                .presencePenalty(openAi.getPresencePenalty());
        if (!StringUtils.isEmpty(openAi.getStop())) {
            builder.stop(Arrays.asList(openAi.getStop().split(",")));
        }
        CompletionRequest completionRequest = builder.build();
        List<CompletionChoice> chs = service.createCompletion(completionRequest).getChoices();
        log.info("resoult:{}",chs);

3:如果没有秘钥KEY,责需要去申请一个。使用网站https://sms-activate.org/

小程序页面使用情况

体验或者需要源码请关注微信公众号: 

 

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐