@@ -93,6 +93,19 @@ def self.preamble
9393 * Returns:
9494 * Array of { fragment: string, metadata: string }
9595 *
96+ * 4. upload
97+ * upload.create(filename, base_64_content): Uploads a file.
98+ * Parameters:
99+ * filename (string): Name of the file.
100+ * base_64_content (string): Base64 encoded file content.
101+ * Returns:
102+ * { id: number, short_url: string }
103+ *
104+ * 5. chain
105+ * chain.setCustomRaw(raw): Sets the body of the post and exist chain.
106+ * Parameters:
107+ * raw (string): raw content to add to post.
108+ *
96109 * Constraints
97110 *
98111 * Execution Time: ≤ 2000ms
@@ -236,6 +249,70 @@ def self.presets
236249 SCRIPT
237250 summary : "Get real-time stock quotes using AlphaVantage API" ,
238251 } ,
252+ {
253+ preset_id : "image_generation" ,
254+ name : "image_generation" ,
255+ description :
256+ "Generate images using the FLUX model from Black Forest Labs using together.ai" ,
257+ parameters : [
258+ {
259+ name : "prompt" ,
260+ type : "string" ,
261+ required : true ,
262+ description : "The text prompt for image generation" ,
263+ } ,
264+ {
265+ name : "seed" ,
266+ type : "number" ,
267+ required : false ,
268+ description : "Optional seed for random number generation" ,
269+ } ,
270+ ] ,
271+ script : <<~SCRIPT ,
272+ #{ preamble }
273+ const apiKey = "YOUR_KEY";
274+ const model = "black-forest-labs/FLUX.1.1-pro";
275+
276+ function invoke(params) {
277+ let seed = parseInt(params.seed);
278+ if (!(seed > 0)) {
279+ seed = Math.floor(Math.random() * 1000000) + 1;
280+ }
281+
282+ const prompt = params.prompt;
283+ const body = {
284+ model: model,
285+ prompt: prompt,
286+ width: 1024,
287+ height: 768,
288+ steps: 10,
289+ n: 1,
290+ seed: seed,
291+ response_format: "b64_json",
292+ };
293+
294+ const result = http.post("https://api.together.xyz/v1/images/generations", {
295+ headers: {
296+ "Authorization": `Bearer ${apiKey}`,
297+ "Content-Type": "application/json",
298+ },
299+ body: JSON.stringify(body),
300+ });
301+
302+ const base64Image = JSON.parse(result.body).data[0].b64_json;
303+ const image = upload.create("generated_image.png", base64Image);
304+ const raw = `\n \n `;
305+ chain.setCustomRaw(raw);
306+
307+ return { result: "Image generated successfully", seed: seed };
308+ }
309+
310+ function details() {
311+ return "Generates images based on a text prompt using the FLUX model.";
312+ }
313+ SCRIPT
314+ summary : "Generate image" ,
315+ } ,
239316 { preset_id : "empty_tool" , script : <<~SCRIPT } ,
240317 #{ preamble }
241318 function invoke(params) {
0 commit comments