From b01cdc58766b9d9bd6b732fa9113d3d77f11d6cf Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 14 Jan 2025 22:50:51 -0800 Subject: [PATCH] Hack on openAi tags --- packages/skin-database/cli.ts | 4 +++- packages/skin-database/services/openAi.ts | 19 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/skin-database/cli.ts b/packages/skin-database/cli.ts index 0fccbdd4..9810fbb9 100755 --- a/packages/skin-database/cli.ts +++ b/packages/skin-database/cli.ts @@ -136,8 +136,10 @@ program if (ai) { const skin = await SkinModel.fromMd5Assert(ctx, md5); const description = await generateDescription(skin); - console.log("Generated description for", skin.getFileName()); + console.log("Generated description for", await skin.getFileName()); + console.log("===================================="); console.log(description); + console.log("===================================="); } if (del) { await Skins.deleteSkin(md5); diff --git a/packages/skin-database/services/openAi.ts b/packages/skin-database/services/openAi.ts index e745efe3..19c097c7 100644 --- a/packages/skin-database/services/openAi.ts +++ b/packages/skin-database/services/openAi.ts @@ -18,10 +18,12 @@ The description should be concise and descriptive, and should not include any personal opinions or judgement. The description should be written in English and should be no longer than 200 characters.`; -const prompt2 = `"Identify thematic and stylistic details in this screenshot of a media player. -Give a comma separated list of tags, and ignore the text."`; +const prompt2 = `You are a staff digital preservationist working at the Internet Archive. +You have been tasked with identifying a comma separated list of tags for a Winamp skin to +be used for indexing purposes. Ignore the names of the tracks in the playlist.`; export async function generateDescription(skin: SkinModel): Promise { + const url = skin.getScreenshotUrl(); const response = await client.chat.completions.create({ model: "gpt-4o-mini", messages: [ @@ -29,16 +31,13 @@ export async function generateDescription(skin: SkinModel): Promise { role: "user", content: [ { type: "text", text: prompt2 }, - { - type: "image_url", - image_url: { - url: skin.getScreenshotUrl(), - }, - }, + { type: "image_url", image_url: { url } }, ], }, ], }); - console.log(response.choices[0].message.content); - return "Done"; + if (typeof response.choices[0].message.content !== "string") { + throw new Error("OpenAI response is not a string"); + } + return response.choices[0].message.content; }