diff options
| author | MohamedBassem <me@mbassem.com> | 2024-02-07 22:19:39 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-02-07 22:19:39 +0000 |
| commit | 7344f167edae95b2edd984ec1ae0ef5359d1e028 (patch) | |
| tree | 721f710c4c897016b9022f07fe9eac4a639680de | |
| parent | cdc05f85a6dc676e8af1227a56f65d6452488d82 (diff) | |
| download | karakeep-7344f167edae95b2edd984ec1ae0ef5359d1e028.tar.zst | |
[openai] fix: Strip the hash symbol from the tag if it exists
| -rw-r--r-- | workers/openai.ts | 11 |
1 files changed, 10 insertions, 1 deletions
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( |
