From 98ea72302a8fc39d519caf2621d1e6888eef07e4 Mon Sep 17 00:00:00 2001 From: Mourits de Beer <31511766+ff137@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:37:21 +0200 Subject: [PATCH] Use opportunity link in result (#9) * add opportunityUrl to embedding metadata * get opportunityUrl from embedding result * :art: use backupUrl in case opportunityUrl is null --- src/xyz/didx/ai/AiHandler.scala | 16 +++++++++++----- src/xyz/didx/ai/embedding/EmbeddingHandler.scala | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/xyz/didx/ai/AiHandler.scala b/src/xyz/didx/ai/AiHandler.scala index 979d977..1e71245 100644 --- a/src/xyz/didx/ai/AiHandler.scala +++ b/src/xyz/didx/ai/AiHandler.scala @@ -91,11 +91,17 @@ object AiHandler { scribe.info(logResult) - val topMatch: TextSegment = embeddingMatch.embedded() - val id: String = topMatch.metadata("id") - val title: String = topMatch.metadata("title") - val organisation: String = topMatch.metadata("organisationName") - val url: String = s"https://app.yoma.world/opportunities/$id" + val topMatch: TextSegment = embeddingMatch.embedded() + val id: String = topMatch.metadata("id") + val title: String = topMatch.metadata("title") + val organisation: String = topMatch.metadata("organisationName") + val opportunityUrl: String = topMatch.metadata("opportunityURL") + + val backupUrl: String = s"https://app.yoma.world/opportunities/$id" + + val url = opportunityUrl match + case null | "null" | "" => backupUrl // handle potential edge cases + case _ => opportunityUrl val response: String = s"You might be interested in: $title, by $organisation. Here's a link to the opportunity page: $url" diff --git a/src/xyz/didx/ai/embedding/EmbeddingHandler.scala b/src/xyz/didx/ai/embedding/EmbeddingHandler.scala index 796f8ee..25778f4 100644 --- a/src/xyz/didx/ai/embedding/EmbeddingHandler.scala +++ b/src/xyz/didx/ai/embedding/EmbeddingHandler.scala @@ -80,6 +80,7 @@ object EmbeddingHandler { .add("id", opportunity.id) .add("title", opportunity.title) .add("organisationName", opportunity.organisationName) + .add("opportunityURL", opportunity.opportunityURL) val opportunityEmbeddingInput: String = removeSpecialCharacters(s"""${opportunity.title} ${opportunity.description}""")