enzostvs HF Staff commited on
Commit
5d7086a
·
1 Parent(s): 8bd4730

specific error for pro user without enough credits

Browse files
app/api/ask/route.ts CHANGED
@@ -141,7 +141,8 @@ export async function POST(request: Request) {
141
  try {
142
  let errorPayload = "";
143
  if (
144
- errorMessage?.includes("exceeded your monthly included credits")
 
145
  ) {
146
  errorPayload = JSON.stringify({
147
  messageError: errorMessage,
 
141
  try {
142
  let errorPayload = "";
143
  if (
144
+ errorMessage?.includes("exceeded your monthly included credits") ||
145
+ errorMessage?.includes("reached the free monthly usage limit")
146
  ) {
147
  errorPayload = JSON.stringify({
148
  messageError: errorMessage,
components/ask-ai/useGeneration.ts CHANGED
@@ -4,11 +4,12 @@ import { useRef } from "react";
4
  import { toast } from "sonner";
5
  import { useRouter } from "next/navigation";
6
  import { v4 as uuidv4 } from "uuid";
 
 
7
 
8
  import { formatResponse } from "@/lib/format";
9
  import { File, Message, MessageActionType, ProviderType } from "@/lib/type";
10
  import { getContextFilesFromPrompt } from "@/lib/utils";
11
- import { useLocalStorage } from "react-use";
12
 
13
  const MESSAGES_QUERY_KEY = (projectName: string) =>
14
  ["messages", projectName] as const;
@@ -22,6 +23,7 @@ export const useGeneration = (projectName: string) => {
22
  `messages-${projectName}`,
23
  []
24
  );
 
25
 
26
  const { data: isLoading } = useQuery({
27
  queryKey: ["ai.generation.isLoading"],
@@ -348,10 +350,14 @@ export const useGeneration = (projectName: string) => {
348
  isThinking: false,
349
  isAborted: true,
350
  content: errorData?.showProMessage
351
- ? `You have exceeded your monthly included credits with Hugging Face inference provider. Please consider upgrading to a pro plan.`
352
  : `Error: ${errorData.messageError}`,
353
  actions: errorData?.showProMessage
354
- ? [
 
 
 
 
355
  {
356
  label: "Upgrade to Pro",
357
  variant: "pro",
 
4
  import { toast } from "sonner";
5
  import { useRouter } from "next/navigation";
6
  import { v4 as uuidv4 } from "uuid";
7
+ import { useLocalStorage } from "react-use";
8
+ import { useSession } from "next-auth/react";
9
 
10
  import { formatResponse } from "@/lib/format";
11
  import { File, Message, MessageActionType, ProviderType } from "@/lib/type";
12
  import { getContextFilesFromPrompt } from "@/lib/utils";
 
13
 
14
  const MESSAGES_QUERY_KEY = (projectName: string) =>
15
  ["messages", projectName] as const;
 
23
  `messages-${projectName}`,
24
  []
25
  );
26
+ const { data: session } = useSession();
27
 
28
  const { data: isLoading } = useQuery({
29
  queryKey: ["ai.generation.isLoading"],
 
350
  isThinking: false,
351
  isAborted: true,
352
  content: errorData?.showProMessage
353
+ ? session?.user?.isPro ? "You have already reached your monthly included credits with Hugging Face Pro plan. Please consider adding more credits to your account." : "You have exceeded your monthly included credits with Hugging Face inference provider. Please consider upgrading to a pro plan."
354
  : `Error: ${errorData.messageError}`,
355
  actions: errorData?.showProMessage
356
+ ? session?.user?.isPro ? [{
357
+ label: "Add more credits",
358
+ variant: "default",
359
+ type: MessageActionType.ADD_CREDITS,
360
+ }] : [
361
  {
362
  label: "Upgrade to Pro",
363
  variant: "pro",
components/chat/index.tsx CHANGED
@@ -19,7 +19,7 @@ import { MessageAction, MessageActionType, File } from "@/lib/type";
19
  import { Button } from "@/components/ui/button";
20
  import { getFileIcon } from "@/components/ask-ai/input-mentions";
21
  import ProIcon from "@/assets/pro.svg";
22
- import ProModal from "../pro-modal";
23
 
24
  export function AppEditorChat({
25
  isNew,
@@ -67,6 +67,11 @@ export function AppEditorChat({
67
  );
68
  case MessageActionType.UPGRADE_TO_PRO:
69
  return setOpenProModal(true);
 
 
 
 
 
70
  }
71
  };
72
 
 
19
  import { Button } from "@/components/ui/button";
20
  import { getFileIcon } from "@/components/ask-ai/input-mentions";
21
  import ProIcon from "@/assets/pro.svg";
22
+ import { ProModal } from "../pro-modal";
23
 
24
  export function AppEditorChat({
25
  isNew,
 
67
  );
68
  case MessageActionType.UPGRADE_TO_PRO:
69
  return setOpenProModal(true);
70
+ case MessageActionType.ADD_CREDITS:
71
+ return window.open(
72
+ "https://huggingface.co/settings/billing?add-credits=true",
73
+ "_blank"
74
+ );
75
  }
76
  };
77
 
components/pro-modal/index.tsx CHANGED
@@ -96,4 +96,3 @@ export const ProTag = ({
96
  PRO
97
  </span>
98
  );
99
- export default ProModal;
 
96
  PRO
97
  </span>
98
  );
 
lib/type.ts CHANGED
@@ -10,6 +10,7 @@ export enum MessageActionType {
10
  PUBLISH_PROJECT = "PUBLISH_PROJECT",
11
  SEE_LIVE_PREVIEW = "SEE_LIVE_PREVIEW",
12
  UPGRADE_TO_PRO = "UPGRADE_TO_PRO",
 
13
  }
14
  export type MessageAction = {
15
  label: string;
 
10
  PUBLISH_PROJECT = "PUBLISH_PROJECT",
11
  SEE_LIVE_PREVIEW = "SEE_LIVE_PREVIEW",
12
  UPGRADE_TO_PRO = "UPGRADE_TO_PRO",
13
+ ADD_CREDITS = "ADD_CREDITS",
14
  }
15
  export type MessageAction = {
16
  label: string;