package com.theokanning.openai;

import com.theokanning.openai.completion.CompletionChoice;
import com.theokanning.openai.completion.CompletionRequest;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertFalse;


public class CompletionTest {

    String token = System.getenv("OPENAI_TOKEN");
    OpenAiService service = new OpenAiService(token);

    @Test
    void createCompletion() {
        CompletionRequest completionRequest = CompletionRequest.builder()
                .model("ada")
                .prompt("Somebody once told me the world is gonna roll me")
                .echo(true)
                .user("testing")
                .logitBias(new HashMap<>())
                .build();

        List<CompletionChoice> choices = service.createCompletion(completionRequest).getChoices();
        assertFalse(choices.isEmpty());
    }

    @Test
    void createCompletionDeprecated() {
        CompletionRequest completionRequest = CompletionRequest.builder()
                .prompt("Somebody once told me the world is gonna roll me")
                .echo(true)
                .user("testing")
                .build();

        List<CompletionChoice> choices = service.createCompletion("ada", completionRequest).getChoices();
        assertFalse(choices.isEmpty());
    }
}

com.theokanning.openai.completion.CompletionRequest.builder
[((522, 785), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((522, 760), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((522, 716), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((522, 683), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((522, 655), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((522, 579), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((1030, 1219), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((1030, 1194), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((1030, 1161), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((1030, 1133), 'com.theokanning.openai.completion.CompletionRequest.builder')]