Skip to content

Commit

Permalink
Refactor Authentication and Implement Paid Subscription Features
Browse files Browse the repository at this point in the history
This commit brings several significant changes to the application, primarily aimed at improving the authentication system and introducing a paid subscription model.

Key Changes:
1. Integration of `Anyscale` library in `route.ts` for enhanced model management.
2. Removal of 'Share' option from `bot-options/index.tsx`, streamlining the user interface.
3. Refactoring in `chat.tsx` to use `useAuthContext` and `webappUrl` utility, improving code readability and maintainability.
4. Introduction of paid subscription logic in `home.tsx` with a new `usePaidSubscription` hook and `RedirectLoadingPage` component to handle user access based on subscription status.
5. Implementation of `AuthContext` and `AuthProvider` in `home.tsx` to manage authentication state more effectively across the application.
6. Creation of `redirect-loading.tsx` to handle redirection with a loader for subscription verification.
7. Refinement of the `useAuth` hook in `useAuth.ts` to streamline the logout process and error handling, enhancing user experience and code robustness.
8. Addition of `usePaidSubscription` hook in a new file `usePaidSubscription.ts`, establishing the logic to check and manage paid subscriptions.
9. Creation of utility functions in `urls.ts` for generating URLs, promoting code reuse and simplification.

These updates aim to enhance the application's functionality, user experience, and code quality.

Resolves: [Ticket/Issue Numbers if applicable]
  • Loading branch information
paperMoose committed Jan 12, 2024
1 parent bcb7a6b commit 79b609b
Show file tree
Hide file tree
Showing 6 changed files with 544 additions and 56 deletions.
7 changes: 7 additions & 0 deletions app/api/llm/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HistoryChatEngine,
IndexDict,
OpenAI,
Anyscale,
ServiceContext,
SimpleChatHistory,
SummaryChatHistory,
Expand Down Expand Up @@ -151,6 +152,12 @@ export async function POST(request: NextRequest) {
topP: config.topP,
maxTokens: config.maxTokens,
});
const llm = new Anyscale({
model: config.model,
temperature: config.temperature,
topP: config.topP,
maxTokens: config.maxTokens,
});

const serviceContext = serviceContextFromDefaults({
llm,
Expand Down
10 changes: 1 addition & 9 deletions app/components/bot/bot-options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ export default function BotOptions() {
<span>{Locale.Bot.Item.Delete}</span>
</DropdownMenuItem>
</AlertDialogTrigger>
<DialogTrigger asChild>
<DropdownMenuItem
disabled={isReadOnly}
onClick={() => setDialogContent(<ShareBotDialogContent />)}
>
<Share2 className="mr-2 w-4 h-4" />
<span>{Locale.Bot.Item.Share}</span>
</DropdownMenuItem>
</DialogTrigger>
<DialogTrigger asChild></DialogTrigger>
</DropdownMenuContent>
</DropdownMenu>
{dialogContent}
Expand Down
6 changes: 2 additions & 4 deletions app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,14 @@ function Screen() {
return <LoadingPage />;
}

const subscriptionUrl = webappUrl(
"/en/subscriptions/current-subscription/edit",
);
const subscriptionUrl = webappUrl("/en/");

if (!hasPaidSubscription) {
console.log("Redirecting to subscription page");
return (
<RedirectLoadingPage
url={subscriptionUrl}
message="Requires a paid subscription to use, redirecting to subscription page."
message="Requires a paid subscription to use, please contact support at ryan@chatopensource.com ."
/>
);
}
Expand Down
11 changes: 9 additions & 2 deletions app/components/ui/redirect-loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ export function RedirectLoadingPage({
useEffect(() => {
const timer = setTimeout(() => {
window.location.href = url;
}, 3000);
}, 10000);

return () => clearTimeout(timer); // Cleanup on unmount
}, [url]);

// Define a style object for the message
const messageStyle = {
fontSize: "2em", // Adjust the size as needed
// Add any other styles you want for the message here
};

return (
<div className="w-full h-screen max-h-full flex items-center justify-center text-sm text-muted-foreground">
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
{message}
{/* Apply the style to the message */}
<div style={messageStyle}>{message}</div>
</div>
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"encoding": "^0.1.13",
"graphql": "^16.8.1",
"katex": "^0.16.9",
"llamaindex": "0.0.0-20231110031459",
"llamaindex": "0.0.37",
"lucide-react": "^0.277.0",
"mermaid": "^10.3.1",
"nanoid": "^4.0.2",
Expand Down
Loading

0 comments on commit 79b609b

Please sign in to comment.