Skip to content

Commit

Permalink
chore: update webhook timeout, param desc and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Nov 27, 2024
1 parent d5f3827 commit 35b07d1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions src/adapters/openai/openai.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import OpenAI from "openai";
import { PluginContext } from "../../types/plugin-context-single";
import { logger } from "../../utils/logger";
import { Context } from "../../types";

Expand Down Expand Up @@ -86,15 +85,13 @@ export class Completions {
query: string;
model: string;
}): Promise<string> {
const config = PluginContext.getInstance().config;
const ctxWindow = this.createSystemMessage(params);

logger.info("ctxWindow:\n\n", { ctxWindow });

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",
},
Expand Down
2 changes: 1 addition & 1 deletion src/bot/features/commands/shared/ask-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
1 change: 1 addition & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function createServer(dependencies: Dependencies) {
},
webhookCallback(bot, "hono", {
secretToken: TELEGRAM_BOT_WEBHOOK_SECRET,
timeoutMilliseconds: 60_000,
})
);

Expand Down
12 changes: 10 additions & 2 deletions src/types/plugin-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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." }),
}),
],
Expand Down
6 changes: 3 additions & 3 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
});

/**
Expand Down
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 35b07d1

Please sign in to comment.