Skip to content

Commit 2a82192

Browse files
committed
Stub out description generation
1 parent b06490d commit 2a82192

File tree

4 files changed

+102
-21
lines changed

4 files changed

+102
-21
lines changed

packages/skin-database/cli.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { program } from "commander";
3333
import * as config from "./config";
3434
import { setHashesForSkin } from "./skinHash";
3535
import * as S3 from "./s3";
36+
import { generateDescription } from "./services/openAi";
3637

3738
async function withHandler(
3839
cb: (handler: DiscordEventHandler) => Promise<void>
@@ -125,12 +126,19 @@ program
125126
)
126127
.option("--reject", 'Give a skin a "rejected" review.')
127128
.option("--metadata", "Push metadata to the archive.")
129+
.option("--ai", "Use AI to generate a text description of the skin.")
128130
.action(
129131
async (
130132
md5,
131-
{ delete: del, deleteLocal, index, refresh, reject, metadata, hide }
133+
{ delete: del, deleteLocal, index, refresh, reject, metadata, hide, ai }
132134
) => {
133135
const ctx = new UserContext("CLI");
136+
if (ai) {
137+
const skin = await SkinModel.fromMd5Assert(ctx, md5);
138+
const description = await generateDescription(skin);
139+
console.log("Generated description for", skin.getFileName());
140+
console.log(description);
141+
}
134142
if (del) {
135143
await Skins.deleteSkin(md5);
136144
}

packages/skin-database/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"mastodon-api": "^1.3.0",
3232
"md5": "^2.2.1",
3333
"node-fetch": "^2.6.7",
34+
"openai": "^4.68.0",
3435
"polygon-clipping": "^0.15.3",
3536
"puppeteer": "^13.3.2",
3637
"sharp": "^0.31.3",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import fs from "node:fs";
2+
import SkinModel from "../data/SkinModel.js";
3+
import OpenAI from "openai";
4+
5+
const client = new OpenAI({
6+
apiKey: process.env["OPENAI_API_KEY"], // This is the default and can be omitted
7+
});
8+
9+
const prompt = `
10+
You are a digital preservationist being presented with a screenshot of a Winamp
11+
skin. Write a short description of the skin which can be used to index the skin
12+
for search retrieval.
13+
14+
Do not describe any features which are common to all Winamp skins, such as the
15+
set of UI elements visible.
16+
17+
The description should be concise and descriptive, and should not include any
18+
personal opinions or judgement. The description should be written in English and
19+
should be no longer than 200 characters.`;
20+
21+
const prompt2 = `"Identify thematic and stylistic details in this screenshot of a media player.
22+
Give a comma separated list of tags, and ignore the text."`;
23+
24+
export async function generateDescription(skin: SkinModel): Promise<string> {
25+
const response = await client.chat.completions.create({
26+
model: "gpt-4o-mini",
27+
messages: [
28+
{
29+
role: "user",
30+
content: [
31+
{ type: "text", text: prompt2 },
32+
{
33+
type: "image_url",
34+
image_url: {
35+
url: skin.getScreenshotUrl(),
36+
},
37+
},
38+
],
39+
},
40+
],
41+
});
42+
console.log(response.choices[0].message.content);
43+
return "Done";
44+
}

yarn.lock

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6210,7 +6210,7 @@
62106210
resolved "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz"
62116211
integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==
62126212

6213-
"@types/node-fetch@^2.1.6", "@types/node-fetch@^2.5.7":
6213+
"@types/node-fetch@^2.1.6", "@types/node-fetch@^2.5.7", "@types/node-fetch@^2.6.4":
62146214
version "2.6.11"
62156215
resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz"
62166216
integrity sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==
@@ -6242,6 +6242,13 @@
62426242
resolved "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz"
62436243
integrity sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==
62446244

6245+
"@types/node@^18.11.18":
6246+
version "18.19.56"
6247+
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.56.tgz#e46d3e6e5417d3b89e89ee6207d3c2cba7ad1ef2"
6248+
integrity sha512-4EMJlWwwGnVPflJAtM14p9eVSa6BOv5b92mCsh5zcM1UagNtEtrbbtaE6WE1tw2TabavatnwqXjlIpcAEuJJNg==
6249+
dependencies:
6250+
undici-types "~5.26.4"
6251+
62456252
"@types/normalize-package-data@^2.4.0":
62466253
version "2.4.4"
62476254
resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz"
@@ -7428,7 +7435,7 @@ agentkeepalive@^2.2.0:
74287435
resolved "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-2.2.0.tgz"
74297436
integrity sha512-TnB6ziK363p7lR8QpeLC8aMr8EGYBKZTpgzQLfqTs3bR0Oo5VbKdwKf8h0dSzsYrB7lSCgfJnMZKqShvlq5Oyg==
74307437

7431-
agentkeepalive@^4.1.3:
7438+
agentkeepalive@^4.1.3, agentkeepalive@^4.2.1:
74327439
version "4.5.0"
74337440
resolved "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz"
74347441
integrity sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==
@@ -14230,6 +14237,11 @@ fork-ts-checker-webpack-plugin@^6.5.0:
1423014237
semver "^7.3.2"
1423114238
tapable "^1.0.0"
1423214239

14240+
form-data-encoder@1.7.2:
14241+
version "1.7.2"
14242+
resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-1.7.2.tgz#1f1ae3dccf58ed4690b86d87e4f57c654fbab040"
14243+
integrity sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==
14244+
1423314245
form-data@^3.0.0:
1423414246
version "3.0.1"
1423514247
resolved "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz"
@@ -14262,6 +14274,14 @@ format@^0.2.0:
1426214274
resolved "https://registry.npmjs.org/format/-/format-0.2.2.tgz"
1426314275
integrity sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==
1426414276

14277+
formdata-node@^4.3.2:
14278+
version "4.4.1"
14279+
resolved "https://registry.yarnpkg.com/formdata-node/-/formdata-node-4.4.1.tgz#23f6a5cb9cb55315912cbec4ff7b0f59bbd191e2"
14280+
integrity sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==
14281+
dependencies:
14282+
node-domexception "1.0.0"
14283+
web-streams-polyfill "4.0.0-beta.3"
14284+
1426514285
formidable@^2.1.2:
1426614286
version "2.1.2"
1426714287
resolved "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz"
@@ -15114,16 +15134,11 @@ graphql-ws@5.12.1:
1511415134
resolved "https://registry.npmjs.org/graphql-ws/-/graphql-ws-5.12.1.tgz"
1511515135
integrity sha512-umt4f5NnMK46ChM2coO36PTFhHouBrK9stWWBczERguwYrGnPNxJ9dimU6IyOBfOkC6Izhkg4H8+F51W/8CYDg==
1511615136

15117-
graphql@^16.8.1:
15137+
graphql@16.8.1, graphql@^16.8.1, graphql@^16.9.0:
1511815138
version "16.8.1"
15119-
resolved "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz"
15139+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.1.tgz#1930a965bef1170603702acdb68aedd3f3cf6f07"
1512015140
integrity sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==
1512115141

15122-
graphql@^16.9.0:
15123-
version "16.9.0"
15124-
resolved "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz"
15125-
integrity sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==
15126-
1512715142
grats@^0.0.29:
1512815143
version "0.0.29"
1512915144
resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.29.tgz#9efe40da41a90c35c75f7ee4617290623a4318a9"
@@ -18641,7 +18656,7 @@ jss@10.10.0, jss@^10.0.0:
1864118656
object.assign "^4.1.4"
1864218657
object.values "^1.1.6"
1864318658

18644-
jszip@*, jszip@^3.1.5, jszip@^3.7.0:
18659+
jszip@*, jszip@^3.1.5, jszip@^3.10.1, jszip@^3.7.0:
1864518660
version "3.10.1"
1864618661
resolved "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz"
1864718662
integrity sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==
@@ -18651,16 +18666,6 @@ jszip@*, jszip@^3.1.5, jszip@^3.7.0:
1865118666
readable-stream "~2.3.6"
1865218667
setimmediate "^1.0.5"
1865318668

18654-
jszip@^3.10.1:
18655-
version "3.10.1"
18656-
resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.10.1.tgz#34aee70eb18ea1faec2f589208a157d1feb091c2"
18657-
integrity sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==
18658-
dependencies:
18659-
lie "~3.3.0"
18660-
pako "~1.0.2"
18661-
readable-stream "~2.3.6"
18662-
setimmediate "^1.0.5"
18663-
1866418669
junk@^3.1.0:
1866518670
version "3.1.0"
1866618671
resolved "https://registry.npmjs.org/junk/-/junk-3.1.0.tgz"
@@ -21065,6 +21070,11 @@ node-dir@^0.1.10:
2106521070
dependencies:
2106621071
minimatch "^3.0.2"
2106721072

21073+
node-domexception@1.0.0:
21074+
version "1.0.0"
21075+
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
21076+
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
21077+
2106821078
node-fetch@2.6.7:
2106921079
version "2.6.7"
2107021080
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
@@ -21661,6 +21671,19 @@ open@^8.0.9, open@^8.2.1, open@^8.4.0:
2166121671
is-docker "^2.1.1"
2166221672
is-wsl "^2.2.0"
2166321673

21674+
openai@^4.68.0:
21675+
version "4.68.0"
21676+
resolved "https://registry.yarnpkg.com/openai/-/openai-4.68.0.tgz#6390d35fbcb2b8dc15f93b1a8c87a65ebeac8636"
21677+
integrity sha512-cVH0WMKd4cColyorwqo+Gn08lN8LQ8uKLMfWXFfvnedrLq3lCH6lRd0Rd0XJRunyfgNve/L9E7uZLAii39NBkw==
21678+
dependencies:
21679+
"@types/node" "^18.11.18"
21680+
"@types/node-fetch" "^2.6.4"
21681+
abort-controller "^3.0.0"
21682+
agentkeepalive "^4.2.1"
21683+
form-data-encoder "1.7.2"
21684+
formdata-node "^4.3.2"
21685+
node-fetch "^2.6.7"
21686+
2166421687
opener@~1.4.0:
2166521688
version "1.4.3"
2166621689
resolved "https://registry.npmjs.org/opener/-/opener-1.4.3.tgz"
@@ -28665,6 +28688,11 @@ web-namespaces@^1.0.0:
2866528688
resolved "https://registry.npmjs.org/web-namespaces/-/web-namespaces-1.1.4.tgz"
2866628689
integrity sha512-wYxSGajtmoP4WxfejAPIr4l0fVh+jeMXZb08wNc0tMg6xsfZXj3cECqIK0G7ZAqUq0PP8WlMDtaOGVBTAWztNw==
2866728690

28691+
web-streams-polyfill@4.0.0-beta.3:
28692+
version "4.0.0-beta.3"
28693+
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz#2898486b74f5156095e473efe989dcf185047a38"
28694+
integrity sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==
28695+
2866828696
web-streams-polyfill@^3.2.1:
2866928697
version "3.3.3"
2867028698
resolved "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz"

0 commit comments

Comments
 (0)