Add random length and some more house-keeping
This commit is contained in:
@@ -9,7 +9,6 @@ export default defineEventHandler(async (event) => {
|
||||
data: {
|
||||
enabled: body.enabled,
|
||||
language: body.language,
|
||||
tone: body.tone,
|
||||
units: body.units,
|
||||
},
|
||||
})
|
||||
|
||||
25
server/auth.d.ts
vendored
Normal file
25
server/auth.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
declare module "#auth-utils" {
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
country: string;
|
||||
sex: string;
|
||||
weight: number;
|
||||
avatar: string;
|
||||
}
|
||||
|
||||
interface UserSession {
|
||||
user: {
|
||||
id: number;
|
||||
name: string;
|
||||
country: string;
|
||||
sex: string;
|
||||
weight: number;
|
||||
avatar: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface SecureSessionData {
|
||||
// Add your own fields
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { get, omit } from "radash";
|
||||
import type { H3Event } from "h3";
|
||||
|
||||
const requiredScope = ["read", "activity:write", "activity:read_all"];
|
||||
const hasEnoughScope = (scope: string) => {
|
||||
@@ -11,7 +12,7 @@ export default defineOAuthStravaEventHandler({
|
||||
config: {
|
||||
scope: [requiredScope.join(",")],
|
||||
},
|
||||
onSuccess: async (event, auth) => {
|
||||
onSuccess: async (event: H3Event, auth: any) => {
|
||||
const query = getQuery(event);
|
||||
const scope = get(query, "scope", "");
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { get, omit, draw } from "radash";
|
||||
import { get } from "radash";
|
||||
import { createActivityContent } from "~~/server/utils/create-content";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
const db = useDrizzle();
|
||||
const openai = useOpenAI();
|
||||
|
||||
const user = await db.query.users.findFirst({
|
||||
where: (f, o) => o.eq(f.id, body.owner_id),
|
||||
@@ -17,18 +16,9 @@ export default defineEventHandler(async (event) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const tone = draw([
|
||||
"casual",
|
||||
"funny",
|
||||
"epic",
|
||||
"poetic",
|
||||
"reflective",
|
||||
"snarky",
|
||||
]);
|
||||
|
||||
const strava = await useStrava(body.owner_id);
|
||||
|
||||
const [, activity] = await strava!<any>(`/activities/${body.object_id}`);
|
||||
const activity = await strava!<any>(`/activities/${body.object_id}`);
|
||||
|
||||
const [aiError, aiResponse] = await createActivityContent(activity, user);
|
||||
if (aiError) {
|
||||
@@ -52,15 +42,13 @@ export default defineEventHandler(async (event) => {
|
||||
description: [responseObject.description, promo].join("\n"),
|
||||
};
|
||||
|
||||
const [stravaError] = await strava!(`activities/${body.object_id}`, {
|
||||
await strava!(`activities/${body.object_id}`, {
|
||||
method: "PUT",
|
||||
body: stravaRequestBody,
|
||||
});
|
||||
|
||||
if (stravaError) {
|
||||
}).catch((error) => {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: `Strava API: ${stravaError.message}`,
|
||||
message: `Strava API: ${error.message}`,
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { get, isEmpty } from "radash";
|
||||
import { get } from "radash";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
|
||||
@@ -101,7 +101,10 @@ const stringifyActivity = chain<[Activity], Activity, string>(
|
||||
(activity) => JSON.stringify(activity),
|
||||
);
|
||||
|
||||
export const createActivityContent = async (activity: Activity, user: User) => {
|
||||
export const createActivityContent = async (
|
||||
activity: Activity,
|
||||
user: User & { preferences: any },
|
||||
) => {
|
||||
const openai = useOpenAI();
|
||||
|
||||
const tone = draw([
|
||||
@@ -113,12 +116,14 @@ export const createActivityContent = async (activity: Activity, user: User) => {
|
||||
"snarky",
|
||||
]);
|
||||
|
||||
console.log(tone, activity.type);
|
||||
const length = draw(["short", "short", "short", "medium", "long"]);
|
||||
|
||||
console.log(tone, length);
|
||||
|
||||
const prompt = `
|
||||
Generate a short title and 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.
|
||||
Don't exaggerate. Try keeping it calm as I am using Strava often and I don't want to have boring feed. Keep things short.
|
||||
Use a little bit of ${tone} to make things less boring. Highlight any PR if available.
|
||||
Use a little bit of ${tone} to make things less boring. Highlight any PR only if available, do not mention them if no PRs.
|
||||
|
||||
Language: ${user?.preferences.data.language}
|
||||
Unit system: ${user?.preferences.data.units}
|
||||
@@ -134,7 +139,7 @@ export const createActivityContent = async (activity: Activity, user: User) => {
|
||||
|
||||
const [aiError, aiResponse] = await openai("/responses", {
|
||||
body: {
|
||||
model: "gpt-4o",
|
||||
model: "gpt-4.1",
|
||||
input: [
|
||||
{
|
||||
role: "user",
|
||||
|
||||
@@ -57,12 +57,12 @@ export const useStrava = async (userId: number) => {
|
||||
.where(eq(tables.tokens.userId, userId));
|
||||
}
|
||||
|
||||
return tryit(
|
||||
$fetch.create({
|
||||
const client = $fetch.create({
|
||||
baseURL: "https://www.strava.com/api/v3/",
|
||||
onRequest({ options }) {
|
||||
options.headers.set("Authorization", `Bearer ${tokens?.accessToken}`);
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
return client;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user