fix issue with longer context
This commit is contained in:
@@ -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!");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -2,7 +2,7 @@ import { omit } from "radash";
|
|||||||
|
|
||||||
export default defineOAuthStravaEventHandler({
|
export default defineOAuthStravaEventHandler({
|
||||||
config: {
|
config: {
|
||||||
scope: ["read,activity:read,activity:write"],
|
scope: ["read,activity:read_all,activity:write"],
|
||||||
},
|
},
|
||||||
onSuccess: async (event, auth) => {
|
onSuccess: async (event, auth) => {
|
||||||
const userPayload = {
|
const userPayload = {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { get, omit } from "radash";
|
import { get, omit, tryit } from "radash";
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const body = await readBody(event);
|
const body = await readBody(event);
|
||||||
@@ -21,7 +21,22 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
const activity = (await strava!(`/activities/${body.object_id}`)) as any;
|
const activity = (await strava!(`/activities/${body.object_id}`)) as any;
|
||||||
|
|
||||||
const aiResponse = await ai.run("@cf/meta/llama-3.1-8b-instruct", {
|
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: {
|
response_format: {
|
||||||
type: "json_schema",
|
type: "json_schema",
|
||||||
json_schema: {
|
json_schema: {
|
||||||
@@ -43,10 +58,23 @@ export default defineEventHandler(async (event) => {
|
|||||||
Weight: ${user?.weight}
|
Weight: ${user?.weight}
|
||||||
Language: ${user?.preferences.data.language}
|
Language: ${user?.preferences.data.language}
|
||||||
|
|
||||||
The activity data in json format:
|
The activity data:
|
||||||
${JSON.stringify(omit(activity, ["map", "laps", "stats_visibility", "embed_token", "private_note"]))}
|
${promptActivity}
|
||||||
`,
|
`,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
omit(activity, [
|
||||||
|
"map",
|
||||||
|
"laps",
|
||||||
|
"stats_visibility",
|
||||||
|
"embed_token",
|
||||||
|
"private_note",
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
console.error(aiError?.message);
|
||||||
|
|
||||||
// console.log(activity);
|
// console.log(activity);
|
||||||
// console.log(aiResponse.response.title);
|
// console.log(aiResponse.response.title);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { get } from "radash";
|
|||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const body = await readBody(event);
|
const body = await readBody(event);
|
||||||
const db = useDrizzle();
|
|
||||||
|
|
||||||
const aspectType = get(body, "aspect_type");
|
const aspectType = get(body, "aspect_type");
|
||||||
const objectType = get(body, "object_type");
|
const objectType = get(body, "object_type");
|
||||||
|
|||||||
Reference in New Issue
Block a user