-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { task, logger } from "@trigger.dev/sdk/v3"; | ||
import OpenAI from 'openai'; | ||
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 | ||
} | ||
} | ||
}); | ||
|
||
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})) | ||
|
||
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 | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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 | ||
}); | ||
|
||
return { | ||
...result, | ||
} | ||
} | ||
}) | ||
|
||
export const htmlEmail = 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, | ||
html: payload.message | ||
}); | ||
|
||
return { | ||
...result, | ||
} | ||
} | ||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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>'); | ||
|
||
// Convert the markdown to HTML | ||
const html = marked(payload.markdown); | ||
|
||
// Log the converted HTML text | ||
logger.log('HTML', {html}); | ||
|
||
return { | ||
html, | ||
}; | ||
}, | ||
}); |