1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { getOpenAiResponse } from "https://esm.town/v/thomasatflexos/getOpenAiResponse";
import { getRelevantContent } from "https://esm.town/v/thomasatflexos/getRelevantContent";
import process from "node:process";
export let createRelevantComment = async (
req: express.Request,
res: express.Response,
) => {
const content = req?.body?.content;
const url = req?.body?.url;
if (!content || !url) {
res.status(400)
.json({
message: "The content and url parameter is required for this end point",
});
}
const { createClient } = await import(
"https://esm.sh/@supabase/supabase-js@2"
);
const supabase = createClient(
process.env.supabaseURL,
process.env.supabaseKey,
);
// Query from the database to see if this link already exists
const { data, error } = await supabase
.from("linkedin_seedings")
.select()
.eq("link", url)
.limit(1);
if (error) {
throw error;
}
// If it does, then no more processing
if (data.length > 0) {
res.status(200).json({
message: "This link already exists in the database",
});
}
// Otherwise, start processing this new link
// First, retrieve documents in the database relevant to the post content
let relevantContent = await getRelevantContent(content);
let context = "";
let link = "";
// Prepare the context from relevant documents
for (let i = 0; i < relevantContent.length; i++) {
context += "\n" + relevantContent[i].pageContent;
link += "\n" + relevantContent[i].metadata.source;
}
// Inject relenvat context into our prompt
let PROMPT =
`You are a passionate advocate of remote work, and you're helping to make meaningful comments to a Linkedin post about remote work.
\n I will provide you with the text of a Linkedin post and some relevant context.
\n Here's the Linkedin post:
\n """${content}"""
\n Here's the context:
\n """${context}"""
\n IF you think that the Linkedin post is about new job opportunities, just respond with the text "N/A" and stop immediately. Do not respond any further.
\n ELSE IF you think the Linkdedin post is not about new job opportunities, please proceed to a meaningful comment to the provided Linkedin post based on the provided context and include ${link} in the post in a clever and relevant way, (don't be too
let finalResponse = await getOpenAiResponse(PROMPT);
const { data1, error1 } = await supabase
.from("linkedin_seedings")
.insert({ link: url, content: content, comment: finalResponse });
if (error1) {
throw error1;
}
res.status(200).json({
message: finalResponse,
});
};