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

Feat/add ai.chat.allowed models feature limit #552

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

TroyceGowdy
Copy link
Contributor

fixes #328

…sage

- AIController.ts now rejects requests if the requested model is not in the allowed models list
- Added error handling to provide feedback when disallowed model is requested
chore: Added description to AIChatFeaturesConfiguration allowedModels interface
@TroyceGowdy TroyceGowdy added enhancement New feature or request area:backend Is related to the backend server. (Everything in aux-records and aux-server/aux-backend) labels Oct 14, 2024
@TroyceGowdy TroyceGowdy self-assigned this Oct 14, 2024
const model = 'modelA';
const result = { choices: ['choice1', 'choice2'] };

const response = (function () {
Copy link
Member

Choose a reason for hiding this comment

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

@TroyceGowdy These tests need to actually call into the AIController in order to properly test that the AIController is functioning correctly. Currently, the test just happens to use the same code as the AIController, but there is no guarantee that it will stay that way in the future,

Copy link
Member

@KallynGowdy KallynGowdy left a comment

Choose a reason for hiding this comment

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

The overall changes look good, but the tests still need some work.

…icate code.

- Updated implementation to use AIController.ts
- Removed redundant code that was duplicating AIController.ts functionality
Copy link
Member

@KallynGowdy KallynGowdy left a comment

Choose a reason for hiding this comment

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

Still a couple things with the tests but you're getting closer!

Comment on lines 372 to 397
it('should return success when allowedModels includes the model', async () => {
chatInterface.chat.mockReturnValueOnce(
Promise.resolve({
choices: [
{
role: 'user',
content: 'test',
finishReason: 'stop',
},
],
totalTokens: 1,
})
);

const result = await controller.chat({
model: 'test-model1',
messages: [
{
role: 'user',
content: 'test',
},
],
temperature: 0.5,
userId,
userSubscriptionTier,
});
Copy link
Member

Choose a reason for hiding this comment

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

@TroyceGowdy This test should be inside the "subscriptions" group and it should setup a subscription configuration that specifies the allowed models for the subscription tier that the user has. See lines 626-649 for an example of setting up the subscription configuration.

The way this test is currently written, it doesn't actually test the new subscription feature limit and only tests the server config.

Comment on lines +422 to +453
it('should return not_authorized when allowedModels does not include the model', async () => {
controller = new AIController({
chat: {
interfaces: {
provider1: chatInterface,
},
options: {
defaultModel: 'default-model',
defaultModelProvider: 'provider1',
allowedChatModels: [
{
provider: 'provider1',
model: 'modelA',
},
{
provider: 'provider1',
model: 'modelB',
},
],
allowedChatSubscriptionTiers: ['test-tier'],
},
},
generateSkybox: null,
images: null,
metrics: store,
config: store,
hume: null,
sloyd: null,
policies: null,
policyController: policies,
records: store,
});
Copy link
Member

Choose a reason for hiding this comment

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

@TroyceGowdy Same with this test. You shouldn't have to create a new AIController, instead you need to setup a subscription config.

@@ -1502,6 +1607,111 @@ describe('AIController', () => {
});
});

it('should return success when allowedModels includes the model', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

@TroyceGowdy Same here.

});
});

it('should return not_authorized error when allowedModels does not include the model', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

@TroyceGowdy And here.

- Relocated test code from both "chat" and "chatStream"
@KallynGowdy KallynGowdy added this to the v3.3.11 milestone Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:backend Is related to the backend server. (Everything in aux-records and aux-server/aux-backend) enhancement New feature or request
Projects
Status: To triage
Development

Successfully merging this pull request may close these issues.

Add ai.chat.allowedModels feature limit
2 participants