Take previous activities into consideration
This commit is contained in:
@@ -26,12 +26,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
const strava = await useStrava(session.user.id);
|
const strava = await useStrava(session.user.id);
|
||||||
|
|
||||||
const activity = await strava!<any>(`/activities/${activityId}`);
|
const currentActivity = await strava!<any>(`/activities/${activityId}`);
|
||||||
|
const [, ...previousActivities] = await strava!<any[]>(`/activities`);
|
||||||
|
|
||||||
const [aiError, stravaRequestBody] = await createActivityContent(
|
const [aiError, stravaRequestBody] = await createActivityContent({
|
||||||
activity,
|
currentActivity,
|
||||||
user!,
|
previousActivities,
|
||||||
);
|
user: user!,
|
||||||
|
});
|
||||||
if (aiError) {
|
if (aiError) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
const strava = await useStrava(body.owner_id);
|
const strava = await useStrava(body.owner_id);
|
||||||
|
|
||||||
const activity = await strava!<any>(`/activities/${body.object_id}`);
|
const currentActivity = await strava!<any>(`/activities/${body.object_id}`);
|
||||||
|
const [, ...previousActivities] = await strava!<any[]>(`/activities`);
|
||||||
|
|
||||||
const [aiError, stravaRequestBody] = await createActivityContent(
|
const [aiError, stravaRequestBody] = await createActivityContent({
|
||||||
activity,
|
currentActivity,
|
||||||
user,
|
previousActivities,
|
||||||
);
|
user: user!,
|
||||||
|
});
|
||||||
if (aiError) {
|
if (aiError) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { chain, draw, get, omit, tryit } from "radash";
|
import { chain, draw, get, omit, pick, tryit } from "radash";
|
||||||
import { safeDestr } from "destr";
|
import { safeDestr } from "destr";
|
||||||
import { User } from "./drizzle";
|
import { User } from "./drizzle";
|
||||||
|
|
||||||
@@ -104,10 +104,15 @@ const stringifyActivity = chain<[Activity], Activity, string>(
|
|||||||
(activity) => JSON.stringify(activity),
|
(activity) => JSON.stringify(activity),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const createActivityContent = async (
|
export const createActivityContent = async ({
|
||||||
activity: Activity,
|
currentActivity,
|
||||||
user: User & { preferences: any },
|
previousActivities,
|
||||||
) => {
|
user,
|
||||||
|
}: {
|
||||||
|
currentActivity: Activity;
|
||||||
|
previousActivities: Activity[];
|
||||||
|
user: User & { preferences: any };
|
||||||
|
}) => {
|
||||||
const openai = useOpenAI();
|
const openai = useOpenAI();
|
||||||
|
|
||||||
const tone = draw([
|
const tone = draw([
|
||||||
@@ -131,6 +136,7 @@ export const createActivityContent = async (
|
|||||||
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 say things like nothing too fancy or wild.
|
||||||
Use a little bit of ${tone} to make things less boring. Highlight any PR only if available, do not mention them if no PRs.
|
Use a little bit of ${tone} to make things less boring. Highlight any PR only if available, do not mention them if no PRs.
|
||||||
|
Maybe comment if any interesting fact in comparison to previous activities.
|
||||||
|
|
||||||
Add #${tone} at the end of the description. Depending the length of the description, maybe add more hashtags.
|
Add #${tone} at the end of the description. Depending the length of the description, maybe add more hashtags.
|
||||||
|
|
||||||
@@ -143,7 +149,10 @@ export const createActivityContent = async (
|
|||||||
Convert distance to larger units when appropriate, keep in mind we don't need much accuracy.
|
Convert distance to larger units when appropriate, keep in mind we don't need much accuracy.
|
||||||
|
|
||||||
The activity data in json format from strava:
|
The activity data in json format from strava:
|
||||||
${stringifyActivity(activity)}
|
${stringifyActivity(currentActivity)}
|
||||||
|
|
||||||
|
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)}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const [aiError, aiResponse] = await openai("/responses", {
|
const [aiError, aiResponse] = await openai("/responses", {
|
||||||
|
|||||||
Reference in New Issue
Block a user