Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add gpt version in query #342

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@emotion/react": "11.11.4",
"@emotion/styled": "11.11.5",
"@graasp/sdk": "4.7.5",
"@graasp/sdk": "github:graasp/graasp-sdk#493-add-gpt-enum",
spaenleh marked this conversation as resolved.
Show resolved Hide resolved
"@mui/icons-material": "5.15.15",
"@mui/material": "5.15.15",
"axios": "0.28.1",
Expand Down
11 changes: 8 additions & 3 deletions src/api/chatBot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatBotMessage } from '@graasp/sdk';
import { ChatBotMessage, GPTVersion } from '@graasp/sdk';

import { ApiData, ChatBotCompletion } from 'types';

Expand All @@ -10,11 +10,16 @@ const axios = configureAxios();
export const postChatBot = (
args: ApiData & {
body: ChatBotMessage[];
gptModelVersion?: GPTVersion;
},
) => {
const { token, itemId, apiHost, body } = args;
const { token, itemId, apiHost, body, gptModelVersion } = args;
const url = new URL(buildPostChatBotRoute(itemId), apiHost);
if (gptModelVersion) {
url.searchParams.set('gptVersion', gptModelVersion);
}
return axios
.post<ChatBotCompletion>(`${apiHost}/${buildPostChatBotRoute(itemId)}`, body, {
.post<ChatBotCompletion>(url.toString(), body, {
headers: {
Authorization: `Bearer ${token}`,
},
Expand Down
6 changes: 3 additions & 3 deletions src/mutations/chatBot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatBotMessage } from '@graasp/sdk';
import { ChatBotMessage, GPTVersion } from '@graasp/sdk';

import { useMutation, useQueryClient } from '@tanstack/react-query';

Expand All @@ -10,14 +10,14 @@ import { QueryClientConfig } from '../types';
export default (queryConfig: QueryClientConfig) => {
const { notifier } = queryConfig;

const usePostChatBot = () => {
const usePostChatBot = (gptModelVersion?: GPTVersion) => {
const queryClient = useQueryClient();
return useMutation(
async (payload: ChatBotMessage[]) => {
const apiHost = getApiHost(queryClient);
const data = getDataOrThrow(queryClient);

return Api.postChatBot({ ...data, body: payload, apiHost });
return Api.postChatBot({ ...data, body: payload, apiHost, gptModelVersion });
},
{
onError: (error: Error) => {
Expand Down
32 changes: 16 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1202,10 +1202,10 @@ __metadata:
languageName: node
linkType: hard

"@eslint/js@npm:8.57.0":
version: 8.57.0
resolution: "@eslint/js@npm:8.57.0"
checksum: 10/3c501ce8a997cf6cbbaf4ed358af5492875e3550c19b9621413b82caa9ae5382c584b0efa79835639e6e0ddaa568caf3499318e5bdab68643ef4199dce5eb0a0
"@eslint/js@npm:8.56.0":
version: 8.56.0
resolution: "@eslint/js@npm:8.56.0"
checksum: 10/97a4b5ccf7e24f4d205a1fb0f21cdcd610348ecf685f6798a48dd41ba443f2c1eedd3050ff5a0b8f30b8cf6501ab512aa9b76e531db15e59c9ebaa41f3162e37
languageName: node
linkType: hard

Expand Down Expand Up @@ -1262,7 +1262,7 @@ __metadata:
"@commitlint/config-conventional": "npm:19.2.2"
"@emotion/react": "npm:11.11.4"
"@emotion/styled": "npm:11.11.5"
"@graasp/sdk": "npm:4.7.5"
"@graasp/sdk": "github:graasp/graasp-sdk#493-add-gpt-enum"
"@mui/icons-material": "npm:5.15.15"
"@mui/material": "npm:5.15.15"
"@tanstack/react-query": "npm:4.36.1"
Expand All @@ -1280,7 +1280,7 @@ __metadata:
axios: "npm:0.28.1"
date-fns: "npm:3.6.0"
dexie: "npm:4.0.4"
eslint: "npm:8.57.0"
eslint: "npm:8.56.0"
eslint-config-airbnb: "npm:19.0.4"
eslint-config-airbnb-typescript: "npm:18.0.0"
eslint-config-prettier: "npm:9.1.0"
Expand Down Expand Up @@ -1320,9 +1320,9 @@ __metadata:
languageName: unknown
linkType: soft

"@graasp/sdk@npm:4.7.5":
"@graasp/sdk@github:graasp/graasp-sdk#493-add-gpt-enum":
version: 4.7.5
resolution: "@graasp/sdk@npm:4.7.5"
resolution: "@graasp/sdk@https://github.com/graasp/graasp-sdk.git#commit=0e39fb2ecc2fa7ea5b30efc90426141e9c246159"
dependencies:
"@faker-js/faker": "npm:8.4.1"
filesize: "npm:10.1.1"
Expand All @@ -1331,11 +1331,11 @@ __metadata:
peerDependencies:
date-fns: ^3
uuid: ^9
checksum: 10/8b001f4854855ca8f3f60ac35f8dfa6a6e44af0e284667e76089243d83d6c254f14bc4c89db1d577efb5506aa278c4ff4b9897e19532f94ab7b12ff9c6fc8d47
checksum: 10/3a96c50178228da1778a21163f10973ffda78b55b3386162d4ebb0071d26a27a37bf39abc9f2c4e5d8b0ca7fd3d4072d98d68d1c5b68f70f72a2464e4f36d806
languageName: node
linkType: hard

"@humanwhocodes/config-array@npm:^0.11.14":
"@humanwhocodes/config-array@npm:^0.11.13":
version: 0.11.14
resolution: "@humanwhocodes/config-array@npm:0.11.14"
dependencies:
Expand Down Expand Up @@ -5019,15 +5019,15 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:8.57.0":
version: 8.57.0
resolution: "eslint@npm:8.57.0"
"eslint@npm:8.56.0":
version: 8.56.0
resolution: "eslint@npm:8.56.0"
dependencies:
"@eslint-community/eslint-utils": "npm:^4.2.0"
"@eslint-community/regexpp": "npm:^4.6.1"
"@eslint/eslintrc": "npm:^2.1.4"
"@eslint/js": "npm:8.57.0"
"@humanwhocodes/config-array": "npm:^0.11.14"
"@eslint/js": "npm:8.56.0"
"@humanwhocodes/config-array": "npm:^0.11.13"
"@humanwhocodes/module-importer": "npm:^1.0.1"
"@nodelib/fs.walk": "npm:^1.2.8"
"@ungap/structured-clone": "npm:^1.2.0"
Expand Down Expand Up @@ -5063,7 +5063,7 @@ __metadata:
text-table: "npm:^0.2.0"
bin:
eslint: bin/eslint.js
checksum: 10/00496e218b23747a7a9817bf58b522276d0dc1f2e546dceb4eea49f9871574088f72f1f069a6b560ef537efa3a75261b8ef70e51ef19033da1cc4c86a755ef15
checksum: 10/ef6193c6e4cef20774b985a5cc2fd4bf6d3c4decd423117cbc4a0196617861745db291217ad3c537bc3a160650cca965bc818f55e1f3e446af1fcb293f9940a5
languageName: node
linkType: hard

Expand Down