From 7344f167edae95b2edd984ec1ae0ef5359d1e028 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 7 Feb 2024 22:19:39 +0000 Subject: [openai] fix: Strip the hash symbol from the tag if it exists --- workers/openai.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'workers') diff --git a/workers/openai.ts b/workers/openai.ts index cc23f700..893aa1af 100644 --- a/workers/openai.ts +++ b/workers/openai.ts @@ -65,10 +65,19 @@ async function inferTags( } try { - const tags = openAIResponseSchema.parse(JSON.parse(response)).tags; + let tags = openAIResponseSchema.parse(JSON.parse(response)).tags; logger.info( `[openai][${jobId}] Inferring tag for url "${link.url}" used ${chatCompletion.usage?.total_tokens} tokens and inferred: ${tags}`, ); + + // Sometimes the tags contain the hashtag symbol, let's strip them out if they do. + tags = tags.map((t) => { + if (t.startsWith("#")) { + return t.slice(1); + } + return t; + }); + return tags; } catch (e) { throw new Error( -- cgit v1.2.3-70-g09d2