Make it less repeatitive

This commit is contained in:
2025-06-19 10:52:45 +03:00
parent db70281d67
commit 81a159b9a4
3 changed files with 25 additions and 54 deletions

View File

@@ -26,7 +26,7 @@ export default defineEventHandler(async (event) => {
currentActivity, currentActivity,
previousActivities, previousActivities,
user: user!, user: user!,
}); }).catch((err) => [err]);
if (aiError) { if (aiError) {
throw createError({ throw createError({
statusCode: 500, statusCode: 500,

View File

@@ -51,44 +51,9 @@ const staticActivityTypes = [
"Golf", "Golf",
]; ];
const stringifyActivity = chain<[Activity], Activity, string>( const stringifyActivity = chain(
(activity) => { ({ activity, shouldKeepNames = false }) => {
if (movingActivityTypes.includes(activity.sport_type)) { const baseFieldsToOmit = [
return omit(activity, [
"laps",
"splits_metric",
"splits_standard",
"hide_from_home",
"available_zones",
"map",
"start_date_local",
"gear",
"stats_visibility",
"embed_token",
"name",
"description",
]);
}
if (staticActivityTypes.includes(activity.sport_type)) {
return omit(activity, [
"laps",
"splits_metric",
"splits_standard",
"hide_from_home",
"available_zones",
"map",
"start_date_local",
"gear",
"stats_visibility",
"embed_token",
"name",
"description",
"distance",
]);
}
return omit(activity, [
"laps", "laps",
"splits_metric", "splits_metric",
"splits_standard", "splits_standard",
@@ -99,9 +64,19 @@ const stringifyActivity = chain<[Activity], Activity, string>(
"gear", "gear",
"stats_visibility", "stats_visibility",
"embed_token", "embed_token",
"name", ];
"description",
]); const nameFields = shouldKeepNames ? [] : ["name", "description"];
if (movingActivityTypes.includes(activity.type)) {
return omit(activity, [...baseFieldsToOmit, ...nameFields]);
}
if (staticActivityTypes.includes(activity.type)) {
return omit(activity, [...baseFieldsToOmit, ...nameFields, "distance"]);
}
return omit(activity, [...baseFieldsToOmit, ...nameFields]);
}, },
(activity) => JSON.stringify(activity), (activity) => JSON.stringify(activity),
); );
@@ -128,22 +103,19 @@ export const createActivityContent = async ({
.when( .when(
({ highlight, activity }) => ({ highlight, activity }) =>
highlight === "Area Exploration" && highlight === "Area Exploration" &&
movingActivityTypes.includes(get(activity, "sport_type")), movingActivityTypes.includes(get(activity, "type")),
() => "Highlight places visited and areas explored.", () =>
"Focus on places visited and areas explored. Highlight any previous or new visits.",
) )
.with( .with(
{ highlight: "Athletic" }, { highlight: "Athletic" },
() => () =>
"Highlight athletic properties and performance. Highlight PR's as well but only if available.", "Highlight athletic properties and performance. Highlight PR's as well but only if available.",
) )
.with(
{ highlight: "Social" },
() =>
"Highlight social properties such as friend participation and activities.",
)
.with( .with(
{ highlight: "Mood" }, { highlight: "Mood" },
() => "Highlight how mood was swinging through the activity.", () =>
"Focus on how mood was swinging through the activity, ie I was feeling exhausted because of climb, I was feeling super happy on that descent!",
) )
.with({ highlight: "Conditions" }, () => "Highlight on weather conditions"); .with({ highlight: "Conditions" }, () => "Highlight on weather conditions");
@@ -153,7 +125,7 @@ export const createActivityContent = async ({
const prompt = ` const prompt = `
Generate a short title and a ${length}-lengthed description for my strava activity. Use my preferred language and unit system. Generate a short title and a ${length}-lengthed description for my strava activity. Use my preferred language and unit system.
Try to not exaggerate as I am using Strava often and I want my activites to be unique and easy to read. Don't say things like nothing too fancy or wild. Try to not exaggerate as I am using Strava often and I want my activites to be unique and easy to read. Don't use repeative language.
Use a little bit of ${tone} tone to make things less boring. Use a little bit of ${tone} tone to make things less boring.
${highlightInstructions} ${highlightInstructions}
Maybe comment if any interesting fact in comparison to previous activities. Maybe comment if any interesting fact in comparison to previous activities.
@@ -171,10 +143,10 @@ export const createActivityContent = async ({
In the end of the description, add "${promo}" translated to my language. In the end of the description, add "${promo}" translated to my language.
The activity data in json format from strava: The activity data in json format from strava:
${stringifyActivity(currentActivity)} ${stringifyActivity({ activity: currentActivity })}
The recent previous activities in json format: The recent previous activities in json format:
${previousActivities.map((a) => pick(a, ["distance", "moving_time", "total_elavation_gain", "type", "start_date", "average_speed", "average_watts", "average_heartrate", "max_heartrate"])).map(stringifyActivity)} ${previousActivities.map((activity) => stringifyActivity({ activity, shouldKeepNames: true }))}
`; `;
const [aiError, aiResponse] = await openai("/responses", { const [aiError, aiResponse] = await openai("/responses", {

View File

@@ -26,7 +26,6 @@ export const availableUnits = ["Imperial", "Metric"] as const;
export const availableHighlights = [ export const availableHighlights = [
"Athletic", "Athletic",
"Area Exploration", "Area Exploration",
"Social",
"Mood", "Mood",
"Conditions", "Conditions",
] as const; ] as const;