Skip to content

Commit

Permalink
Change description
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jan 13, 2024
1 parent 2aa31ed commit be6f311
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[![javadoc](https://javadoc.io/badge2/io.github.stefanbratanov/jvm-openai/javadoc.svg)](https://javadoc.io/doc/io.github.stefanbratanov/jvm-openai)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=StefanBratanov_jvm-openai&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=StefanBratanov_jvm-openai)

A minimalistic unofficial JVM client for the [OpenAI API](https://platform.openai.com/docs/api-reference) written in Java
A minimalistic unofficial [OpenAI API](https://platform.openai.com/docs/api-reference) client for the JVM, written in
Java

## Add dependency

Expand All @@ -28,7 +29,7 @@ implementation("io.github.stefanbratanov:jvm-openai:${version}")
</dependency>
```

## Minimal sample
## Minimal example

```java
OpenAI openAI = OpenAI.newBuilder(System.getenv("OPENAI_API_KEY")).build();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ publishing {

pom {
name = "jvm-openai"
description = "A minimalistic JVM client for the OpenAI API written in Java"
description = "A minimalistic OpenAI API client for the JVM, written in Java"
url = "https://github.com/StefanBratanov/jvm-openai"
licenses {
license {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void testChatClient() {
.message(ChatMessage.userMessage("Who won the world series in 2020?"))
.build();

ChatCompletion response = chatClient.createChatCompletion(request);
ChatCompletion completion = chatClient.createChatCompletion(request);

assertThat(response.choices())
assertThat(completion.choices())
.hasSize(1)
.first()
.satisfies(choice -> assertThat(choice.message().content()).isNotNull());
Expand All @@ -53,7 +53,7 @@ public void testChatClient() {
.stream(true)
.build();

String joinedResponse =
String joinedContent =
chatClient
.streamChatCompletion(streamRequest)
.map(ChatCompletionChunk::choices)
Expand All @@ -65,32 +65,32 @@ public void testChatClient() {
.filter(Objects::nonNull)
.collect(Collectors.joining());

assertThat(joinedResponse).containsPattern("(?i)this is (a|the) test");
assertThat(joinedContent).containsPattern("(?i)this is (a|the) test");

// test streaming with a subscriber
CompletableFuture<String> joinedResponseFuture = new CompletableFuture<>();
CompletableFuture<String> joinedContentFuture = new CompletableFuture<>();
chatClient.streamChatCompletion(
streamRequest,
new StreamChatCompletionSubscriber() {
private final StringBuilder joinedResponse = new StringBuilder();
private final StringBuilder joinedContent = new StringBuilder();

@Override
public void onChunk(ChatCompletionChunk chunk) {
List<ChatCompletionChunk.Choice> choices = chunk.choices();
assertThat(choices).hasSize(1);
String content = choices.get(0).delta().content();
if (content != null) {
joinedResponse.append(content);
joinedContent.append(content);
}
}

@Override
public void onComplete() {
joinedResponseFuture.complete(joinedResponse.toString());
joinedContentFuture.complete(joinedContent.toString());
}
});

assertThat(joinedResponseFuture)
assertThat(joinedContentFuture)
.succeedsWithin(Duration.ofSeconds(30))
.asString()
.containsPattern("(?i)this is (a|the) test");
Expand Down

0 comments on commit be6f311

Please sign in to comment.