feat: allow creating articles with marka
This commit is contained in:
@@ -4,6 +4,7 @@ import { OPENAI_API_KEY } from "@lib/env.ts";
|
||||
import { hashString } from "@lib/helpers.ts";
|
||||
import { createCache } from "@lib/cache.ts";
|
||||
import { recipeResponseSchema } from "@lib/recipeSchema.ts";
|
||||
import { articleMetadataSchema } from "./resource/articles.ts";
|
||||
|
||||
const openAI = OPENAI_API_KEY && new OpenAI({ apiKey: OPENAI_API_KEY });
|
||||
|
||||
@@ -32,8 +33,7 @@ export async function summarize(content: string) {
|
||||
{
|
||||
role: "user",
|
||||
content:
|
||||
`Please summarize the article in one sentence as short as possible: ${
|
||||
content.slice(0, 2000)
|
||||
`Please summarize the article in one sentence as short as possible: ${content.slice(0, 2000)
|
||||
}`,
|
||||
},
|
||||
],
|
||||
@@ -100,8 +100,7 @@ export async function createGenres(
|
||||
{
|
||||
role: "system",
|
||||
content:
|
||||
`you create some keywords that can be used in a recommendation system. The keywords are based on a ${type} description or title. If you do not know the title, take into account the description aswell. Create a range of keywords from very specific ones that describe the general vibe. ${
|
||||
title ? `The name of the ${type} is ${title}` : ""
|
||||
`you create some keywords that can be used in a recommendation system. The keywords are based on a ${type} description or title. If you do not know the title, take into account the description aswell. Create a range of keywords from very specific ones that describe the general vibe. ${title ? `The name of the ${type} is ${title}` : ""
|
||||
}. Return a list of around 20 keywords seperated by commas`,
|
||||
},
|
||||
{
|
||||
@@ -165,8 +164,7 @@ export const getMovieRecommendations = async (
|
||||
|
||||
${keywords}
|
||||
|
||||
The movies should be similar to but not include ${
|
||||
exclude.join(", ")
|
||||
The movies should be similar to but not include ${exclude.join(", ")
|
||||
} or remakes of that.
|
||||
|
||||
respond with a plain unordered list each item starting with the year the movie was released and then the title of the movie seperated by a -`,
|
||||
@@ -229,6 +227,28 @@ export async function extractRecipe(content: string) {
|
||||
return recipeResponseSchema.parse(completion.choices[0].message.parsed);
|
||||
}
|
||||
|
||||
export async function extractArticleMetadata(content: string) {
|
||||
if (!openAI) return;
|
||||
const completion = await openAI.beta.chat.completions.parse({
|
||||
model: "gpt-4o-2024-08-06",
|
||||
temperature: 0.1,
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content:
|
||||
"Extract the article information from the provided markdown. If the specified data is not available return undefined for the data values.",
|
||||
},
|
||||
{ role: "user", content },
|
||||
],
|
||||
response_format: zodResponseFormat(
|
||||
articleMetadataSchema,
|
||||
"article-meta-v2",
|
||||
),
|
||||
});
|
||||
|
||||
return articleMetadataSchema.parse(completion.choices[0].message.parsed);
|
||||
}
|
||||
|
||||
export async function transcribe(
|
||||
mp3Data: Uint8Array,
|
||||
): Promise<string | undefined> {
|
||||
|
||||
Reference in New Issue
Block a user