Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- [ ] Show mqtt progress more verbose
- [ ] showTelegramNames is deprecated, remove it from the project
- [x] showTelegramNames is deprecated, remove it from the project
- [ ] When chat has bot_name, and I've added the bot to the new group, bot doesn't check access level
- [ ] Сделать миграцию на новый `npm install openai`. Инструкция по миграции - https://github.com/openai/openai-node/blob/master/MIGRATION.md
- [ ] Tool change_access_settings, for add/remove users to/from adminUsers, privateUsers -
- [ ] В проекте есть скрытые замены "confirm", "noconfirm"
- [ ] В addToHistory инициализируется threads, это неочевидно. Нужно вынести инициализацию threads в отдельную функцию
- [ ] Убрать showTelegramNames
- [x] Убрать showTelegramNames
17 changes: 12 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export function generateConfig(): ConfigType {
deleteToolAnswers: 60,
confirmation: false,
showToolMessages: true,
showTelegramNames: false,
},
toolParams: {
brainstorm: {
Expand Down Expand Up @@ -176,7 +175,6 @@ export function generateConfig(): ConfigType {
deleteToolAnswers: 60,
confirmation: false,
showToolMessages: true,
showTelegramNames: false,
},
toolParams: {
brainstorm: {
Expand Down Expand Up @@ -247,9 +245,18 @@ export function checkConfigSchema(config: ConfigType) {
(c) => c.name === "full-example",
) as ConfigChatType;
const chatKeys = Object.keys(exampleChat) as Array<keyof ConfigChatType>;
config.chats.forEach((c, idx) =>
checkKeys(c as Record<string, unknown>, chatKeys, `chats[${idx}].`),
);
config.chats.forEach((c, idx) => {
checkKeys(c as Record<string, unknown>, chatKeys, `chats[${idx}].`);
if (
c.chatParams &&
"showTelegramNames" in (c.chatParams as Record<string, unknown>)
) {
log({
msg: `chats[${c.name || idx}].chatParams.showTelegramNames is deprecated`,
logLevel: "warn",
});
}
});
}

export function logConfigChanges(oldConfig: ConfigType, newConfig: ConfigType) {
Expand Down
10 changes: 2 additions & 8 deletions src/helpers/history.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Message } from "telegraf/types";
import { ConfigChatType } from "../types.ts";
import { getFullName, isOurUser } from "../telegram/send.ts";
import { isOurUser } from "../telegram/send.ts";
import OpenAI from "openai";
import { useThreads } from "../threads.ts";

Expand All @@ -25,13 +25,7 @@ export function buildUserMessage(
msg: Message.TextMessage,
chatConfig: ConfigChatType,
): OpenAI.ChatCompletionMessageParam {
let content = msg.text || "";
if (chatConfig.chatParams?.showTelegramNames) {
const name = getFullName(msg);
if (name) {
content = `${name}:\n${content}`;
}
}
const content = msg.text || "";
const sender = msg.forward_from || msg.from;
const isOur = isOurUser(sender, chatConfig);
let name = sender?.first_name || sender?.last_name || sender?.username;
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export type ChatParamsType = {
memoryless?: boolean;
forgetTimeout?: number; // in seconds
showToolMessages?: true | false | undefined | "headers";
showTelegramNames?: boolean; // deprecated
markOurUsers?: string;
placeholderCacheTime?: number;
};
Expand Down
1 change: 0 additions & 1 deletion testConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ chats:
deleteToolAnswers: 60
confirmation: false
showToolMessages: true
showTelegramNames: false
toolParams:
brainstorm:
promptBefore: Составь только краткий план действий.
Expand Down
11 changes: 11 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,15 @@ describe("checkConfigSchema", () => {
readConfig("testConfig.yml");
expect(console.warn).toHaveBeenCalled();
});

it("warns about deprecated showTelegramNames", () => {
mockExistsSync.mockReturnValue(true);
const cfg = generateConfig();
cfg.chats[0].chatParams = { showTelegramNames: true } as unknown as Record<string, unknown>;
mockReadFileSync.mockReturnValue("yaml");
mockLoad.mockReturnValue(cfg);

readConfig("testConfig.yml");
expect(console.warn).toHaveBeenCalled();
});
});
6 changes: 3 additions & 3 deletions tests/helpers/history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ describe("history helpers", () => {
toolParams: {},
} as ConfigChatType;

it("adds message with username", () => {
it("adds message", () => {
const msg = createMsg("hi");
addToHistory(msg, { ...baseChat, chatParams: { showTelegramNames: true } });
addToHistory(msg, baseChat);
expect(threads[1].messages[0]).toEqual({
role: "user",
content: "John Doe:\nhi",
content: "hi",
name: "John",
});
expect(threads[1].msgs[0]).toBe(msg);
Expand Down