diff --git a/README.md b/README.md index c0a4939..1878be1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # generic-triggers -- just some integrations and building blocks for ai related \ No newline at end of file +- just some integrations and building blocks for ai related diff --git a/integrations/cloudflare/images.ts b/integrations/cloudflare/images.ts index 932e00e..897f8bc 100644 --- a/integrations/cloudflare/images.ts +++ b/integrations/cloudflare/images.ts @@ -2,38 +2,38 @@ import { logger, task } from '@trigger.dev/sdk/v3'; import axios from 'axios'; export const uploadToCloudflareImages = task({ - id: 'uploadImage', - run: async (payload: { imageData: Buffer, fileName: string }) => { - const CLOUD_FLARE_API_TOKEN = process.env.CLOUDFLARE_API_TOKEN; // Your Cloudflare API Token - const ACCOUNT_ID = process.env.CLOUDFLARE_ACCOUNT_ID; // Your Cloudflare Account ID + id: 'uploadImage', + run: async (payload: { imageData: Buffer; fileName: string }) => { + const CLOUD_FLARE_API_TOKEN = process.env.CLOUDFLARE_API_TOKEN; // Your Cloudflare API Token + const ACCOUNT_ID = process.env.CLOUDFLARE_ACCOUNT_ID; // Your Cloudflare Account ID - // Log the input data - logger.log('Uploading image:', payload.fileName); + // Log the input data + logger.log('Uploading image:', payload.fileName); - try { - const formData = new FormData(); - formData.append('file', payload.imageData, payload.fileName); + try { + const formData = new FormData(); + formData.append('file', payload.imageData, payload.fileName); - const result = await axios.post( - `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/images/v1`, - formData, - { - headers: { - 'Authorization': `Bearer ${CLOUD_FLARE_API_TOKEN}`, - ...formData.getHeaders(), - }, - } - ); + const result = await axios.post( + `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/images/v1`, + formData, + { + headers: { + Authorization: `Bearer ${CLOUD_FLARE_API_TOKEN}`, + ...formData.getHeaders() + } + } + ); - logger.log('Image uploaded successfully', result.data); + logger.log('Image uploaded successfully', result.data); - return { - status: 'success', - data: result.data, - }; - } catch (error) { - logger.error('Failed to upload image', error); - throw new Error('Image upload failed'); - } - }, + return { + status: 'success', + data: result.data + }; + } catch (error) { + logger.error('Failed to upload image', error); + throw new Error('Image upload failed'); + } + } }); diff --git a/integrations/open-ai.ts b/integrations/open-ai.ts index 456945a..132f1dc 100644 --- a/integrations/open-ai.ts +++ b/integrations/open-ai.ts @@ -1,41 +1,46 @@ -import { task, logger } from "@trigger.dev/sdk/v3"; +import { task, logger } from '@trigger.dev/sdk/v3'; import OpenAI from 'openai'; -import { observeOpenAI } from "langfuse"; +import { observeOpenAI } from 'langfuse'; const openai = observeOpenAI(new OpenAI()); - export const DallE = task({ - id: 'dall-e-3', - run: async ({prompt}: { prompt: string}) =>{ - logger.log(prompt); - const imageResult = await openai.images.generate({ - model: "dall-e-3", - prompt - }); - logger.log('result', {output: imageResult.output }) - return { - ...imageResult, - result: imageResult.data[0].url - } - } + id: 'dall-e-3', + run: async ({ prompt }: { prompt: string }) => { + logger.log(prompt); + const imageResult = await openai.images.generate({ + model: 'dall-e-3', + prompt + }); + logger.log('result', { output: imageResult.output }); + return { + ...imageResult, + result: imageResult.data[0].url + }; + } }); export const openAi = task({ - id: 'open-ai', - run: async ({model, messages}: {model: string, messages: { role: string, content: string}[]}) =>{ - logger.log(model); - messages.forEach(message => logger.log(message.content, {message})) + id: 'open-ai', + run: async ({ + model, + messages + }: { + model: string; + messages: { role: string; content: string }[]; + }) => { + logger.log(model); + messages.forEach((message) => logger.log(message.content, { message })); - const request = { - model, - messages, - } - const result = await openai.chat.completions.create(request); - logger.log('Result from open ai', {result}); - return { - ...result, - result: result.choices[0].message.content - } - } -}) \ No newline at end of file + const request = { + model, + messages + }; + const result = await openai.chat.completions.create(request); + logger.log('Result from open ai', { result }); + return { + ...result, + result: result.choices[0].message.content + }; + } +}); diff --git a/integrations/resend.ts b/integrations/resend.ts index 543c937..bfa35b6 100644 --- a/integrations/resend.ts +++ b/integrations/resend.ts @@ -2,32 +2,32 @@ import { logger, task } from '@trigger.dev/sdk/v3'; import { Resend } from 'resend'; const resend = new Resend(process.env.RESEND_API_KEY); - export const textEmail = task({ - id: 'send', - run: async (payload: any) =>{ - logger.log(payload?.subject || ''); - logger.log(payload?.message || ''); - const result = await resend.emails.send({ - from: 'no-reply@profikid.nl', - to: 'profikid@gmail.com', - subject: payload.subject, - text: payload.message - }); +export const textEmail = task({ + id: 'send', + run: async (payload: any) => { + logger.log(payload?.subject || ''); + logger.log(payload?.message || ''); + const result = await resend.emails.send({ + from: 'no-reply@profikid.nl', + to: 'profikid@gmail.com', + subject: payload.subject, + text: payload.message + }); - return { - ...result, - } - } -}) + return { + ...result + }; + } +}); export const htmlEmail = task({ - id: 'send', - run: async (payload: any) =>{ - logger.log('email payload', {payload}) - const result = await resend.emails.send(payload); - - return { - ...result, - } - } -}) \ No newline at end of file + id: 'send', + run: async (payload: any) => { + logger.log('email payload', { payload }); + const result = await resend.emails.send(payload); + + return { + ...result + }; + } +}); diff --git a/jobs/example.ts b/jobs/example.ts index b6986d0..126b653 100644 --- a/jobs/example.ts +++ b/jobs/example.ts @@ -1,15 +1,15 @@ -import { logger, task, wait } from "@trigger.dev/sdk/v3"; +import { logger, task, wait } from '@trigger.dev/sdk/v3'; export const helloWorldTask = task({ - id: "hello-world", - maxDuration: 300, // 5 minutes - run: async (payload: any, { ctx }) => { - logger.log("Hello, world!", { payload, ctx }); + id: 'hello-world', + maxDuration: 300, // 5 minutes + run: async (payload: any, { ctx }) => { + logger.log('Hello, world!', { payload, ctx }); - await wait.for({ seconds: 5 }); + await wait.for({ seconds: 5 }); - return { - message: "Hello, world!", - } - }, -}); \ No newline at end of file + return { + message: 'Hello, world!' + }; + } +}); diff --git a/package.json b/package.json index 6834c0f..a10e589 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "dependencies": { - "@trigger.dev/sdk": "^3.0.12" - }, - "devDependencies": { - "@trigger.dev/build": "^3.0.12" - } + "dependencies": { + "@trigger.dev/sdk": "^3.0.12" + }, + "devDependencies": { + "@trigger.dev/build": "^3.0.12" + } } diff --git a/transformers/mdToHtml.ts b/transformers/mdToHtml.ts index 76709a1..1fb6206 100644 --- a/transformers/mdToHtml.ts +++ b/transformers/mdToHtml.ts @@ -2,19 +2,19 @@ import { logger, task } from '@trigger.dev/sdk/v3'; import { marked } from 'marked'; export const markdownToHtmlTask = task({ - id: 'md2html', - run: async (payload: { markdown: string }) => { - // Log the input markdown text - logger.log(payload?.markdown || ''); + id: 'md2html', + run: async (payload: { markdown: string }) => { + // Log the input markdown text + logger.log(payload?.markdown || ''); - // Convert the markdown to HTML - const html = marked(payload.markdown); + // Convert the markdown to HTML + const html = marked(payload.markdown); - // Log the converted HTML text - logger.log('HTML', {html}); + // Log the converted HTML text + logger.log('HTML', { html }); - return { - html, - }; - }, + return { + html + }; + } }); diff --git a/trigger.config.ts b/trigger.config.ts index 8eed673..7194f60 100644 --- a/trigger.config.ts +++ b/trigger.config.ts @@ -1,20 +1,20 @@ -import { defineConfig } from "@trigger.dev/sdk/v3"; +import { defineConfig } from '@trigger.dev/sdk/v3'; export default defineConfig({ - project: "proj_vsfwdoqfpholtehgarxa", - runtime: "node", - logLevel: "log", - // Set the maxDuration to 300 seconds for all tasks. See https://trigger.dev/docs/runs/max-duration - // maxDuration: 300, - retries: { - enabledInDev: true, - default: { - maxAttempts: 3, - minTimeoutInMs: 1000, - maxTimeoutInMs: 10000, - factor: 2, - randomize: true, - }, - }, - dirs: ["triggers"], + project: 'proj_vsfwdoqfpholtehgarxa', + runtime: 'node', + logLevel: 'log', + // Set the maxDuration to 300 seconds for all tasks. See https://trigger.dev/docs/runs/max-duration + // maxDuration: 300, + retries: { + enabledInDev: true, + default: { + maxAttempts: 3, + minTimeoutInMs: 1000, + maxTimeoutInMs: 10000, + factor: 2, + randomize: true + } + }, + dirs: ['triggers'] });