fix issue with longer context

This commit is contained in:
2025-04-10 21:43:21 +03:00
parent 6a1702282d
commit 980b733a32
4 changed files with 44 additions and 51 deletions

View File

@@ -1,34 +0,0 @@
import { isEmpty } from "radash";
import { URLSearchParams } from "url";
export default defineNitroPlugin(() => {
onHubReady(async () => {
const config = useRuntimeConfig();
const webhooks = await $fetch(
"https://www.strava.com/api/v3/push_subscriptions",
{
params: {
client_id: config.oauth.strava.clientId,
client_secret: config.oauth.strava.clientSecret,
},
},
);
if (!isEmpty(webhooks)) {
return;
}
await $fetch("https://www.strava.com/api/v3/push_subscriptions", {
method: "post",
body: new URLSearchParams({
client_id: config.oauth.strava.clientId,
client_secret: config.oauth.strava.clientSecret,
callback_url: config.webhooksUrl,
verify_token: config.stravaVerifyToken,
}),
});
console.log("Webhook registered successfully!");
});
});

View File

@@ -2,7 +2,7 @@ import { omit } from "radash";
export default defineOAuthStravaEventHandler({
config: {
scope: ["read,activity:read,activity:write"],
scope: ["read,activity:read_all,activity:write"],
},
onSuccess: async (event, auth) => {
const userPayload = {

View File

@@ -1,4 +1,4 @@
import { get, omit } from "radash";
import { get, omit, tryit } from "radash";
export default defineEventHandler(async (event) => {
const body = await readBody(event);
@@ -21,19 +21,34 @@ export default defineEventHandler(async (event) => {
const activity = (await strava!(`/activities/${body.object_id}`)) as any;
const aiResponse = await ai.run("@cf/meta/llama-3.1-8b-instruct", {
response_format: {
type: "json_schema",
json_schema: {
type: "object",
properties: {
title: "string",
description: "string",
const promptActivity = `
type: ${get(activity, "type")}
distance: ${get(activity, "distance")}m
moving time: ${get(activity, "moving_time")}sec
elapsed time: ${get(activity, "elapsed_time")}sec
total elevation gain: ${get(activity, "total_elevation_gain")}m
start (local): ${get(activity, "start_date_local")}
trainer: ${get(activity, "trainer")}
commute: ${get(activity, "commute")}
suffer score: ${get(activity, "suffer_score")}/100
calories: ${get(activity, "calories")}
`;
const [aiError, aiResponse] = await tryit(ai.run)(
"@cf/meta/llama-3.1-8b-instruct",
{
response_format: {
type: "json_schema",
json_schema: {
type: "object",
properties: {
title: "string",
description: "string",
},
required: ["title", "description"],
},
required: ["title", "description"],
},
},
prompt: `
prompt: `
Generate a title and a short description for my strava activity. Use my preferred language.
Use ${user?.preferences.data.tone} tone to generate content.
Add emojis unless tone is set to minimalist.
@@ -43,10 +58,23 @@ export default defineEventHandler(async (event) => {
Weight: ${user?.weight}
Language: ${user?.preferences.data.language}
The activity data in json format:
${JSON.stringify(omit(activity, ["map", "laps", "stats_visibility", "embed_token", "private_note"]))}
The activity data:
${promptActivity}
`,
});
},
);
console.log(
omit(activity, [
"map",
"laps",
"stats_visibility",
"embed_token",
"private_note",
]),
);
console.error(aiError?.message);
// console.log(activity);
// console.log(aiResponse.response.title);

View File

@@ -2,7 +2,6 @@ import { get } from "radash";
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const db = useDrizzle();
const aspectType = get(body, "aspect_type");
const objectType = get(body, "object_type");