Skip to content

feat(compass-generative-ai): don't require Atlas login, use the unauthenticated NLQ endpoints COMPASS-9688 #7191

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions packages/compass-e2e-tests/tests/atlas-login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function getTestBrowserShellCommand() {
)}`;
}

describe('Atlas Login', function () {
// TODO: remove these when we remove atlas login
describe.skip('Atlas Login', function () {
let compass: Compass;
let browser: CompassBrowser;
let oidcMockProvider: OIDCMockProvider;
Expand Down Expand Up @@ -281,7 +282,8 @@ describe('Atlas Login', function () {
);
});

it('should not show AI input if sign in flow was not finished', async function () {
// TODO: remove once we remove atlas login
it.skip('should not show AI input if sign in flow was not finished', async function () {
getTokenPayload = () => {
return new Promise(() => {});
};
Expand Down Expand Up @@ -314,7 +316,8 @@ describe('Atlas Login', function () {
);
});

it('should not show AI input if sign in flow was not finished', async function () {
// TODO: remove once we remove atlas login
it.skip('should not show AI input if sign in flow was not finished', async function () {
getTokenPayload = () => {
return new Promise(() => {});
};
Expand Down
11 changes: 2 additions & 9 deletions packages/compass-generative-ai/src/atlas-ai-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ describe('AtlasAiService', function () {
{
apiURLPreset: 'admin-api',
expectedEndpoints: {
'mql-aggregation': `http://example.com/ai/api/v1/mql-aggregation?request_id=abc`,
'mql-query': `http://example.com/ai/api/v1/mql-query?request_id=abc`,
'mql-aggregation': `http://example.com/unauth/ai/api/v1/mql-aggregation?request_id=abc`,
'mql-query': `http://example.com/unauth/ai/api/v1/mql-query?request_id=abc`,
},
},
{
Expand Down Expand Up @@ -327,13 +327,6 @@ describe('AtlasAiService', function () {
// Reset preferences
await preferences.savePreferences({
optInGenAIFeatures: false,
enableUnauthenticatedGenAI: true,
});
});

afterEach(async function () {
await preferences.savePreferences({
enableUnauthenticatedGenAI: false,
});
});

Expand Down
19 changes: 5 additions & 14 deletions packages/compass-generative-ai/src/atlas-ai-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { Logger } from '@mongodb-js/compass-logging';
import { EJSON } from 'bson';
import { getStore } from './store/atlas-ai-store';
import { optIntoGenAIWithModalPrompt } from './store/atlas-optin-reducer';
import { signIntoAtlasWithModalPrompt } from './store/atlas-signin-reducer';

type GenerativeAiInput = {
userInput: string;
Expand Down Expand Up @@ -197,9 +196,11 @@ const aiURLConfig = {
// There are two different sets of endpoints we use for our requests.
// Down the line we'd like to only use the admin api, however,
// we cannot currently call that from the Atlas UI. Pending CLOUDP-251201
// NOTE: The unauthenticated endpoints are also rate limited by IP address
// rather than by logged in user.
'admin-api': {
aggregation: 'ai/api/v1/mql-aggregation',
query: 'ai/api/v1/mql-query',
aggregation: 'unauth/ai/api/v1/mql-aggregation',
query: 'unauth/ai/api/v1/mql-query',
},
cloud: {
aggregation: (groupId: string) => `ai/v1/groups/${groupId}/mql-aggregation`,
Expand Down Expand Up @@ -277,17 +278,7 @@ export class AtlasAiService {
}

async ensureAiFeatureAccess({ signal }: { signal?: AbortSignal } = {}) {
if (this.preferences.getPreferences().enableUnauthenticatedGenAI) {
return getStore().dispatch(optIntoGenAIWithModalPrompt({ signal }));
}

// When the ai feature is attempted to be opened we make sure
// the user is signed into Atlas and opted in.

if (this.apiURLPreset === 'cloud') {
return getStore().dispatch(optIntoGenAIWithModalPrompt({ signal }));
}
return getStore().dispatch(signIntoAtlasWithModalPrompt({ signal }));
return getStore().dispatch(optIntoGenAIWithModalPrompt({ signal }));
}

private getQueryOrAggregationFromUserInput = async <T>(
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-preferences-model/src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const featureFlags: Required<{
},

enableUnauthenticatedGenAI: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can just remove this rather than set stage to released, right? Or was there some reason you can't do that? I can never remember.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds fine to me, not sure how it works generally though

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally just set these to released, yes. Makes sure that we're not breaking anything that happens to set this flag and expect it to be recognized, and that it won't conflict with a future Compass option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it now, but does that mean we can never remove these?

stage: 'development',
stage: 'released',
description: {
short: 'Enable GenAI for unauthenticated users',
},
Expand Down
Loading