-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: develop
Are you sure you want to change the base?
Changes from 6 commits
ee3a96c
4ef7daa
5b70695
97d417f
2b150fc
0fdce04
bc831d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,111 @@ describe('AIController', () => { | |
expect(chatInterface.chat).not.toBeCalled(); | ||
}); | ||
|
||
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, | ||
}); | ||
|
||
expect(result).toEqual({ | ||
success: true, | ||
choices: [ | ||
{ | ||
role: 'user', | ||
content: 'test', | ||
finishReason: 'stop', | ||
}, | ||
], | ||
}); | ||
expect(chatInterface.chat).toBeCalledWith({ | ||
model: 'test-model1', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: 'test', | ||
}, | ||
], | ||
temperature: 0.5, | ||
userId: 'test-user', | ||
}); | ||
}); | ||
|
||
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, | ||
}); | ||
Comment on lines
+372
to
+403
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
const result = await controller.chat({ | ||
model: 'modelC', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: 'test', | ||
}, | ||
], | ||
temperature: 0.5, | ||
userId, | ||
userSubscriptionTier, | ||
}); | ||
|
||
expect(result).toEqual({ | ||
success: false, | ||
errorCode: 'not_authorized', | ||
errorMessage: | ||
'The subscription does not permit the given model for AI Chat features.', | ||
}); | ||
expect(chatInterface.chat).not.toBeCalled(); | ||
}); | ||
|
||
it('should return an not_logged_in result if the given a null userId', async () => { | ||
const result = await controller.chat({ | ||
model: 'test-model1', | ||
|
@@ -1502,6 +1607,111 @@ describe('AIController', () => { | |
}); | ||
}); | ||
|
||
it('should return success when allowedModels includes the model', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TroyceGowdy Same here. |
||
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, | ||
}); | ||
|
||
expect(result).toEqual({ | ||
success: true, | ||
choices: [ | ||
{ | ||
role: 'user', | ||
content: 'test', | ||
finishReason: 'stop', | ||
}, | ||
], | ||
}); | ||
expect(chatInterface.chat).toBeCalledWith({ | ||
model: 'test-model1', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: 'test', | ||
}, | ||
], | ||
temperature: 0.5, | ||
userId: 'test-user', | ||
}); | ||
}); | ||
|
||
it('should return not_authorized error when allowedModels does not include the model', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TroyceGowdy And here. |
||
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, | ||
}); | ||
|
||
const result = await controller.chat({ | ||
model: 'modelC', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: 'test', | ||
}, | ||
], | ||
temperature: 0.5, | ||
userId, | ||
userSubscriptionTier, | ||
}); | ||
|
||
expect(result).toEqual({ | ||
success: false, | ||
errorCode: 'not_authorized', | ||
errorMessage: | ||
'The subscription does not permit the given model for AI Chat features.', | ||
}); | ||
expect(chatInterface.chat).not.toBeCalled(); | ||
}); | ||
|
||
describe('subscriptions', () => { | ||
beforeEach(async () => { | ||
store.subscriptionConfiguration = buildSubscriptionConfig( | ||
|
There was a problem hiding this comment.
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.