Switch to og openai client
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -20,7 +20,7 @@
|
|||||||
"drizzle-orm": "^0.41.0",
|
"drizzle-orm": "^0.41.0",
|
||||||
"nuxt": "^3.16.2",
|
"nuxt": "^3.16.2",
|
||||||
"nuxt-auth-utils": "0.5.18",
|
"nuxt-auth-utils": "0.5.18",
|
||||||
"openai": "^4.95.1",
|
"openai": "^4.104.0",
|
||||||
"posthog-js": "^1.256.2",
|
"posthog-js": "^1.256.2",
|
||||||
"posthog-node": "^5.1.1",
|
"posthog-node": "^5.1.1",
|
||||||
"radash": "^12.1.0",
|
"radash": "^12.1.0",
|
||||||
@@ -9558,9 +9558,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/openai": {
|
"node_modules/openai": {
|
||||||
"version": "4.95.1",
|
"version": "4.104.0",
|
||||||
"resolved": "https://registry.npmjs.org/openai/-/openai-4.95.1.tgz",
|
"resolved": "https://registry.npmjs.org/openai/-/openai-4.104.0.tgz",
|
||||||
"integrity": "sha512-IqJy+ymeW+k/Wq+2YVN3693OQMMcODRtHEYOlz263MdUwnN/Dwdl9c2EXSxLLtGEHkSHAfvzpDMHI5MaWJKXjQ==",
|
"integrity": "sha512-p99EFNsA/yX6UhVO93f5kJsDRLAg+CTA2RBqdHK4RtK8u5IJw32Hyb2dTGKbnnFmnuoBv5r7Z2CURI9sGZpSuA==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
"drizzle-orm": "^0.41.0",
|
"drizzle-orm": "^0.41.0",
|
||||||
"nuxt": "^3.16.2",
|
"nuxt": "^3.16.2",
|
||||||
"nuxt-auth-utils": "0.5.18",
|
"nuxt-auth-utils": "0.5.18",
|
||||||
"openai": "^4.95.1",
|
"openai": "^4.104.0",
|
||||||
"posthog-js": "^1.256.2",
|
"posthog-js": "^1.256.2",
|
||||||
"posthog-node": "^5.1.1",
|
"posthog-node": "^5.1.1",
|
||||||
"radash": "^12.1.0",
|
"radash": "^12.1.0",
|
||||||
|
|||||||
@@ -150,15 +150,9 @@ export const createActivityContent = async ({
|
|||||||
[${previousActivities.map((activity) => stringifyActivity({ activity, shouldKeepNames: true }))}]
|
[${previousActivities.map((activity) => stringifyActivity({ activity, shouldKeepNames: true }))}]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const [aiError, aiResponse] = await openai("/responses", {
|
const aiResponse = await openai.responses.create({
|
||||||
body: {
|
model: "gpt-4o-mini",
|
||||||
model: "gpt-4.1",
|
input: [{ role: "user", content: prompt }],
|
||||||
input: [
|
|
||||||
{
|
|
||||||
role: "user",
|
|
||||||
content: prompt,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
text: {
|
text: {
|
||||||
format: {
|
format: {
|
||||||
type: "json_schema",
|
type: "json_schema",
|
||||||
@@ -178,12 +172,11 @@ export const createActivityContent = async ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [parseError, responseObject] = tryit(
|
const [parseError, responseObject] = tryit(
|
||||||
chain(
|
chain(
|
||||||
(r) => get(r, "output.0.content.0.text"),
|
(r) => get(r, "output_text"),
|
||||||
(r) => safeDestr<{ title: string; description: string }>(r),
|
(r) => safeDestr<{ title: string; description: string }>(r),
|
||||||
),
|
),
|
||||||
)(aiResponse);
|
)(aiResponse);
|
||||||
@@ -197,5 +190,5 @@ export const createActivityContent = async ({
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return [aiError || parseError, stravaRequestBody] as const;
|
return [parseError, stravaRequestBody] as const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import { tryit } from "radash";
|
import OpenAI from "openai";
|
||||||
|
|
||||||
export const useOpenAI = () => {
|
export const useOpenAI = () => {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
|
|
||||||
const client = $fetch.create({
|
const client = new OpenAI({
|
||||||
baseURL: "https://api.openai.com/v1",
|
apiKey: config.openaiApiKey,
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${config.openaiApiKey}`,
|
|
||||||
},
|
|
||||||
method: "post",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return tryit(client);
|
return client;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user