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",
|
||||
"nuxt": "^3.16.2",
|
||||
"nuxt-auth-utils": "0.5.18",
|
||||
"openai": "^4.95.1",
|
||||
"openai": "^4.104.0",
|
||||
"posthog-js": "^1.256.2",
|
||||
"posthog-node": "^5.1.1",
|
||||
"radash": "^12.1.0",
|
||||
@@ -9558,9 +9558,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/openai": {
|
||||
"version": "4.95.1",
|
||||
"resolved": "https://registry.npmjs.org/openai/-/openai-4.95.1.tgz",
|
||||
"integrity": "sha512-IqJy+ymeW+k/Wq+2YVN3693OQMMcODRtHEYOlz263MdUwnN/Dwdl9c2EXSxLLtGEHkSHAfvzpDMHI5MaWJKXjQ==",
|
||||
"version": "4.104.0",
|
||||
"resolved": "https://registry.npmjs.org/openai/-/openai-4.104.0.tgz",
|
||||
"integrity": "sha512-p99EFNsA/yX6UhVO93f5kJsDRLAg+CTA2RBqdHK4RtK8u5IJw32Hyb2dTGKbnnFmnuoBv5r7Z2CURI9sGZpSuA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@types/node": "^18.11.18",
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"drizzle-orm": "^0.41.0",
|
||||
"nuxt": "^3.16.2",
|
||||
"nuxt-auth-utils": "0.5.18",
|
||||
"openai": "^4.95.1",
|
||||
"openai": "^4.104.0",
|
||||
"posthog-js": "^1.256.2",
|
||||
"posthog-node": "^5.1.1",
|
||||
"radash": "^12.1.0",
|
||||
|
||||
@@ -150,32 +150,25 @@ export const createActivityContent = async ({
|
||||
[${previousActivities.map((activity) => stringifyActivity({ activity, shouldKeepNames: true }))}]
|
||||
`;
|
||||
|
||||
const [aiError, aiResponse] = await openai("/responses", {
|
||||
body: {
|
||||
model: "gpt-4.1",
|
||||
input: [
|
||||
{
|
||||
role: "user",
|
||||
content: prompt,
|
||||
},
|
||||
],
|
||||
text: {
|
||||
format: {
|
||||
type: "json_schema",
|
||||
name: "activity",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
title: {
|
||||
type: "string",
|
||||
},
|
||||
description: {
|
||||
type: "string",
|
||||
},
|
||||
const aiResponse = await openai.responses.create({
|
||||
model: "gpt-4o-mini",
|
||||
input: [{ role: "user", content: prompt }],
|
||||
text: {
|
||||
format: {
|
||||
type: "json_schema",
|
||||
name: "activity",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
title: {
|
||||
type: "string",
|
||||
},
|
||||
description: {
|
||||
type: "string",
|
||||
},
|
||||
required: ["title", "description"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
required: ["title", "description"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -183,7 +176,7 @@ export const createActivityContent = async ({
|
||||
|
||||
const [parseError, responseObject] = tryit(
|
||||
chain(
|
||||
(r) => get(r, "output.0.content.0.text"),
|
||||
(r) => get(r, "output_text"),
|
||||
(r) => safeDestr<{ title: string; description: string }>(r),
|
||||
),
|
||||
)(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 = () => {
|
||||
const config = useRuntimeConfig();
|
||||
|
||||
const client = $fetch.create({
|
||||
baseURL: "https://api.openai.com/v1",
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.openaiApiKey}`,
|
||||
},
|
||||
method: "post",
|
||||
const client = new OpenAI({
|
||||
apiKey: config.openaiApiKey,
|
||||
});
|
||||
|
||||
return tryit(client);
|
||||
return client;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user