JAVA 集成 chatGPT

1.文档地址:

https://platform.openai.com/docs/introduction
下载demo:

JAVA 集成 chatGPT_第1张图片
2. pom集成包

 
        com.theokanning.openai-gpt3-java
        client
        0.9.0
 

3.domo 例子:

  public static void main(String[] args) {
    OpenAiService openAiService = new OpenAiService("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");
    CompletionRequest completionRequest = CompletionRequest.builder()
            .prompt("中印边境自卫反击战谁获胜了?").model(openAiService.listModels().get(1).id).echo(true).build();
    CompletionResult completionResult = openAiService.createCompletion(completionRequest);
    completionResult.getChoices().forEach(System.out::println);
}

4.OpenAiService获取model集合

 public List listModels() {
    return api.listModels().blockingGet().data;
}

5.运行需要注意jdk版本

你可能感兴趣的:(java,java,开发语言)