adds dall-e full history page and metadata downloader
This commit is contained in:
@@ -52,7 +52,7 @@ export const OpenAIV1ChatCompletionSchema = z
|
||||
.number()
|
||||
.int()
|
||||
.nullish()
|
||||
.default(OPENAI_OUTPUT_MAX)
|
||||
.default(Math.min(OPENAI_OUTPUT_MAX, 4096))
|
||||
.transform((v) => Math.min(v ?? OPENAI_OUTPUT_MAX, OPENAI_OUTPUT_MAX)),
|
||||
frequency_penalty: z.number().optional().default(0),
|
||||
presence_penalty: z.number().optional().default(0),
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
const IMAGE_HISTORY_SIZE = 30;
|
||||
const IMAGE_HISTORY_SIZE = 10000;
|
||||
const imageHistory = new Array<ImageHistory>(IMAGE_HISTORY_SIZE);
|
||||
let index = 0;
|
||||
|
||||
type ImageHistory = { url: string; prompt: string };
|
||||
type ImageHistory = { url: string; prompt: string, token?: string };
|
||||
|
||||
export function addToImageHistory(image: ImageHistory) {
|
||||
if (image.token?.length) {
|
||||
image.token = `...${image.token.slice(-5)}`;
|
||||
}
|
||||
imageHistory[index] = image;
|
||||
index = (index + 1) % IMAGE_HISTORY_SIZE;
|
||||
}
|
||||
|
||||
export function getLastNImages(n: number) {
|
||||
export function getLastNImages(n: number = IMAGE_HISTORY_SIZE): ImageHistory[] {
|
||||
const result: ImageHistory[] = [];
|
||||
let currentIndex = (index - 1 + IMAGE_HISTORY_SIZE) % IMAGE_HISTORY_SIZE;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import axios from "axios";
|
||||
import express from "express";
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import { v4 } from "uuid";
|
||||
@@ -53,10 +54,11 @@ async function createThumbnail(filepath: string) {
|
||||
* Mutates the result object.
|
||||
*/
|
||||
export async function mirrorGeneratedImage(
|
||||
host: string,
|
||||
req: express.Request,
|
||||
prompt: string,
|
||||
result: OpenAIImageGenerationResult
|
||||
): Promise<OpenAIImageGenerationResult> {
|
||||
const host = req.protocol + "://" + req.get("host");
|
||||
for (const item of result.data) {
|
||||
let mirror: string;
|
||||
if (item.b64_json) {
|
||||
@@ -66,7 +68,7 @@ export async function mirrorGeneratedImage(
|
||||
}
|
||||
item.url = `${host}/user_content/${path.basename(mirror)}`;
|
||||
await createThumbnail(mirror);
|
||||
addToImageHistory({ url: item.url, prompt });
|
||||
addToImageHistory({ url: item.url, prompt, token: req.user?.token ?? "" });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ export const injectLocals: RequestHandler = (req, res, next) => {
|
||||
res.locals.nextQuotaRefresh = userStore.getNextQuotaRefresh();
|
||||
res.locals.persistenceEnabled = config.gatekeeperStore !== "memory";
|
||||
res.locals.usersEnabled = config.gatekeeper === "user_token";
|
||||
res.locals.imageGenerationEnabled = config.allowedModelFamilies.some(
|
||||
(f) => ["dall-e", "azure-dall-e"].includes(f)
|
||||
);
|
||||
res.locals.showTokenCosts = config.showTokenCosts;
|
||||
res.locals.maxIps = config.maxIpsPerUser;
|
||||
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
<meta name="csrf-token" content="<%= csrfToken %>">
|
||||
<title><%= title %></title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
background-color: #e0e6f6;
|
||||
}
|
||||
@@ -69,9 +75,32 @@
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
background-color: #222;
|
||||
color: #eee;
|
||||
}
|
||||
|
||||
a:link, a:visited {
|
||||
color: #bbe;
|
||||
}
|
||||
|
||||
a:link:hover, a:visited:hover {
|
||||
background-color: #446;
|
||||
}
|
||||
|
||||
table.striped tr:nth-child(even) {
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
th.active {
|
||||
background-color: #446;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="font-family: sans-serif; background-color: #f0f0f0; padding: 1em;">
|
||||
<body>
|
||||
<%- include("partials/shared_flash", { flashData: flash }) %>
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<p>Next refresh: <time><%- nextQuotaRefresh %></time></p>
|
||||
<table>
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Model Family</th>
|
||||
|
||||
Reference in New Issue
Block a user