Skip to content

Commit 2937830

Browse files
authored
fix: upgrade openai models (#1918)
* fix: wip * fix: update types for GPT versions * fix: use sdk version
1 parent 882b469 commit 2937830

8 files changed

Lines changed: 21 additions & 22 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
"mhutchie.git-graph",
6666
"firsttris.vscode-jest-runner",
6767
"Orta.vscode-jest",
68-
"Gruntfuggly.todo-tree",
69-
"wayou.vscode-todo-highlight"
68+
"Gruntfuggly.todo-tree"
7069
]
7170
}
7271
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@fastify/type-provider-typebox": "5.1.0",
6767
"@fastify/websocket": "11.0.2",
6868
"@graasp/etherpad-api": "2.1.1",
69-
"@graasp/sdk": "5.13.3",
69+
"@graasp/sdk": "5.14.0",
7070
"@graasp/translations": "1.44.0",
7171
"@rapideditor/country-coder": "5.4.0",
7272
"@sentry/node": "7.119.2",

src/services/item/plugins/app/chatBot/chatBot.controller.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ describe('Chat Bot Tests', () => {
202202
const chosenApp = apps[0];
203203

204204
const token = await getAccessToken(app, item, chosenApp);
205-
const gptVersion = GPTVersion.GPT_4;
205+
const gptVersion = GPTVersion.GPT_4_1_NANO;
206206
const response = await app.inject({
207207
method: HttpMethod.Post,
208208
url: `${APP_ITEMS_PREFIX}/${item.id}/${CHAT_PATH}?gptVersion=${gptVersion}`,

src/services/item/plugins/app/chatBot/chatBot.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { singleton } from 'tsyringe';
22

3-
import { type ChatBotMessage, GPTVersion, PermissionLevel } from '@graasp/sdk';
3+
import { type ChatBotMessage, type GPTVersionType, PermissionLevel } from '@graasp/sdk';
44

55
import { type DBConnection } from '../../../../../drizzle/db';
66
import type { AuthenticatedUser } from '../../../../../types';
@@ -20,7 +20,7 @@ export class ChatBotService {
2020
account: AuthenticatedUser,
2121
itemId: string,
2222
body: Array<ChatBotMessage>,
23-
gptVersion: GPTVersion,
23+
gptVersion: GPTVersionType,
2424
temperature: number,
2525
) {
2626
// check that the member can read the item to be allowed to interact with the chat

src/services/item/plugins/app/chatBot/openAICompletion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { OpenAI } from 'openai';
22

3-
import { type ChatBotMessage, GPTVersion } from '@graasp/sdk';
3+
import { type ChatBotMessage, GPTVersion, type GPTVersionType } from '@graasp/sdk';
44

55
import { OPENAI_API_KEY, OPENAI_ORG_ID } from '../../../../../utils/config';
66
import { OpenAIBadVersion } from '../../../../../utils/errors';
77

88
export const openAICompletion = async (
99
body: Array<ChatBotMessage>,
10-
gptVersion: GPTVersion,
10+
gptVersion: GPTVersionType,
1111
temperature?: number,
1212
) => {
1313
validateGPTVersion(gptVersion);
@@ -25,8 +25,8 @@ export const openAICompletion = async (
2525
return completion;
2626
};
2727

28-
export function validateGPTVersion(gptVersion?: GPTVersion) {
29-
if (gptVersion && !Object.values(GPTVersion).includes(gptVersion as GPTVersion)) {
28+
export function validateGPTVersion(gptVersion?: GPTVersionType) {
29+
if (gptVersion && !Object.values(GPTVersion).includes(gptVersion as GPTVersionType)) {
3030
throw new OpenAIBadVersion(gptVersion, `${Object.values(GPTVersion)}`);
3131
}
3232
}

src/services/item/plugins/app/chatBot/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ChatCompletion } from 'openai/resources/chat/index';
22

3-
import { type ChatBotMessage, GPTVersion } from '@graasp/sdk';
3+
import { type ChatBotMessage, type GPTVersionType } from '@graasp/sdk';
44

55
import {
66
OpenAIBaseError,
@@ -13,7 +13,7 @@ import { openAICompletion } from './openAICompletion';
1313

1414
export const fetchOpenAI = async (
1515
body: ChatBotMessage[],
16-
gptVersion: GPTVersion,
16+
gptVersion: GPTVersionType,
1717
temperature: number,
1818
) => {
1919
try {
@@ -35,7 +35,7 @@ export const fetchOpenAI = async (
3535
}
3636
};
3737

38-
function computeResult(choice: ChatCompletion.Choice, gptVersion?: GPTVersion) {
38+
function computeResult(choice: ChatCompletion.Choice, gptVersion?: GPTVersionType) {
3939
const finishReason = choice.finish_reason;
4040
switch (finishReason) {
4141
case FinishReason.LENGTH:

src/utils/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os from 'os';
22

3-
import { ClientManager, Context, GPTVersion } from '@graasp/sdk';
3+
import { ClientManager, Context, GPTVersion, type GPTVersionType } from '@graasp/sdk';
44
import { DEFAULT_LANG } from '@graasp/translations';
55

66
import { requiredEnvVar } from '../config/helpers';
@@ -220,12 +220,12 @@ export const MEILISEARCH_STORE_LEGACY_PDF_CONTENT: boolean =
220220
process.env.MEILISEARCH_STORE_LEGACY_PDF_CONTENT === 'true';
221221

222222
// OpenAI
223-
const getGptVersion = (): GPTVersion => {
223+
const getGptVersion = (): GPTVersionType => {
224224
const GPTVersionEnv = process.env.OPENAI_GPT_VERSION ?? '';
225225
if ((Object.values(GPTVersion) as string[]).includes(GPTVersionEnv)) {
226-
return GPTVersionEnv as GPTVersion;
226+
return GPTVersionEnv as GPTVersionType;
227227
}
228-
return GPTVersion.GPT_3_5_TURBO;
228+
return GPTVersion.GPT_4_O_MINI;
229229
};
230230
export const OPENAI_GPT_VERSION = getGptVersion();
231231
export const OPENAI_API_KEY = process.env.OPENAI_API_KEY;

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,17 +2592,17 @@ __metadata:
25922592
languageName: node
25932593
linkType: hard
25942594

2595-
"@graasp/sdk@npm:5.13.3":
2596-
version: 5.13.3
2597-
resolution: "@graasp/sdk@npm:5.13.3"
2595+
"@graasp/sdk@npm:5.14.0":
2596+
version: 5.14.0
2597+
resolution: "@graasp/sdk@npm:5.14.0"
25982598
dependencies:
25992599
"@faker-js/faker": "npm:9.7.0"
26002600
filesize: "npm:10.1.6"
26012601
js-cookie: "npm:3.0.5"
26022602
peerDependencies:
26032603
date-fns: ^3 || ^4.0.0
26042604
uuid: ^9 || ^10 || ^11.0.0
2605-
checksum: 10/923b18760e762c7e44a6fb1d8e2fdef93421d726958dd9fc730a67504ed9e932550f3daac01b365458d9cfd17d14771599e4ed7dabcabc2ac643619d3bfe5d77
2605+
checksum: 10/59245e47486117fe2906a1e0f3a3f493b40157e05b34a637aa4d6b9d9ea2b2067d4b25ffb22ac9f34de1150953663bb7d1479d9fa8792406ddfcd90ce306c029
26062606
languageName: node
26072607
linkType: hard
26082608

@@ -8638,7 +8638,7 @@ __metadata:
86388638
"@fastify/type-provider-typebox": "npm:5.1.0"
86398639
"@fastify/websocket": "npm:11.0.2"
86408640
"@graasp/etherpad-api": "npm:2.1.1"
8641-
"@graasp/sdk": "npm:5.13.3"
8641+
"@graasp/sdk": "npm:5.14.0"
86428642
"@graasp/translations": "npm:1.44.0"
86438643
"@jest/globals": "npm:29.7.0"
86448644
"@quobix/vacuum": "npm:0.17.0"

0 commit comments

Comments
 (0)