Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/remove dotenv and add deps #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@mendable/firecrawl-js": "^1.8.1",
"@supabase/supabase-js": "^2.46.1",
"axios": "^1.7.9",
"dotenv": "^14.3.2",
"express": "^4.18.2",
"express-async-handler": "^1.2.0",
Expand All @@ -31,6 +32,8 @@
"playht": "^0.13.0",
"resend": "^4.0.1-alpha.0",
"together-ai": "^0.9.0",
"ts-node-dev": "^2.0.0"
"ts-node-dev": "^2.0.0",
"zod": "^3.24.1",
"zod-to-json-schema": "^3.24.1"
}
}
3 changes: 2 additions & 1 deletion src/controllers/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { scrapeSources } from '../services/scrapeSources';
import { getCronSources } from '../services/getCronSources';
import { generateDraft } from '../services/generateDraft';
import { sendDraft } from '../services/sendDraft';

export const handleCron = async (): Promise<void> => {
try {
const cronSources = await getCronSources();
Expand All @@ -13,4 +14,4 @@ export const handleCron = async (): Promise<void> => {
} catch (error) {
console.error(error);
}
}
}
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dotenv/config'
import { handleCron } from "./controllers/cron"
import cron from 'node-cron';
import dotenv from 'dotenv';

dotenv.config();

async function main() {
console.log(`Starting process to generate draft...`);
Expand All @@ -15,4 +13,4 @@ main();
//cron.schedule(`0 17 * * *`, async () => {
// console.log(`Starting process to generate draft...`);
// await handleCron();
//});
//});
11 changes: 2 additions & 9 deletions src/services/getCronSources.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@

import dotenv from 'dotenv';

dotenv.config();



export async function getCronSources() {
try {
console.log("Fetching sources...");
Expand All @@ -31,12 +25,11 @@ export async function getCronSources() {
{ identifier: "https://x.com/nickscamara_"},
{ identifier: "https://x.com/ericciarla"},
{ identifier: "https://www.firecrawl.dev/blog"},

];

return sources.map(source => source.identifier);
} catch (error) {
console.error(error);
}
}

}
9 changes: 3 additions & 6 deletions src/services/scrapeSources.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import FirecrawlApp from '@mendable/firecrawl-js';
import dotenv from 'dotenv';
import Together from 'together-ai';
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

dotenv.config();

const app = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });

// 1. Define the schema for your expected JSON
Expand Down Expand Up @@ -114,9 +111,9 @@ export async function scrapeSources(sources: string[]) {
{
role: "system",
content: `Today is ${currentDate}. Return only today's AI or LLM related story or post headlines and links in JSON format from the scraped content. They must be posted today. The format should be {"stories": [{"headline": "headline1", "link": "link1", "date_posted": "date1"}, ...]}.
If there are no AI or LLM stories from today, return {"stories": []}. The source link is ${source}.
If the story or post link is not absolute, prepend ${source} to make it absolute.
Return only pure JSON in the specified format (no extra text, no markdown, no \`\`\`).
If there are no AI or LLM stories from today, return {"stories": []}. The source link is ${source}.
If the story or post link is not absolute, prepend ${source} to make it absolute.
Return only pure JSON in the specified format (no extra text, no markdown, no \`\`\`).
Scraped Content:\n\n${scrapeResponse.markdown}\n\nJSON:`,
},
],
Expand Down
4 changes: 1 addition & 3 deletions src/services/sendDraft.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import axios from 'axios';
import dotenv from 'dotenv';
dotenv.config();

export async function sendDraft(draft_post: string) {
try {
Expand All @@ -21,4 +19,4 @@ export async function sendDraft(draft_post: string) {
console.log('error sending draft to Slack');
console.log(error);
}
}
}