Skip to content

Commit

Permalink
save message body and username when handling invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
jade-vogt committed Sep 17, 2023
1 parent 0ff7cc6 commit 93f7c3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>best.tigers</groupId>
<artifactId>tigersbot</artifactId>
<version>1.3.4</version>
<version>1.3.5</version>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/best/tigers/tigersbot/handlers/GptHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,10 @@ public void handle(Message message) {
return;
}
if (message.text().startsWith("/gpt4 ")) {
var span = ElasticApm.currentTransaction().startSpan("external", "openai", "chatcompletion");
try {
showTypingIndicator();
var prompt = message.text().split("/gpt4 ")[1].strip();
var completion = completionService.getAdvancedCompletion(prompt, message.from().username());
sendReplyMessage(message, completion);
} catch (Throwable e) {
span.captureException(e);
throw e;
} finally {
span.end();
}
showTypingIndicator();
var prompt = message.text().split("/gpt4 ")[1].strip();
var completion = completionService.getAdvancedCompletion(prompt, message.from().username());
sendReplyMessage(message, completion);
return;
}
if (message.text().startsWith("/pissed ")) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/best/tigers/tigersbot/services/BotService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private void processUpdate(Update update) {
try (Scope scope = transaction.activate()){
transaction.setName(handler.getClass().getSimpleName());
transaction.setType(Transaction.TYPE_REQUEST);
transaction.setLabel("username", message.from().username());
transaction.setLabel("message_body", message.text());
handler.handle(message);
} catch (Throwable e) {
transaction.captureException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ public String getImage(String query) {
var span = ElasticApm.currentTransaction().startSpan("external", "googleimages", "query");
try {
span.setName("Get Google Image");
span.setLabel("image_query", query);
var conn = getConnection(query);
if (conn == null) {
return "";
}
return getImageLink(conn);
String imageLink = getImageLink(conn);
span.setLabel("image_link", imageLink);
return imageLink;
} catch (Throwable e) {
span.captureException(e);
throw e;
Expand Down

0 comments on commit 93f7c3d

Please sign in to comment.