-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00fb801
commit 2308414
Showing
6 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/test/java/io/github/stefanbratanov/jvm/openai/DeserializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.stefanbratanov.jvm.openai; | ||
|
||
import static io.github.stefanbratanov.jvm.openai.TestUtil.getStringResource; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class DeserializationTest { | ||
|
||
private final ObjectMapper objectMapper = ObjectMapperSingleton.getInstance(); | ||
|
||
@Test | ||
public void deserializesChatCompletionChunk() throws JsonProcessingException { | ||
ChatCompletionChunk result = | ||
objectMapper.readValue( | ||
getStringResource("/chat-completion-chunk.json"), ChatCompletionChunk.class); | ||
|
||
assertThat(result).isNotNull(); | ||
assertThat(result.id()).isEqualTo("chatcmpl-xyz"); | ||
assertThat(result.choices()) | ||
.hasSize(1) | ||
.first() | ||
.satisfies( | ||
choice -> { | ||
assertThat(choice.index()).isZero(); | ||
assertThat(choice.delta().role()).isEqualTo("assistant"); | ||
assertThat(choice.delta().content()).isEqualTo(""); | ||
assertThat(choice.finishReason()).isNull(); | ||
}); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/java/io/github/stefanbratanov/jvm/openai/OpenAIAssistantsApiIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/test/java/io/github/stefanbratanov/jvm/openai/OpenAIIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/java/io/github/stefanbratanov/jvm/openai/TestUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.github.stefanbratanov.jvm.openai; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Objects; | ||
|
||
public class TestUtil { | ||
|
||
public static Path getTestResource(String resource) { | ||
try { | ||
return Paths.get(Objects.requireNonNull(TestUtil.class.getResource(resource)).toURI()); | ||
} catch (URISyntaxException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
public static String getStringResource(String resource) { | ||
try { | ||
return Files.readString(getTestResource(resource)); | ||
} catch (IOException ex) { | ||
throw new UncheckedIOException(ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": "chatcmpl-xyz", | ||
"object": "chat.completion.chunk", | ||
"created": 1711604346, | ||
"model": "gpt-4-0613", | ||
"system_fingerprint": null, | ||
"choices": [ | ||
{ | ||
"index": 0, | ||
"delta": { | ||
"role": "assistant", | ||
"content": "" | ||
}, | ||
"logprobs": null, | ||
"finish_reason": null | ||
} | ||
] | ||
} |