From 35b07d1e4d8b96598b4e680edf88b2a90eddc15f Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:50:06 +0000 Subject: [PATCH] chore: update webhook timeout, param desc and examples --- package.json | 3 ++- src/adapters/openai/openai.ts | 3 --- src/bot/features/commands/shared/ask-command.ts | 2 +- src/server/index.ts | 1 + src/types/plugin-inputs.ts | 12 ++++++++++-- tests/main.test.ts | 6 +++--- yarn.lock | 16 ++++++++++++++++ 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index cbce46e..ce082a0 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "knip": "knip --config .github/knip.ts", "knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts", "prepare": "husky install", - "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage", + "test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage", "worker": "wrangler dev --env dev --port 3000", "deploy": "wrangler deploy --env dev", "sms-auth": "npx tsx src/bot/mtproto-api/bot/scripts/sms-auth/sms-auth.ts", @@ -66,6 +66,7 @@ "@mswjs/data": "0.16.1", "@types/jest": "^29.5.12", "@types/node": "20.14.5", + "cross-env": "^7.0.3", "cspell": "8.14.2", "eslint": "9.9.1", "eslint-config-prettier": "9.1.0", diff --git a/src/adapters/openai/openai.ts b/src/adapters/openai/openai.ts index b727930..98ea1b6 100644 --- a/src/adapters/openai/openai.ts +++ b/src/adapters/openai/openai.ts @@ -1,5 +1,4 @@ import OpenAI from "openai"; -import { PluginContext } from "../../types/plugin-context-single"; import { logger } from "../../utils/logger"; import { Context } from "../../types"; @@ -86,7 +85,6 @@ export class Completions { query: string; model: string; }): Promise { - const config = PluginContext.getInstance().config; const ctxWindow = this.createSystemMessage(params); logger.info("ctxWindow:\n\n", { ctxWindow }); @@ -94,7 +92,6 @@ export class Completions { const res: OpenAI.Chat.Completions.ChatCompletion = await this.client.chat.completions.create({ model: params.model, messages: ctxWindow, - max_completion_tokens: config.aiConfig.maxCompletionTokens, response_format: { type: "text", }, diff --git a/src/bot/features/commands/shared/ask-command.ts b/src/bot/features/commands/shared/ask-command.ts index 8e98ab2..4cc9d2d 100644 --- a/src/bot/features/commands/shared/ask-command.ts +++ b/src/bot/features/commands/shared/ask-command.ts @@ -24,7 +24,7 @@ feature.command("ubiquityos", logHandle("command-ubiquityos"), chatAction("typin const constraints = [ "Ensure the response is crafted from the corpus provided, without introducing information outside of what's available or relevant to the query.", "Consider edge cases where the corpus might lack explicit answers, and justify responses with logical reasoning based on the existing information.", - "Replies MUST be in Markdown V1 format.", + "Replies MUST be in Markdown V1 format but do not wrap in code blocks.", ]; const outputStyle = "Concise and coherent responses in paragraphs that directly address the user's question."; diff --git a/src/server/index.ts b/src/server/index.ts index a92ff30..07a1e55 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -84,6 +84,7 @@ export function createServer(dependencies: Dependencies) { }, webhookCallback(bot, "hono", { secretToken: TELEGRAM_BOT_WEBHOOK_SECRET, + timeoutMilliseconds: 60_000, }) ); diff --git a/src/types/plugin-inputs.ts b/src/types/plugin-inputs.ts index 71d400b..0ff13c1 100644 --- a/src/types/plugin-inputs.ts +++ b/src/types/plugin-inputs.ts @@ -26,13 +26,21 @@ export const pluginSettingsSchema = T.Object({ T.Object({ kind: T.Literal("OpenAi", { description: "The API provider you wish to use.", examples: ["OpenAi", "OpenRouter"] }), model: T.String({ default: "o1-mini", description: "The model to use.", examples: ["o1-mini", "gpt-4o"] }), - baseUrl: T.String({ default: "https://api.openai.com/v1", description: "The base URL of the API.", examples: ["https://api.openai.com/v1", "https://api.openai.com/v2"] }), + baseUrl: T.String({ + default: "https://api.openai.com/v1", + description: "The base URL of the API.", + examples: ["https://api.openai.com/v1", "https://api.openai.com/v2"], + }), similarityThreshold: T.Number({ default: 0.9, description: "The similarity threshold for when fetching embeddings-based context." }), }), T.Object({ kind: T.Literal("OpenRouter", { description: "The API provider you wish to use.", examples: ["OpenAi", "OpenRouter"] }), model: T.String({ default: "openai/o1-mini", description: "The model to use.", examples: ["openai/o1-mini", "openai/gpt-4o"] }), - baseUrl: T.String({ default: "https://openrouter.ai/api/v1", description: "The base URL of the API.", examples: ["https://openrouter.ai/api/v1", "https://openrouter.ai/api/v2"] }), + baseUrl: T.String({ + default: "https://openrouter.ai/api/v1", + description: "The base URL of the API.", + examples: ["https://openrouter.ai/api/v1", "https://openrouter.ai/api/v2"], + }), similarityThreshold: T.Number({ default: 0.9, description: "The similarity threshold for when fetching embeddings-based context." }), }), ], diff --git a/tests/main.test.ts b/tests/main.test.ts index b3f51eb..a2e944b 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -3,9 +3,10 @@ import { db } from "./__mocks__/db"; import { server } from "./__mocks__/node"; import { expect, describe, beforeAll, beforeEach, afterAll, afterEach, it, jest } from "@jest/globals"; import { setupTests } from "./__mocks__/helpers"; -import manifest from "../manifest.json"; import dotenv from "dotenv"; import { Env } from "../src/types"; +import manifest from "../manifest.json"; +import worker from "../src/worker"; dotenv.config(); @@ -25,12 +26,11 @@ describe("Plugin tests", () => { }); it("Should serve the manifest file", async () => { - const { default: worker } = await import("../src/worker"); const response = await worker.fetch(new Request("http://localhost/manifest.json"), {} as Env); const body = await response.json(); expect(response.status).toBe(200); expect(body).toEqual(manifest); - }); + }, 10000); }); /** diff --git a/yarn.lock b/yarn.lock index 845da7c..274e6b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4150,6 +4150,13 @@ create-jest@^29.7.0: jest-util "^29.7.0" prompts "^2.0.1" +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + cross-spawn@^6.0.5: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" @@ -4161,6 +4168,15 @@ cross-spawn@^6.0.5: shebang-command "^1.2.0" which "^1.2.9" +cross-spawn@^7.0.1: + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== + dependencies: + path-key "^3.1.0" + shebang-command "^2.0.0" + which "^2.0.1" + cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"