Skip to content

Commit

Permalink
fixing post request
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchitharajaghatta committed Nov 14, 2024
1 parent ee684c7 commit cdbfa92
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
80 changes: 80 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"@types/react-dom": "^17.0.25",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"dependencies": {
"query-string": "^9.1.1"
}
}
22 changes: 18 additions & 4 deletions packages/compass-generative-ai/src/atlas-ai-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { EJSON } from 'bson';
import { signIntoAtlasWithModalPrompt } from './store/atlas-signin-reducer';
import { getStore } from './store/atlas-ai-store';
import { optIntoGenAIWithModalPrompt } from './store/atlas-optin-reducer';
import type { StringifyOptions } from 'query-string';
import queryString from 'query-string';

type GenerativeAiInput = {
userInput: string;
Expand All @@ -28,6 +30,18 @@ type GenerativeAiInput = {
const AI_MAX_REQUEST_SIZE = 5120000;
const AI_MIN_SAMPLE_DOCUMENTS = 1;

// Usage: when sending a request of content type 'application/x-www-form-urlencoded'
export const formParams = function formParams(
params: Record<string, any>,
{
skipNull = true,
arrayFormat = 'bracket',
...options
}: StringifyOptions = {}
) {
return queryString.stringify(params, { skipNull, arrayFormat, ...options });
};

type AIAggregation = {
content: {
aggregation?: {
Expand Down Expand Up @@ -450,13 +464,13 @@ export class AtlasAiService {
),
{
method: 'POST',
body: JSON.stringify({
value: true,
}),
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
},
body: formParams({
value: true,
}),
}
);
await this.preferences.savePreferences({
Expand Down

0 comments on commit cdbfa92

Please sign in to comment.