publicstaticvoidmain(String[] args){ObjectMapper mapper =defaultObjectMapper();// 主机地址,端口号Proxy proxy =newProxy(Proxy.Type.HTTP,newInetSocketAddress("127.0.0.1", port));// 设置token(需自行申请),增加timeout字段,修改默认超时时间OkHttpClient client =defaultClient("your_token",Duration.ofSeconds(100)).newBuilder().proxy(proxy).build();Retrofit retrofit =defaultRetrofit(client, mapper);OpenAiApi api = retrofit.create(OpenAiApi.class);OpenAiService service =newOpenAiService(api);CompletionRequest completionRequest =CompletionRequest.builder()// 设置提示.prompt("Somebody once told me the world is gonna roll me")// 把ada模型修改为davinci模型,davinci模型功能更强大.model("text-davinci-003").echo(true)// 增加maxTokens字段,默认tokens数不够用.maxTokens(1000).build();System.out.println("--------");
service.createCompletion(completionRequest).getChoices().forEach(System.out::println);System.out.println("--------");}
运行,在控制台窗口中显示
CompletionChoice(text=Somebody once told me the world is gonna roll me
I ain't the sharpest tool in the shed
She was looking kind of dumb with her finger and her thumb
In the shape of an "L" on her forehead,index=0, logprobs=null, finish_reason=stop)