fixes tookens counter on infopage

This commit is contained in:
nai-degen
2023-09-02 18:49:14 -05:00
parent 6afb62fef6
commit a558920ccf
5 changed files with 15 additions and 5 deletions
+2 -1
View File
@@ -28,7 +28,8 @@
# TOKEN_QUOTA_TURBO=0
# TOKEN_QUOTA_GPT4=0
# TOKEN_QUOTA_CLAUDE=0
# QUOTA_REFRESH_PERIOD=hourly
# QUOTA_REFRESH_PERIOD=daily
# ALLOW_NICKNAME_CHANGES=true
# Optional settings for prompt logging. See docs/logging-sheets.md.
# PROMPT_LOGGING=false
+1 -1
View File
@@ -1,5 +1,5 @@
# Deploy to Render.com
Render.com offers a free tier that includes 750 hours of compute time per month. This is enough to run a single proxy instance 24/7. Instances shut down after 15 minutes without traffic but start up again automatically when a request is received.
Render.com offers a free tier that includes 750 hours of compute time per month. This is enough to run a single proxy instance 24/7. Instances shut down after 15 minutes without traffic but start up again automatically when a request is received. You can use something like https://app.checklyhq.com/ to ping your proxy every 15 minutes to keep it alive.
### 1. Create account
- [Sign up for Render.com](https://render.com/) to create an account and access the dashboard.
+7
View File
@@ -143,6 +143,11 @@ type Config = {
* Defaults to no automatic quota refresh.
*/
quotaRefreshPeriod?: "hourly" | "daily" | string;
/**
* Whether to allow users to change their nickname via the UI. Defaults to
* true.
**/
allowNicknameChanges: boolean;
};
// To change configs, create a file called .env in the root directory.
@@ -206,6 +211,7 @@ export const config: Config = {
claude: getEnvWithDefault("TOKEN_QUOTA_CLAUDE", 0),
},
quotaRefreshPeriod: getEnvWithDefault("QUOTA_REFRESH_PERIOD", undefined),
allowNicknameChanges: getEnvWithDefault("ALLOW_NICKNAME_CHANGES", true),
} as const;
function generateCookieSecret() {
@@ -306,6 +312,7 @@ export const OMITTED_KEYS: (keyof Config)[] = [
"blockedOrigins",
"blockMessage",
"blockRedirect",
"allowNicknameChanges",
];
const getKeys = Object.keys as <T extends object>(obj: T) => Array<keyof T>;
+1 -3
View File
@@ -87,9 +87,7 @@ function cacheInfoPageHtml(baseUrl: string) {
...(anthropicKeys ? { anthropic: baseUrl + "/proxy/anthropic" } : {}),
},
proompts,
...(config.showTokenCosts
? { tookens: `${prettyTokens(tokens)}${getCostString(tokenCost)}` }
: { tookens: tokens }),
tookens: `${prettyTokens(tokens)}${getCostString(tokenCost)}`,
...(config.modelRateLimit ? { proomptersNow: getUniqueIps() } : {}),
openaiKeys,
anthropicKeys,
+4
View File
@@ -3,6 +3,7 @@ import { UserSchema } from "../../shared/users/schema";
import * as userStore from "../../shared/users/user-store";
import { UserInputError } from "../../shared/errors";
import { sanitizeAndTrim } from "../../shared/utils";
import { config } from "../../config";
const router = Router();
@@ -27,6 +28,9 @@ router.post("/lookup", (req, res) => {
});
router.post("/edit-nickname", (req, res) => {
if (!config.allowNicknameChanges)
throw new UserInputError("Nickname changes are not allowed.");
const nicknameUpdateSchema = UserSchema.pick({ token: true, nickname: true })
.extend({
nickname: UserSchema.shape.nickname.transform((v) => sanitizeAndTrim(v)),