-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unlimited messages for contributors (#1458)
- Loading branch information
Showing
5 changed files
with
40 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ const showdown = new Converter({ | |
openLinksInNewWindow: true, | ||
}); | ||
|
||
const FREE_MESSAGE_CAP = 5; | ||
const CONTRIB_MESSAGE_CAP = 50; | ||
const ABUSE_MESSAGE_CAP = 1440; | ||
|
||
export class Assistant { | ||
private openAiHelper: OpenAIHelper; | ||
/** | ||
|
@@ -126,8 +130,6 @@ export class Assistant { | |
} | ||
|
||
async checkMessageLimit(userId: string) { | ||
if (process.env.NODE_ENV === "development") return false; | ||
|
||
const moreMessages = await userHasCapability( | ||
userId, | ||
Capabilities.AssistantMoreMessages, | ||
|
@@ -148,14 +150,23 @@ export class Assistant { | |
}, | ||
}); | ||
|
||
const messageLimit = moreMessages ? 75 : 5; | ||
const isOverLimit = | ||
(!moreMessages && todayMessageCount >= FREE_MESSAGE_CAP) || | ||
todayMessageCount >= ABUSE_MESSAGE_CAP; | ||
const useLowQualityModel = | ||
moreMessages && todayMessageCount >= CONTRIB_MESSAGE_CAP; | ||
|
||
const isOverLimit = todayMessageCount >= messageLimit; | ||
|
||
return isOverLimit; | ||
return { | ||
isOverLimit, | ||
useLowQualityModel, | ||
}; | ||
} | ||
|
||
async sendChat(content: string, userId: string): Promise<void> { | ||
async sendChat( | ||
content: string, | ||
userId: string, | ||
useLowQualityModel: boolean, | ||
): Promise<void> { | ||
const assistantUser = await prisma.user.findUniqueOrThrow({ | ||
where: { | ||
email: "[email protected]", | ||
|
@@ -172,7 +183,9 @@ export class Assistant { | |
const recipes: Prisma.RecipeUncheckedCreateInput[] = []; | ||
|
||
const response = await this.openAiHelper.getChatResponseWithTools( | ||
SupportedGPTModel.GPT4O, | ||
useLowQualityModel | ||
? SupportedGPTModel.GPT4OMini | ||
: SupportedGPTModel.GPT4O, | ||
context, | ||
[initBuildRecipe(assistantUser.id, recipes)], | ||
); | ||
|