Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
profikid committed Oct 14, 2024
1 parent ffa16ac commit 98d4081
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 134 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# generic-triggers

- just some integrations and building blocks for ai related
- just some integrations and building blocks for ai related
58 changes: 29 additions & 29 deletions integrations/cloudflare/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
});
69 changes: 37 additions & 32 deletions integrations/open-ai.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
})
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
};
}
});
52 changes: 26 additions & 26 deletions integrations/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '<no subject>');
logger.log(payload?.message || '<no body>');
const result = await resend.emails.send({
from: '[email protected]',
to: '[email protected]',
subject: payload.subject,
text: payload.message
});
export const textEmail = task({
id: 'send',
run: async (payload: any) => {
logger.log(payload?.subject || '<no subject>');
logger.log(payload?.message || '<no body>');
const result = await resend.emails.send({
from: '[email protected]',
to: '[email protected]',
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,
}
}
})
id: 'send',
run: async (payload: any) => {
logger.log('email payload', { payload });
const result = await resend.emails.send(payload);

return {
...result
};
}
});
22 changes: 11 additions & 11 deletions jobs/example.ts
Original file line number Diff line number Diff line change
@@ -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!",
}
},
});
return {
message: 'Hello, world!'
};
}
});
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
24 changes: 12 additions & 12 deletions transformers/mdToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '<no markdown>');
id: 'md2html',
run: async (payload: { markdown: string }) => {
// Log the input markdown text
logger.log(payload?.markdown || '<no 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
};
}
});
34 changes: 17 additions & 17 deletions trigger.config.ts
Original file line number Diff line number Diff line change
@@ -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']
});

0 comments on commit 98d4081

Please sign in to comment.