From 161f5aba3ea0e16c55c552d9e88888ad2cad30bc Mon Sep 17 00:00:00 2001 From: nai-degen Date: Sun, 6 Oct 2024 11:03:48 -0500 Subject: [PATCH] handles sillytavern using both camel and snake-cased parameters for gemini api --- package-lock.json | 33 +++++++++++++++++++++++++++++ package.json | 1 + src/shared/api-schemas/google-ai.ts | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/package-lock.json b/package-lock.json index aa9da87..7e3e861 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,6 +49,7 @@ "source-map-support": "^0.5.21", "stream-json": "^1.8.0", "tiktoken": "^1.0.10", + "tinyws": "^0.1.0", "uuid": "^9.0.0", "zlib": "^1.0.5", "zod": "^3.22.3", @@ -6611,6 +6612,17 @@ "resolved": "https://registry.npmjs.org/tiktoken/-/tiktoken-1.0.14.tgz", "integrity": "sha512-g5zd5r/DoH8Kw0fiYbYpVhb6WO8BHO1unXqmBBWKwoT17HwSounnDtMDFUKm2Pko8U47sjQarOe+9aUrnqmmTg==" }, + "node_modules/tinyws": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/tinyws/-/tinyws-0.1.0.tgz", + "integrity": "sha512-6WQ2FlFM7qm6lAXxeKnzsAEfmnBHz5W5EwonNs52V0++YfK1IoCCAWM429afcChFE9BFrDgOFnq7ligaWMsa/A==", + "engines": { + "node": ">=12.4" + }, + "peerDependencies": { + "ws": ">=8" + } + }, "node_modules/tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -6945,6 +6957,27 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "node_modules/ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "peer": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index db72180..7b9cc48 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "source-map-support": "^0.5.21", "stream-json": "^1.8.0", "tiktoken": "^1.0.10", + "tinyws": "^0.1.0", "uuid": "^9.0.0", "zlib": "^1.0.5", "zod": "^3.22.3", diff --git a/src/shared/api-schemas/google-ai.ts b/src/shared/api-schemas/google-ai.ts index 3cad3fe..5919ab5 100644 --- a/src/shared/api-schemas/google-ai.ts +++ b/src/shared/api-schemas/google-ai.ts @@ -37,6 +37,10 @@ export const GoogleAIV1GenerateContentSchema = z tools: z.array(z.object({})).max(0).optional(), safetySettings: SafetySettingsSchema, systemInstruction: GoogleAIV1ContentSchema.optional(), + // quick fix for SillyTavern, which uses camel case field names for everything + // except for system_instruction where it randomly uses snake case. + // google api evidently accepts either case. + "system_instruction": GoogleAIV1ContentSchema.optional(), generationConfig: z .object({ temperature: z.number().min(0).max(2).optional(),