feat(openai): add chat streaming and model commands
- add /openai (/chatgpt) chat command using OpenAI Responses API (streaming + incremental edits) - add /openAIListModels, /openAIGetModel, /openAISetModel - introduce base Command class and migrate non-chat commands to it - wire OpenAI client + env vars (OPENAI_API_KEY, OPENAI_MODEL) - bump deps (@google/genai, systeminformation, @types/node) and add openai
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import {Command} from "../base/command";
|
||||
import {Requirements} from "../base/requirements";
|
||||
import {Requirement} from "../base/requirement";
|
||||
import {Message} from "typescript-telegram-bot-api";
|
||||
import {openAi} from "../index";
|
||||
import {logError, replyToMessage} from "../util/utils";
|
||||
|
||||
export class OpenAIListModels extends Command {
|
||||
title = "/openAIListModels";
|
||||
description = "List all OpenAI models";
|
||||
|
||||
requirements = Requirements.Build(Requirement.BOT_CREATOR);
|
||||
|
||||
async execute(msg: Message): Promise<void> {
|
||||
try {
|
||||
const listResponse = await openAi.models.list();
|
||||
console.log(listResponse);
|
||||
|
||||
const modelsString = listResponse.data
|
||||
.map(e => `${e.id}`)
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.join("\n")
|
||||
.substring(0, 4000);
|
||||
|
||||
const text = "Доступные модели:\n\n" + "<blockquote expandable>" + modelsString + "</blockquote>";
|
||||
|
||||
await replyToMessage({
|
||||
message: msg,
|
||||
text: text,
|
||||
parse_mode: "HTML"
|
||||
});
|
||||
} catch (e) {
|
||||
logError(e);
|
||||
await replyToMessage({message: msg, text: "Не получилось загрузить список моделей"}).catch(logError);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user