move max_photo_size to environment variable
This commit is contained in:
@@ -34,7 +34,7 @@ export class OllamaChat extends ChatCommand {
|
|||||||
|
|
||||||
let imageFilePath: string | null = null;
|
let imageFilePath: string | null = null;
|
||||||
|
|
||||||
const maxSize = await getPhotoMaxSize(msg.photo, 600);
|
const maxSize = await getPhotoMaxSize(msg.photo);
|
||||||
if (maxSize) {
|
if (maxSize) {
|
||||||
const res = await axios.get<ArrayBuffer>(maxSize.url, {responseType: "arraybuffer"});
|
const res = await axios.get<ArrayBuffer>(maxSize.url, {responseType: "arraybuffer"});
|
||||||
const src = Buffer.from(res.data);
|
const src = Buffer.from(res.data);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export class Environment {
|
|||||||
static OLLAMA_API_KEY?: string;
|
static OLLAMA_API_KEY?: string;
|
||||||
static SYSTEM_PROMPT?: string;
|
static SYSTEM_PROMPT?: string;
|
||||||
|
|
||||||
|
static MAX_PHOTO_SIZE: number;
|
||||||
|
|
||||||
static GEMINI_API_KEY?: string;
|
static GEMINI_API_KEY?: string;
|
||||||
|
|
||||||
static waitText = "⏳ Дайте-ка подумать...";
|
static waitText = "⏳ Дайте-ка подумать...";
|
||||||
@@ -45,6 +47,8 @@ export class Environment {
|
|||||||
Environment.OLLAMA_API_KEY = process.env.OLLAMA_API_KEY;
|
Environment.OLLAMA_API_KEY = process.env.OLLAMA_API_KEY;
|
||||||
Environment.SYSTEM_PROMPT = process.env.SYSTEM_PROMPT?.trim();
|
Environment.SYSTEM_PROMPT = process.env.SYSTEM_PROMPT?.trim();
|
||||||
|
|
||||||
|
Environment.MAX_PHOTO_SIZE = Number(process.env.MAX_PHOTO_SIZE || "1280");
|
||||||
|
|
||||||
Environment.GEMINI_API_KEY = process.env.GEMINI_API_KEY;
|
Environment.GEMINI_API_KEY = process.env.GEMINI_API_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -754,7 +754,7 @@ export function getRuntimeInfo(): RuntimeInfo {
|
|||||||
|
|
||||||
export type PhotoMaxSize = { width: number, height: number, url: string; unique_file_id: string; };
|
export type PhotoMaxSize = { width: number, height: number, url: string; unique_file_id: string; };
|
||||||
|
|
||||||
export async function getPhotoMaxSize(photos: PhotoSize[], target: number = 1280): Promise<PhotoMaxSize | null> {
|
export async function getPhotoMaxSize(photos: PhotoSize[], target: number = Environment.MAX_PHOTO_SIZE): Promise<PhotoMaxSize | null> {
|
||||||
if (!photos) return null;
|
if (!photos) return null;
|
||||||
|
|
||||||
photos = photos.filter(p => Math.max(p.width, p.height) <= target);
|
photos = photos.filter(p => Math.max(p.width, p.height) <= target);
|
||||||
|
|||||||
Reference in New Issue
Block a user