@jutge.org/toolkit 4.2.38 → 4.2.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +484 -420
- package/package.json +2 -1
- package/toolkit/generate.ts +30 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jutge.org/toolkit",
|
|
3
3
|
"description": "Toolkit to prepare problems for Jutge.org",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.39",
|
|
5
5
|
"homepage": "https://jutge.org",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Jutge.org",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"pretty-ms": "^9.3.0",
|
|
85
85
|
"radash": "^12.1.1",
|
|
86
86
|
"semver": "^7.7.3",
|
|
87
|
+
"sharp": "^0.34.5",
|
|
87
88
|
"terminal-link": "^5.0.0",
|
|
88
89
|
"tree-node-cli": "^1.6.0",
|
|
89
90
|
"yaml": "^2.8.2",
|
package/toolkit/generate.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Argument, Command } from '@commander-js/extra-typings'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import sharp from 'sharp'
|
|
2
4
|
import { createProblemWithJutgeAI } from '../lib/create-with-jutgeai'
|
|
5
|
+
import { complete } from '../lib/aiclient'
|
|
3
6
|
import { languageKeys, languageNames, proglangKeys, proglangNames } from '../lib/data'
|
|
4
7
|
import {
|
|
5
8
|
addAlternativeSolution,
|
|
@@ -10,6 +13,7 @@ import {
|
|
|
10
13
|
import { newProblem } from '../lib/problem'
|
|
11
14
|
import { settings } from '../lib/settings'
|
|
12
15
|
import tui from '../lib/tui'
|
|
16
|
+
import { writeText } from '../lib/utils'
|
|
13
17
|
import { getLoggedInJutgeClient } from '../lib/login'
|
|
14
18
|
|
|
15
19
|
export const generateCmd = new Command('generate')
|
|
@@ -153,7 +157,7 @@ generateCmd
|
|
|
153
157
|
if (all || efficiency) await generateTestCasesGenerator(jutge, model, problem, output, 'efficiency')
|
|
154
158
|
})
|
|
155
159
|
})
|
|
156
|
-
|
|
160
|
+
|
|
157
161
|
generateCmd
|
|
158
162
|
.command('award.png')
|
|
159
163
|
.summary('Generate award.png using JutgeAI')
|
|
@@ -179,15 +183,25 @@ The new image will be saved as award.png in the problem directory, overriding an
|
|
|
179
183
|
.argument('[prompt]', 'prompt to generate the image', '')
|
|
180
184
|
|
|
181
185
|
.action(async (prompt, { directory, model }) => {
|
|
186
|
+
const jutge = await getLoggedInJutgeClient()
|
|
182
187
|
const output = join(directory, 'award.png')
|
|
183
188
|
const problem = await newProblem(directory)
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
let imagePrompt = prompt.trim()
|
|
190
|
+
if (imagePrompt === '') {
|
|
191
|
+
imagePrompt = 'A colorful award on a white background'
|
|
186
192
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
193
|
+
await tui.section('Generating award image', async () => {
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call -- generated API client
|
|
195
|
+
const download = await jutge.instructor.jutgeai.createImage({
|
|
196
|
+
model,
|
|
197
|
+
label: 'award',
|
|
198
|
+
prompt: imagePrompt,
|
|
199
|
+
size: '1024x1024',
|
|
200
|
+
})
|
|
201
|
+
await sharp(Buffer.from(download.data)).resize(512, 512).toFile(output)
|
|
202
|
+
await tui.image(output, 20, 10)
|
|
203
|
+
tui.success(`Added ${output}`)
|
|
204
|
+
})
|
|
191
205
|
})
|
|
192
206
|
|
|
193
207
|
generateCmd
|
|
@@ -217,11 +231,14 @@ The new message will be saved as award.html in the problem directory, overriding
|
|
|
217
231
|
.option('-m, --model <model>', 'AI model to use', settings.defaultModel)
|
|
218
232
|
|
|
219
233
|
.action(async (prompt, { directory, model }) => {
|
|
234
|
+
const jutge = await getLoggedInJutgeClient()
|
|
220
235
|
const output = join(directory, 'award.html')
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
tui.
|
|
224
|
-
|
|
225
|
-
|
|
236
|
+
const systemPrompt =
|
|
237
|
+
'You generate short textual award messages shown when a user solves a problem. Output only the message text, no markdown code blocks or explanation. If you like, use a famous quote by a famous person. In this case, use the name of the person in the message.'
|
|
238
|
+
await tui.section('Generating award message', async () => {
|
|
239
|
+
const message = await complete(jutge, model, 'award', systemPrompt, prompt)
|
|
240
|
+
tui.print(message)
|
|
241
|
+
await writeText(output, message)
|
|
242
|
+
tui.success(`Added ${output}`)
|
|
243
|
+
})
|
|
226
244
|
})
|
|
227
|
-
*/
|