|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.openai.proguard |
| 4 | + |
| 5 | +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef |
| 6 | +import com.openai.client.okhttp.OpenAIOkHttpClient |
| 7 | +import com.openai.core.jsonMapper |
| 8 | +import com.openai.models.chat.completions.ChatCompletion |
| 9 | +import com.openai.models.chat.completions.ChatCompletionAudio |
| 10 | +import com.openai.models.chat.completions.ChatCompletionContentPart |
| 11 | +import com.openai.models.chat.completions.ChatCompletionContentPartText |
| 12 | +import com.openai.models.chat.completions.ChatCompletionMessage |
| 13 | +import com.openai.models.chat.completions.ChatCompletionMessageToolCall |
| 14 | +import com.openai.models.chat.completions.ChatCompletionModality |
| 15 | +import com.openai.models.chat.completions.ChatCompletionTokenLogprob |
| 16 | +import com.openai.models.completions.CompletionUsage |
| 17 | +import org.assertj.core.api.Assertions.assertThat |
| 18 | +import org.junit.jupiter.api.BeforeAll |
| 19 | +import org.junit.jupiter.api.Test |
| 20 | + |
| 21 | +internal class ProGuardCompatibilityTest { |
| 22 | + |
| 23 | + companion object { |
| 24 | + |
| 25 | + @BeforeAll |
| 26 | + @JvmStatic |
| 27 | + fun setUp() { |
| 28 | + // To debug that we're using the right JAR. |
| 29 | + val jarPath = this::class.java.getProtectionDomain().codeSource.location |
| 30 | + println("JAR being used: $jarPath") |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + fun proguardRules() { |
| 36 | + val rulesFile = |
| 37 | + javaClass.classLoader.getResourceAsStream("META-INF/proguard/openai-java-core.pro") |
| 38 | + |
| 39 | + assertThat(rulesFile).isNotNull() |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + fun client() { |
| 44 | + val client = OpenAIOkHttpClient.builder().apiKey("My API Key").build() |
| 45 | + |
| 46 | + assertThat(client).isNotNull() |
| 47 | + assertThat(client.completions()).isNotNull() |
| 48 | + assertThat(client.chat()).isNotNull() |
| 49 | + assertThat(client.embeddings()).isNotNull() |
| 50 | + assertThat(client.files()).isNotNull() |
| 51 | + assertThat(client.images()).isNotNull() |
| 52 | + assertThat(client.audio()).isNotNull() |
| 53 | + assertThat(client.moderations()).isNotNull() |
| 54 | + assertThat(client.models()).isNotNull() |
| 55 | + assertThat(client.fineTuning()).isNotNull() |
| 56 | + assertThat(client.graders()).isNotNull() |
| 57 | + assertThat(client.vectorStores()).isNotNull() |
| 58 | + assertThat(client.webhooks()).isNotNull() |
| 59 | + assertThat(client.beta()).isNotNull() |
| 60 | + assertThat(client.batches()).isNotNull() |
| 61 | + assertThat(client.uploads()).isNotNull() |
| 62 | + assertThat(client.responses()).isNotNull() |
| 63 | + assertThat(client.evals()).isNotNull() |
| 64 | + assertThat(client.containers()).isNotNull() |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + fun chatCompletionRoundtrip() { |
| 69 | + val jsonMapper = jsonMapper() |
| 70 | + val chatCompletion = |
| 71 | + ChatCompletion.builder() |
| 72 | + .id("id") |
| 73 | + .addChoice( |
| 74 | + ChatCompletion.Choice.builder() |
| 75 | + .finishReason(ChatCompletion.Choice.FinishReason.STOP) |
| 76 | + .index(0L) |
| 77 | + .logprobs( |
| 78 | + ChatCompletion.Choice.Logprobs.builder() |
| 79 | + .addContent( |
| 80 | + ChatCompletionTokenLogprob.builder() |
| 81 | + .token("token") |
| 82 | + .addByte(0L) |
| 83 | + .logprob(0.0) |
| 84 | + .addTopLogprob( |
| 85 | + ChatCompletionTokenLogprob.TopLogprob.builder() |
| 86 | + .token("token") |
| 87 | + .addByte(0L) |
| 88 | + .logprob(0.0) |
| 89 | + .build() |
| 90 | + ) |
| 91 | + .build() |
| 92 | + ) |
| 93 | + .addRefusal( |
| 94 | + ChatCompletionTokenLogprob.builder() |
| 95 | + .token("token") |
| 96 | + .addByte(0L) |
| 97 | + .logprob(0.0) |
| 98 | + .addTopLogprob( |
| 99 | + ChatCompletionTokenLogprob.TopLogprob.builder() |
| 100 | + .token("token") |
| 101 | + .addByte(0L) |
| 102 | + .logprob(0.0) |
| 103 | + .build() |
| 104 | + ) |
| 105 | + .build() |
| 106 | + ) |
| 107 | + .build() |
| 108 | + ) |
| 109 | + .message( |
| 110 | + ChatCompletionMessage.builder() |
| 111 | + .content("content") |
| 112 | + .refusal("refusal") |
| 113 | + .addAnnotation( |
| 114 | + ChatCompletionMessage.Annotation.builder() |
| 115 | + .urlCitation( |
| 116 | + ChatCompletionMessage.Annotation.UrlCitation.builder() |
| 117 | + .endIndex(0L) |
| 118 | + .startIndex(0L) |
| 119 | + .title("title") |
| 120 | + .url("url") |
| 121 | + .build() |
| 122 | + ) |
| 123 | + .build() |
| 124 | + ) |
| 125 | + .audio( |
| 126 | + ChatCompletionAudio.builder() |
| 127 | + .id("id") |
| 128 | + .data("data") |
| 129 | + .expiresAt(0L) |
| 130 | + .transcript("transcript") |
| 131 | + .build() |
| 132 | + ) |
| 133 | + .functionCall( |
| 134 | + ChatCompletionMessage.FunctionCall.builder() |
| 135 | + .arguments("arguments") |
| 136 | + .name("name") |
| 137 | + .build() |
| 138 | + ) |
| 139 | + .addToolCall( |
| 140 | + ChatCompletionMessageToolCall.builder() |
| 141 | + .id("id") |
| 142 | + .function( |
| 143 | + ChatCompletionMessageToolCall.Function.builder() |
| 144 | + .arguments("arguments") |
| 145 | + .name("name") |
| 146 | + .build() |
| 147 | + ) |
| 148 | + .build() |
| 149 | + ) |
| 150 | + .build() |
| 151 | + ) |
| 152 | + .build() |
| 153 | + ) |
| 154 | + .created(0L) |
| 155 | + .model("model") |
| 156 | + .serviceTier(ChatCompletion.ServiceTier.AUTO) |
| 157 | + .systemFingerprint("system_fingerprint") |
| 158 | + .usage( |
| 159 | + CompletionUsage.builder() |
| 160 | + .completionTokens(0L) |
| 161 | + .promptTokens(0L) |
| 162 | + .totalTokens(0L) |
| 163 | + .completionTokensDetails( |
| 164 | + CompletionUsage.CompletionTokensDetails.builder() |
| 165 | + .acceptedPredictionTokens(0L) |
| 166 | + .audioTokens(0L) |
| 167 | + .reasoningTokens(0L) |
| 168 | + .rejectedPredictionTokens(0L) |
| 169 | + .build() |
| 170 | + ) |
| 171 | + .promptTokensDetails( |
| 172 | + CompletionUsage.PromptTokensDetails.builder() |
| 173 | + .audioTokens(0L) |
| 174 | + .cachedTokens(0L) |
| 175 | + .build() |
| 176 | + ) |
| 177 | + .build() |
| 178 | + ) |
| 179 | + .build() |
| 180 | + |
| 181 | + val roundtrippedChatCompletion = |
| 182 | + jsonMapper.readValue( |
| 183 | + jsonMapper.writeValueAsString(chatCompletion), |
| 184 | + jacksonTypeRef<ChatCompletion>(), |
| 185 | + ) |
| 186 | + |
| 187 | + assertThat(roundtrippedChatCompletion).isEqualTo(chatCompletion) |
| 188 | + } |
| 189 | + |
| 190 | + @Test |
| 191 | + fun chatCompletionContentPartRoundtrip() { |
| 192 | + val jsonMapper = jsonMapper() |
| 193 | + val chatCompletionContentPart = |
| 194 | + ChatCompletionContentPart.ofText( |
| 195 | + ChatCompletionContentPartText.builder().text("text").build() |
| 196 | + ) |
| 197 | + |
| 198 | + val roundtrippedChatCompletionContentPart = |
| 199 | + jsonMapper.readValue( |
| 200 | + jsonMapper.writeValueAsString(chatCompletionContentPart), |
| 201 | + jacksonTypeRef<ChatCompletionContentPart>(), |
| 202 | + ) |
| 203 | + |
| 204 | + assertThat(roundtrippedChatCompletionContentPart).isEqualTo(chatCompletionContentPart) |
| 205 | + } |
| 206 | + |
| 207 | + @Test |
| 208 | + fun chatCompletionModalityRoundtrip() { |
| 209 | + val jsonMapper = jsonMapper() |
| 210 | + val chatCompletionModality = ChatCompletionModality.TEXT |
| 211 | + |
| 212 | + val roundtrippedChatCompletionModality = |
| 213 | + jsonMapper.readValue( |
| 214 | + jsonMapper.writeValueAsString(chatCompletionModality), |
| 215 | + jacksonTypeRef<ChatCompletionModality>(), |
| 216 | + ) |
| 217 | + |
| 218 | + assertThat(roundtrippedChatCompletionModality).isEqualTo(chatCompletionModality) |
| 219 | + } |
| 220 | +} |
0 commit comments