Skip to content

Commit

Permalink
🪙 feat: automatically add start balance (#168)
Browse files Browse the repository at this point in the history
* Adding information about the starting balance

* Adding information about the starting balance

* chore: type fixes

* fix: MDX build errors

* chore: explicit typing

* chore: improve typing for author metadata socials

* chore: strict assertion

---------

Co-authored-by: MSITE.TOP <[email protected]>
  • Loading branch information
danny-avila and MSITETOP authored Nov 16, 2024
1 parent 816db32 commit eec5608
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 10 deletions.
12 changes: 8 additions & 4 deletions components/Author/AuthorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ interface AuthorMetadata {
name: string
bio: string
ogImage: string
socials?: Record<string, string>
socials?: {
[key: string]: string
}
}

const AuthorCard: React.FC<{ author: AuthorMetadata }> = ({ author }) => {
Expand All @@ -21,7 +23,9 @@ const AuthorCard: React.FC<{ author: AuthorMetadata }> = ({ author }) => {
setIsClient(true)
}, [])

const socialsEntries = Object.entries(author.socials ?? {}).filter(([, value]) => !!value)
const socialsEntries = Object.entries(author.socials ?? {}).filter(
([, value]) => !!value,
) as unknown as [string, string][]

return (
<Link href={`/authors/${author.authorid}`}>
Expand All @@ -43,7 +47,7 @@ const AuthorCard: React.FC<{ author: AuthorMetadata }> = ({ author }) => {
socialsEntries.map(([key, value]) => (
<a
key={key}
href={value as string}
href={value}
className="btn btn-square relative overflow-hidden"
title={`See ${author.name}'s ${key}`}
target="_blank"
Expand All @@ -52,7 +56,7 @@ const AuthorCard: React.FC<{ author: AuthorMetadata }> = ({ author }) => {
onClick={(e) => e.stopPropagation()}
>
<SocialIcon
url={value as string}
url={value}
className="absolute inset-0 w-full h-full transform scale-100 transition-transform opacity-100 hover:scale-90"
bgColor="#9B9B9B80"
fgColor="background"
Expand Down
3 changes: 2 additions & 1 deletion components/home/components/HomeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import React, { forwardRef } from 'react'

export const HomeSection = forwardRef<
HTMLElement,
{ children: React.ReactNode; className?: string }
{ children: React.ReactNode; className?: string; id?: string }
>((props, ref) => {
return (
<section
id={props.id}
ref={ref}
className={cn(
'py-20 lg:py-32 mx-auto max-w-7xl px-5 sm:px-7 xl:px-10 first:pt-10 last:pb-40 last:lg:pb-52',
Expand Down
1 change: 1 addition & 0 deletions components/ui/accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
'use client'

import * as React from 'react'
Expand Down
1 change: 1 addition & 0 deletions components/ui/avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
'use client'

import * as React from 'react'
Expand Down
1 change: 1 addition & 0 deletions components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
'use client'

import * as React from 'react'
Expand Down
16 changes: 13 additions & 3 deletions components/ui/dropdown-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
'use client'

import * as React from 'react'
Expand All @@ -22,6 +23,7 @@ const DropdownMenuSubTrigger = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
inset?: boolean
children: React.ReactNode
}
>(({ className, inset, children, ...props }, ref) => (
<DropdownMenuPrimitive.SubTrigger
Expand Down Expand Up @@ -56,7 +58,9 @@ DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayNam

const DropdownMenuContent = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> & {
children?: React.ReactNode
}
>(({ className, sideOffset = 4, ...props }, ref) => (
<DropdownMenuPrimitive.Content
ref={ref}
Expand All @@ -75,6 +79,8 @@ const DropdownMenuItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean
children?: React.ReactNode
onClick?: (event: React.MouseEvent) => void
}
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Item
Expand All @@ -91,7 +97,9 @@ DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName

const DropdownMenuCheckboxItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem> & {
children: React.ReactNode
}
>(({ className, children, checked, ...props }, ref) => (
<DropdownMenuPrimitive.CheckboxItem
ref={ref}
Expand All @@ -114,7 +122,9 @@ DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displa

const DropdownMenuRadioItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem> & {
children: React.ReactNode
}
>(({ className, children, value, ...props }, ref) => (
<DropdownMenuPrimitive.RadioItem
ref={ref}
Expand Down
1 change: 1 addition & 0 deletions components/ui/form.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import * as React from 'react'
import * as LabelPrimitive from '@radix-ui/react-label'
import { Slot } from '@radix-ui/react-slot'
Expand Down
1 change: 1 addition & 0 deletions components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
'use client'

import * as React from 'react'
Expand Down
1 change: 1 addition & 0 deletions components/ui/select.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
'use client'

import * as React from 'react'
Expand Down
1 change: 1 addition & 0 deletions components/ui/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
'use client'

import * as React from 'react'
Expand Down
3 changes: 2 additions & 1 deletion pages/docs/configuration/dotenv.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,14 @@ see: **[Automated Moderation](/docs/configuration/mod_system)**

### Balance

The following enables user balances for the OpenAI/Plugins endpoints, which you can add manually or you will need to build out a balance accruing system for users.
The following feature allows for the management of user balances within the system's endpoints. You have the option to add balances manually, or you may choose to implement a system that accumulates balances automatically for users. If a specific initial balance is defined in the configuration, tokens will be credited to the user's balance automatically when they register.

see: **[Token Usage](/docs/configuration/token_usage)**

<OptionTable
options={[
['CHECK_BALANCE', 'boolean', 'Enable token credit balances for the OpenAI/Plugins endpoints.','CHECK_BALANCE=false'],
['START_BALANCE', 'integer', 'If the value is set, tokens will be credited to the user\'s balance after registration.', 'START_BALANCE=20000']
]}
/>

Expand Down
9 changes: 8 additions & 1 deletion pages/docs/configuration/token_usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ Currently, you can limit user token usage by enabling user balances. To enables
]}
/>

And You can also set the number of tokens a user will receive upon registration:

<OptionTable
options={[
['START_BALANCE', 'integer', 'If the value is set, tokens will be credited to the user\'s balance after registration.','START_BALANCE=20000']
]}
/>

You manually add user balance, or you will need to build out a balance-accruing system for users. This may come as a feature to the app whenever an admin dashboard is introduced.

Expand Down Expand Up @@ -101,4 +108,4 @@ There will be more customization for this soon from the `librechat.yaml` file.

![image](https://github.com/danny-avila/LibreChat/assets/110412045/39a1aa5d-f8fc-43bf-81f2-299e57d944bb)

![image](https://github.com/danny-avila/LibreChat/assets/110412045/e1b1cc3f-8981-4c7c-a5f8-e7badbc6f675)
![image](https://github.com/danny-avila/LibreChat/assets/110412045/e1b1cc3f-8981-4c7c-a5f8-e7badbc6f675)

0 comments on commit eec5608

Please sign in to comment.