mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
adds eslint
This commit is contained in:

committed by
Geoff Seemueller

parent
9698fc6f3b
commit
02c3253343
@@ -1,20 +1,17 @@
|
||||
export class Utils {
|
||||
static getSeason(date: string): string {
|
||||
const hemispheres = {
|
||||
Northern: ["Winter", "Spring", "Summer", "Autumn"],
|
||||
Southern: ["Summer", "Autumn", "Winter", "Spring"],
|
||||
Northern: ['Winter', 'Spring', 'Summer', 'Autumn'],
|
||||
Southern: ['Summer', 'Autumn', 'Winter', 'Spring'],
|
||||
};
|
||||
const d = new Date(date);
|
||||
const month = d.getMonth();
|
||||
const day = d.getDate();
|
||||
const hemisphere = "Northern";
|
||||
const hemisphere = 'Northern';
|
||||
|
||||
if (month < 2 || (month === 2 && day <= 20) || month === 11)
|
||||
return hemispheres[hemisphere][0];
|
||||
if (month < 5 || (month === 5 && day <= 21))
|
||||
return hemispheres[hemisphere][1];
|
||||
if (month < 8 || (month === 8 && day <= 22))
|
||||
return hemispheres[hemisphere][2];
|
||||
if (month < 2 || (month === 2 && day <= 20) || month === 11) return hemispheres[hemisphere][0];
|
||||
if (month < 5 || (month === 5 && day <= 21)) return hemispheres[hemisphere][1];
|
||||
if (month < 8 || (month === 8 && day <= 22)) return hemispheres[hemisphere][2];
|
||||
return hemispheres[hemisphere][3];
|
||||
}
|
||||
static getTimezone(timezone) {
|
||||
@@ -30,7 +27,7 @@ export class Utils {
|
||||
|
||||
static isAssetUrl(url) {
|
||||
const { pathname } = new URL(url);
|
||||
return pathname.startsWith("/assets/");
|
||||
return pathname.startsWith('/assets/');
|
||||
}
|
||||
|
||||
static selectEquitably({ a, b, c, d }, itemCount = 9) {
|
||||
@@ -39,9 +36,7 @@ export class Utils {
|
||||
|
||||
let combinedItems = [];
|
||||
sources.forEach((source, index) => {
|
||||
combinedItems.push(
|
||||
...Object.keys(source).map((key) => ({ source: index, key })),
|
||||
);
|
||||
combinedItems.push(...Object.keys(source).map(key => ({ source: index, key })));
|
||||
});
|
||||
|
||||
combinedItems = combinedItems.sort(() => Math.random() - 0.5);
|
||||
@@ -60,37 +55,35 @@ export class Utils {
|
||||
return result;
|
||||
}
|
||||
|
||||
static normalizeWithBlanks<T extends Normalize.ChatMessage>(msgs: T[]): T[] {
|
||||
static normalizeWithBlanks<T extends NormalizeChatMessage>(msgs: T[]): T[] {
|
||||
const out: T[] = [];
|
||||
|
||||
// In local mode first turn expected to be user.
|
||||
let expected: Normalize.Role = "user";
|
||||
let expected: NormalizeRole = 'user';
|
||||
|
||||
for (const m of msgs) {
|
||||
while (m.role !== expected) {
|
||||
// Insert blanks to match expected sequence user/assistant/user...
|
||||
out.push(Normalize.makeBlank(expected) as T);
|
||||
expected = expected === "user" ? "assistant" : "user";
|
||||
out.push(makeNormalizeBlank(expected) as T);
|
||||
expected = expected === 'user' ? 'assistant' : 'user';
|
||||
}
|
||||
|
||||
out.push(m);
|
||||
expected = expected === "user" ? "assistant" : "user";
|
||||
expected = expected === 'user' ? 'assistant' : 'user';
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module Normalize {
|
||||
export type Role = "user" | "assistant";
|
||||
// Normalize module exports
|
||||
export type NormalizeRole = 'user' | 'assistant';
|
||||
|
||||
export interface ChatMessage extends Record<any, any> {
|
||||
role: Role;
|
||||
}
|
||||
|
||||
export const makeBlank = (role: Role): ChatMessage => ({
|
||||
role,
|
||||
content: ""
|
||||
});
|
||||
export interface NormalizeChatMessage extends Record<any, any> {
|
||||
role: NormalizeRole;
|
||||
}
|
||||
|
||||
export const makeNormalizeBlank = (role: NormalizeRole): NormalizeChatMessage => ({
|
||||
role,
|
||||
content: '',
|
||||
});
|
||||
|
Reference in New Issue
Block a user