Skip to content

Commit

Permalink
release: 0.1.4
Browse files Browse the repository at this point in the history
release: 0.1.4
  • Loading branch information
devxb authored Jan 15, 2024
2 parents cc11517 + ec6f086 commit b370f46
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 123 deletions.
38 changes: 38 additions & 0 deletions src/main/java/net/teumteum/user/infra/ChatCompletionResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.teumteum.user.infra;

import java.util.List;

public record ChatCompletionResponse(
String id,
String object,
long created,
String model,
List<ChatCompletionResponse.Choice> choices,
ChatCompletionResponse.Usage usage,
String systemFingerprint
) {

public record Choice(
int index,
Message message,
Object logprobs,
String finishReason
) {

}

public record Message(
String role,
String content
) {

}

public record Usage(
int promptTokens,
int completionTokens,
int totalTokens
) {

}
}
24 changes: 20 additions & 4 deletions src/main/java/net/teumteum/user/infra/GptInterestQuestion.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ public BalanceQuestionResponse getBalanceGame(List<User> users) {
.header(HttpHeaders.AUTHORIZATION, "Bearer " + gptToken)
.exchangeToMono(response -> {
if (response.statusCode().is2xxSuccessful()) {
return response.bodyToMono(BalanceQuestionResponse.class);
return response.bodyToMono(ChatCompletionResponse.class);
}
return response.createError();
})
.map(response -> {
try {
return objectMapper.readValue(response.choices().get(0).message().content(),
BalanceQuestionResponse.class);
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
})
.retry(MAX_RETRY_COUNT)
.subscribeOn(Schedulers.fromExecutor(executorService))
.block(Duration.ofSeconds(5));
.block(Duration.ofSeconds(20));
}

@Override
Expand All @@ -63,13 +71,21 @@ public StoryQuestionResponse getStoryGame(List<User> users) {
.header(HttpHeaders.AUTHORIZATION, "Bearer " + gptToken)
.exchangeToMono(response -> {
if (response.statusCode().is2xxSuccessful()) {
return response.bodyToMono(StoryQuestionResponse.class);
return response.bodyToMono(ChatCompletionResponse.class);
}
return response.createError();
})
.map(response -> {
try {
return objectMapper.readValue(response.choices().get(0).message().content(),
StoryQuestionResponse.class);
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
})
.retry(MAX_RETRY_COUNT)
.subscribeOn(Schedulers.fromExecutor(executorService))
.block(Duration.ofSeconds(5));
.block(Duration.ofSeconds(20));
}

private String parseInterests(List<User> users) {
Expand Down
119 changes: 0 additions & 119 deletions src/test/java/net/teumteum/user/infra/GptInterestQuestionTest.java

This file was deleted.

0 comments on commit b370f46

Please sign in to comment.