package com.lmx.project.until;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.theokanning.openai.OpenAiApi;
import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.service.OpenAiService;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.time.Duration;
import java.time.temporal.TemporalUnit;

import static com.theokanning.openai.service.OpenAiService.*;


public class CH {
    public static void main(String[] args) {
        ObjectMapper mapper = defaultObjectMapper();
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10809));
        OkHttpClient client = defaultClient("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",Duration.ofSeconds(5))
                .newBuilder()
                .proxy(proxy)
                .build();
        Retrofit retrofit = defaultRetrofit(client, mapper);
        OpenAiApi api = retrofit.create(OpenAiApi.class);
        OpenAiService service = new OpenAiService(api);

        CompletionRequest completionRequest = CompletionRequest.builder()
                .prompt("Somebody once told me the world is gonna roll me")
                .model("gpt-3")
                .echo(true)
                .build();
        service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
    }
}

com.theokanning.openai.completion.CompletionRequest.builder
[((1123, 1311), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((1123, 1286), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((1123, 1258), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((1123, 1226), 'com.theokanning.openai.completion.CompletionRequest.builder')]