neogram 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +1239 -0
- package/package.json +56 -0
- package/src/Bot.js +4419 -0
- package/src/TelegramObject.js +106 -0
- package/src/ai/ChatGPT.js +77 -0
- package/src/ai/Deef.js +170 -0
- package/src/ai/OnlySQ.js +126 -0
- package/src/index.js +290 -0
- package/src/types/AcceptedGiftTypes.js +10 -0
- package/src/types/AffiliateInfo.js +10 -0
- package/src/types/Animation.js +10 -0
- package/src/types/Audio.js +10 -0
- package/src/types/BackgroundFill.js +5 -0
- package/src/types/BackgroundFillFreeformGradient.js +10 -0
- package/src/types/BackgroundFillGradient.js +10 -0
- package/src/types/BackgroundFillSolid.js +10 -0
- package/src/types/BackgroundType.js +5 -0
- package/src/types/BackgroundTypeChatTheme.js +10 -0
- package/src/types/BackgroundTypeFill.js +10 -0
- package/src/types/BackgroundTypePattern.js +10 -0
- package/src/types/BackgroundTypeWallpaper.js +10 -0
- package/src/types/Birthdate.js +10 -0
- package/src/types/BotCommand.js +10 -0
- package/src/types/BotCommandScope.js +5 -0
- package/src/types/BotCommandScopeAllChatAdministrators.js +10 -0
- package/src/types/BotCommandScopeAllGroupChats.js +10 -0
- package/src/types/BotCommandScopeAllPrivateChats.js +10 -0
- package/src/types/BotCommandScopeChat.js +10 -0
- package/src/types/BotCommandScopeChatAdministrators.js +10 -0
- package/src/types/BotCommandScopeChatMember.js +10 -0
- package/src/types/BotCommandScopeDefault.js +10 -0
- package/src/types/BotDescription.js +10 -0
- package/src/types/BotName.js +10 -0
- package/src/types/BotShortDescription.js +10 -0
- package/src/types/BusinessBotRights.js +10 -0
- package/src/types/BusinessConnection.js +10 -0
- package/src/types/BusinessIntro.js +10 -0
- package/src/types/BusinessLocation.js +10 -0
- package/src/types/BusinessMessagesDeleted.js +10 -0
- package/src/types/BusinessOpeningHours.js +10 -0
- package/src/types/BusinessOpeningHoursInterval.js +10 -0
- package/src/types/CallbackGame.js +5 -0
- package/src/types/CallbackQuery.js +26 -0
- package/src/types/Chat.js +10 -0
- package/src/types/ChatAdministratorRights.js +10 -0
- package/src/types/ChatBackground.js +10 -0
- package/src/types/ChatBoost.js +10 -0
- package/src/types/ChatBoostAdded.js +10 -0
- package/src/types/ChatBoostRemoved.js +10 -0
- package/src/types/ChatBoostSource.js +5 -0
- package/src/types/ChatBoostSourceGiftCode.js +10 -0
- package/src/types/ChatBoostSourceGiveaway.js +10 -0
- package/src/types/ChatBoostSourcePremium.js +10 -0
- package/src/types/ChatBoostUpdated.js +10 -0
- package/src/types/ChatFullInfo.js +10 -0
- package/src/types/ChatInviteLink.js +10 -0
- package/src/types/ChatJoinRequest.js +10 -0
- package/src/types/ChatLocation.js +10 -0
- package/src/types/ChatMember.js +5 -0
- package/src/types/ChatMemberAdministrator.js +10 -0
- package/src/types/ChatMemberBanned.js +10 -0
- package/src/types/ChatMemberLeft.js +10 -0
- package/src/types/ChatMemberMember.js +10 -0
- package/src/types/ChatMemberOwner.js +10 -0
- package/src/types/ChatMemberRestricted.js +10 -0
- package/src/types/ChatMemberUpdated.js +10 -0
- package/src/types/ChatPermissions.js +10 -0
- package/src/types/ChatPhoto.js +10 -0
- package/src/types/ChatShared.js +10 -0
- package/src/types/Checklist.js +10 -0
- package/src/types/ChecklistTask.js +10 -0
- package/src/types/ChecklistTasksAdded.js +10 -0
- package/src/types/ChecklistTasksDone.js +10 -0
- package/src/types/ChosenInlineResult.js +10 -0
- package/src/types/Contact.js +10 -0
- package/src/types/CopyTextButton.js +10 -0
- package/src/types/Dice.js +10 -0
- package/src/types/DirectMessagePriceChanged.js +10 -0
- package/src/types/DirectMessagesTopic.js +10 -0
- package/src/types/Document.js +10 -0
- package/src/types/EncryptedCredentials.js +10 -0
- package/src/types/EncryptedPassportElement.js +10 -0
- package/src/types/ExternalReplyInfo.js +10 -0
- package/src/types/File.js +10 -0
- package/src/types/ForceReply.js +10 -0
- package/src/types/ForumTopic.js +10 -0
- package/src/types/ForumTopicClosed.js +5 -0
- package/src/types/ForumTopicCreated.js +10 -0
- package/src/types/ForumTopicEdited.js +10 -0
- package/src/types/ForumTopicReopened.js +5 -0
- package/src/types/Game.js +10 -0
- package/src/types/GameHighScore.js +10 -0
- package/src/types/GeneralForumTopicHidden.js +5 -0
- package/src/types/GeneralForumTopicUnhidden.js +5 -0
- package/src/types/Gift.js +10 -0
- package/src/types/GiftBackground.js +10 -0
- package/src/types/GiftInfo.js +10 -0
- package/src/types/Gifts.js +10 -0
- package/src/types/Giveaway.js +10 -0
- package/src/types/GiveawayCompleted.js +10 -0
- package/src/types/GiveawayCreated.js +10 -0
- package/src/types/GiveawayWinners.js +10 -0
- package/src/types/InaccessibleMessage.js +10 -0
- package/src/types/InlineKeyboardButton.js +10 -0
- package/src/types/InlineKeyboardMarkup.js +10 -0
- package/src/types/InlineQuery.js +24 -0
- package/src/types/InlineQueryResult.js +5 -0
- package/src/types/InlineQueryResultArticle.js +10 -0
- package/src/types/InlineQueryResultAudio.js +10 -0
- package/src/types/InlineQueryResultCachedAudio.js +10 -0
- package/src/types/InlineQueryResultCachedDocument.js +10 -0
- package/src/types/InlineQueryResultCachedGif.js +10 -0
- package/src/types/InlineQueryResultCachedMpeg4Gif.js +10 -0
- package/src/types/InlineQueryResultCachedPhoto.js +10 -0
- package/src/types/InlineQueryResultCachedSticker.js +10 -0
- package/src/types/InlineQueryResultCachedVideo.js +10 -0
- package/src/types/InlineQueryResultCachedVoice.js +10 -0
- package/src/types/InlineQueryResultContact.js +10 -0
- package/src/types/InlineQueryResultDocument.js +10 -0
- package/src/types/InlineQueryResultGame.js +10 -0
- package/src/types/InlineQueryResultGif.js +10 -0
- package/src/types/InlineQueryResultLocation.js +10 -0
- package/src/types/InlineQueryResultMpeg4Gif.js +10 -0
- package/src/types/InlineQueryResultPhoto.js +10 -0
- package/src/types/InlineQueryResultVenue.js +10 -0
- package/src/types/InlineQueryResultVideo.js +10 -0
- package/src/types/InlineQueryResultVoice.js +10 -0
- package/src/types/InlineQueryResultsButton.js +10 -0
- package/src/types/InputChecklist.js +10 -0
- package/src/types/InputChecklistTask.js +10 -0
- package/src/types/InputContactMessageContent.js +10 -0
- package/src/types/InputFile.js +5 -0
- package/src/types/InputInvoiceMessageContent.js +10 -0
- package/src/types/InputLocationMessageContent.js +10 -0
- package/src/types/InputMedia.js +5 -0
- package/src/types/InputMediaAnimation.js +14 -0
- package/src/types/InputMediaAudio.js +14 -0
- package/src/types/InputMediaDocument.js +14 -0
- package/src/types/InputMediaPhoto.js +14 -0
- package/src/types/InputMediaVideo.js +14 -0
- package/src/types/InputMessageContent.js +5 -0
- package/src/types/InputPaidMedia.js +5 -0
- package/src/types/InputPaidMediaPhoto.js +10 -0
- package/src/types/InputPaidMediaVideo.js +10 -0
- package/src/types/InputPollOption.js +10 -0
- package/src/types/InputProfilePhoto.js +5 -0
- package/src/types/InputProfilePhotoAnimated.js +10 -0
- package/src/types/InputProfilePhotoStatic.js +10 -0
- package/src/types/InputSticker.js +10 -0
- package/src/types/InputStoryContent.js +5 -0
- package/src/types/InputStoryContentPhoto.js +10 -0
- package/src/types/InputStoryContentVideo.js +10 -0
- package/src/types/InputTextMessageContent.js +10 -0
- package/src/types/InputVenueMessageContent.js +10 -0
- package/src/types/Invoice.js +10 -0
- package/src/types/KeyboardButton.js +10 -0
- package/src/types/KeyboardButtonPollType.js +10 -0
- package/src/types/KeyboardButtonRequestChat.js +10 -0
- package/src/types/KeyboardButtonRequestUsers.js +10 -0
- package/src/types/LabeledPrice.js +10 -0
- package/src/types/LinkPreviewOptions.js +10 -0
- package/src/types/Location.js +10 -0
- package/src/types/LocationAddress.js +10 -0
- package/src/types/LoginUrl.js +10 -0
- package/src/types/MaskPosition.js +10 -0
- package/src/types/MaybeInaccessibleMessage.js +5 -0
- package/src/types/MenuButton.js +5 -0
- package/src/types/MenuButtonCommands.js +10 -0
- package/src/types/MenuButtonDefault.js +10 -0
- package/src/types/MenuButtonWebApp.js +10 -0
- package/src/types/Message.js +10 -0
- package/src/types/MessageAutoDeleteTimerChanged.js +10 -0
- package/src/types/MessageEntity.js +10 -0
- package/src/types/MessageId.js +10 -0
- package/src/types/MessageOrigin.js +5 -0
- package/src/types/MessageOriginChannel.js +10 -0
- package/src/types/MessageOriginChat.js +10 -0
- package/src/types/MessageOriginHiddenUser.js +10 -0
- package/src/types/MessageOriginUser.js +10 -0
- package/src/types/MessageReactionCountUpdated.js +10 -0
- package/src/types/MessageReactionUpdated.js +10 -0
- package/src/types/OrderInfo.js +10 -0
- package/src/types/OwnedGift.js +5 -0
- package/src/types/OwnedGiftRegular.js +10 -0
- package/src/types/OwnedGiftUnique.js +10 -0
- package/src/types/OwnedGifts.js +10 -0
- package/src/types/PaidMedia.js +5 -0
- package/src/types/PaidMediaInfo.js +10 -0
- package/src/types/PaidMediaPhoto.js +10 -0
- package/src/types/PaidMediaPreview.js +10 -0
- package/src/types/PaidMediaPurchased.js +10 -0
- package/src/types/PaidMediaVideo.js +10 -0
- package/src/types/PaidMessagePriceChanged.js +10 -0
- package/src/types/PassportData.js +10 -0
- package/src/types/PassportElementError.js +5 -0
- package/src/types/PassportElementErrorDataField.js +10 -0
- package/src/types/PassportElementErrorFile.js +10 -0
- package/src/types/PassportElementErrorFiles.js +10 -0
- package/src/types/PassportElementErrorFrontSide.js +10 -0
- package/src/types/PassportElementErrorReverseSide.js +10 -0
- package/src/types/PassportElementErrorSelfie.js +10 -0
- package/src/types/PassportElementErrorTranslationFile.js +10 -0
- package/src/types/PassportElementErrorTranslationFiles.js +10 -0
- package/src/types/PassportElementErrorUnspecified.js +10 -0
- package/src/types/PassportFile.js +10 -0
- package/src/types/PhotoSize.js +10 -0
- package/src/types/Poll.js +10 -0
- package/src/types/PollAnswer.js +10 -0
- package/src/types/PollOption.js +10 -0
- package/src/types/PreCheckoutQuery.js +10 -0
- package/src/types/PreparedInlineMessage.js +10 -0
- package/src/types/ProximityAlertTriggered.js +10 -0
- package/src/types/ReactionCount.js +10 -0
- package/src/types/ReactionType.js +5 -0
- package/src/types/ReactionTypeCustomEmoji.js +10 -0
- package/src/types/ReactionTypeEmoji.js +10 -0
- package/src/types/ReactionTypePaid.js +10 -0
- package/src/types/RefundedPayment.js +10 -0
- package/src/types/ReplyKeyboardMarkup.js +10 -0
- package/src/types/ReplyKeyboardRemove.js +10 -0
- package/src/types/ReplyParameters.js +10 -0
- package/src/types/ResponseParameters.js +10 -0
- package/src/types/RevenueWithdrawalState.js +5 -0
- package/src/types/RevenueWithdrawalStateFailed.js +10 -0
- package/src/types/RevenueWithdrawalStatePending.js +10 -0
- package/src/types/RevenueWithdrawalStateSucceeded.js +10 -0
- package/src/types/SentWebAppMessage.js +10 -0
- package/src/types/SharedUser.js +10 -0
- package/src/types/ShippingAddress.js +10 -0
- package/src/types/ShippingOption.js +10 -0
- package/src/types/ShippingQuery.js +10 -0
- package/src/types/StarAmount.js +10 -0
- package/src/types/StarTransaction.js +10 -0
- package/src/types/StarTransactions.js +10 -0
- package/src/types/Sticker.js +10 -0
- package/src/types/StickerSet.js +10 -0
- package/src/types/Story.js +10 -0
- package/src/types/StoryArea.js +10 -0
- package/src/types/StoryAreaPosition.js +10 -0
- package/src/types/StoryAreaType.js +5 -0
- package/src/types/StoryAreaTypeLink.js +10 -0
- package/src/types/StoryAreaTypeLocation.js +10 -0
- package/src/types/StoryAreaTypeSuggestedReaction.js +10 -0
- package/src/types/StoryAreaTypeUniqueGift.js +10 -0
- package/src/types/StoryAreaTypeWeather.js +10 -0
- package/src/types/SuccessfulPayment.js +10 -0
- package/src/types/SuggestedPostApprovalFailed.js +10 -0
- package/src/types/SuggestedPostApproved.js +10 -0
- package/src/types/SuggestedPostDeclined.js +10 -0
- package/src/types/SuggestedPostInfo.js +10 -0
- package/src/types/SuggestedPostPaid.js +10 -0
- package/src/types/SuggestedPostParameters.js +10 -0
- package/src/types/SuggestedPostPrice.js +10 -0
- package/src/types/SuggestedPostRefunded.js +10 -0
- package/src/types/SwitchInlineQueryChosenChat.js +10 -0
- package/src/types/TextQuote.js +10 -0
- package/src/types/TransactionPartner.js +5 -0
- package/src/types/TransactionPartnerAffiliateProgram.js +10 -0
- package/src/types/TransactionPartnerChat.js +10 -0
- package/src/types/TransactionPartnerFragment.js +10 -0
- package/src/types/TransactionPartnerOther.js +10 -0
- package/src/types/TransactionPartnerTelegramAds.js +10 -0
- package/src/types/TransactionPartnerTelegramApi.js +10 -0
- package/src/types/TransactionPartnerUser.js +10 -0
- package/src/types/UniqueGift.js +10 -0
- package/src/types/UniqueGiftBackdrop.js +10 -0
- package/src/types/UniqueGiftBackdropColors.js +10 -0
- package/src/types/UniqueGiftColors.js +10 -0
- package/src/types/UniqueGiftInfo.js +10 -0
- package/src/types/UniqueGiftModel.js +10 -0
- package/src/types/UniqueGiftSymbol.js +10 -0
- package/src/types/Update.js +10 -0
- package/src/types/User.js +10 -0
- package/src/types/UserChatBoosts.js +10 -0
- package/src/types/UserProfilePhotos.js +10 -0
- package/src/types/UserRating.js +10 -0
- package/src/types/UsersShared.js +10 -0
- package/src/types/Venue.js +10 -0
- package/src/types/Video.js +10 -0
- package/src/types/VideoChatEnded.js +10 -0
- package/src/types/VideoChatParticipantsInvited.js +10 -0
- package/src/types/VideoChatScheduled.js +10 -0
- package/src/types/VideoChatStarted.js +5 -0
- package/src/types/VideoNote.js +10 -0
- package/src/types/Voice.js +10 -0
- package/src/types/WebAppData.js +10 -0
- package/src/types/WebAppInfo.js +10 -0
- package/src/types/WebhookInfo.js +10 -0
- package/src/types/WriteAccessAllowed.js +10 -0
- package/types/index.d.ts +1133 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export class TelegramObject {
|
|
2
|
+
/**
|
|
3
|
+
* Конструктор с поддержкой маппинга полей (from -> from_user, type -> type_val и т.д.)
|
|
4
|
+
*/
|
|
5
|
+
constructor(data = {}) {
|
|
6
|
+
if (data && typeof data === 'object') {
|
|
7
|
+
for (const [key, value] of Object.entries(data)) {
|
|
8
|
+
// Применяем тот же маппинг что и в fromJSON
|
|
9
|
+
let field = key;
|
|
10
|
+
if (key === 'from') {
|
|
11
|
+
field = 'from_user';
|
|
12
|
+
} else if (key === 'type') {
|
|
13
|
+
field = 'type_val';
|
|
14
|
+
} else if (key === 'filter') {
|
|
15
|
+
field = 'filter_val';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this[field] = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Сериализация в JSON с учётом правил:
|
|
25
|
+
* - from_user -> from
|
|
26
|
+
* - type_val -> type
|
|
27
|
+
* - filter_val -> filter
|
|
28
|
+
*/
|
|
29
|
+
toJSON() {
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [key, value] of Object.entries(this)) {
|
|
32
|
+
if (value === null || value === undefined) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let outKey = key;
|
|
37
|
+
if (key === 'from_user') {
|
|
38
|
+
outKey = 'from';
|
|
39
|
+
} else if (key === 'type_val') {
|
|
40
|
+
outKey = 'type';
|
|
41
|
+
} else if (key === 'filter_val') {
|
|
42
|
+
outKey = 'filter';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
result[outKey] = this.#clean(value);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#clean(val) {
|
|
51
|
+
if (val === null || val === undefined) {
|
|
52
|
+
return val;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(val)) {
|
|
56
|
+
return val.map(v => this.#clean(v));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (val instanceof TelegramObject) {
|
|
60
|
+
return val.toJSON();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (typeof val === 'object') {
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const [k, v] of Object.entries(val)) {
|
|
66
|
+
if (v === null || v === undefined) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
out[k] = this.#clean(v);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return val;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Базовый fromJSON — просто маппит поля с учётом from/type/filter.
|
|
79
|
+
* Конкретные классы могут переопределить, если нужно создавать вложенные объекты.
|
|
80
|
+
*/
|
|
81
|
+
static fromJSON(data) {
|
|
82
|
+
const obj = new this();
|
|
83
|
+
if (!data || typeof data !== 'object') {
|
|
84
|
+
return obj;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for (const [key, value] of Object.entries(data)) {
|
|
88
|
+
let field = key;
|
|
89
|
+
if (key === 'from') {
|
|
90
|
+
field = 'from_user';
|
|
91
|
+
} else if (key === 'type') {
|
|
92
|
+
field = 'type_val';
|
|
93
|
+
} else if (key === 'filter') {
|
|
94
|
+
field = 'filter_val';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (field in obj) {
|
|
98
|
+
obj[field] = value;
|
|
99
|
+
} else {
|
|
100
|
+
// позволяем динамически добавлять поля, чтобы сохранить максимум данных
|
|
101
|
+
obj[field] = value;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return obj;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
export class ChatGPT {
|
|
4
|
+
constructor(url, headers = {}) {
|
|
5
|
+
this.url = url ? url.replace(/\/$/, '') : '';
|
|
6
|
+
this.headers = headers;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async _makeRequest(method, endpoint, data = null, files = null) {
|
|
10
|
+
try {
|
|
11
|
+
const url = `${this.url}/${endpoint.replace(/^\//, '')}`;
|
|
12
|
+
let response;
|
|
13
|
+
if (files) {
|
|
14
|
+
const FormData = (await import('form-data')).default;
|
|
15
|
+
const form = new FormData();
|
|
16
|
+
for (const [k, v] of Object.entries(data || {})) {
|
|
17
|
+
form.append(k, v);
|
|
18
|
+
}
|
|
19
|
+
for (const [k, v] of Object.entries(files)) {
|
|
20
|
+
form.append(k, v);
|
|
21
|
+
}
|
|
22
|
+
response = await axios.request({
|
|
23
|
+
method,
|
|
24
|
+
url,
|
|
25
|
+
headers: { ...this.headers, ...form.getHeaders() },
|
|
26
|
+
data: form,
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
response = await axios.request({
|
|
30
|
+
method,
|
|
31
|
+
url,
|
|
32
|
+
headers: {
|
|
33
|
+
...this.headers,
|
|
34
|
+
'Content-Type': 'application/json',
|
|
35
|
+
},
|
|
36
|
+
data: data ? JSON.stringify(data) : undefined,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return response.data;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error(`ChatGPT(${endpoint}):`, e.message);
|
|
42
|
+
throw new Error(`ChatGPT API error: ${e.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async generateChatCompletion(model, messages, temperature = null, max_tokens = null, stream = false, ...kwargs) {
|
|
47
|
+
const data = { model, messages, temperature, max_tokens, stream, ...kwargs };
|
|
48
|
+
return await this._makeRequest('POST', 'chat/completions', data);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async generateImage(prompt, n = 1, size = '1024x1024', response_format = 'url', ...kwargs) {
|
|
52
|
+
const data = { prompt, n, size, response_format, ...kwargs };
|
|
53
|
+
return await this._makeRequest('POST', 'images/generations', data);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async generateEmbedding(model, input_i, user = null, ...kwargs) {
|
|
57
|
+
const data = { model, input: input_i, user, ...kwargs };
|
|
58
|
+
return await this._makeRequest('POST', 'embeddings', data);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async generateTranscription(file, model, language = null, prompt = null, response_format = 'json', temperature = 0, ...kwargs) {
|
|
62
|
+
const data = { model, language, prompt, response_format, temperature, ...kwargs };
|
|
63
|
+
const files = { file };
|
|
64
|
+
return await this._makeRequest('POST', 'audio/transcriptions', data, files);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async generateTranslation(file, model, prompt = null, response_format = 'json', temperature = 0, ...kwargs) {
|
|
68
|
+
const data = { model, prompt, response_format, temperature, ...kwargs };
|
|
69
|
+
const files = { file };
|
|
70
|
+
return await this._makeRequest('POST', 'audio/translations', data, files);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getModels() {
|
|
74
|
+
return await this._makeRequest('GET', 'models');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
package/src/ai/Deef.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import * as cheerio from 'cheerio';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
export class Deef {
|
|
6
|
+
async translate(text = null, lang = 'en') {
|
|
7
|
+
try {
|
|
8
|
+
if (!text) {
|
|
9
|
+
throw new Error('Text parameter is required');
|
|
10
|
+
}
|
|
11
|
+
const url = `https://translate.google.com/m?tl=${encodeURIComponent(lang)}&sl=auto&q=${encodeURIComponent(text)}`;
|
|
12
|
+
const { data } = await axios.get(url, {
|
|
13
|
+
timeout: 10000,
|
|
14
|
+
headers: {
|
|
15
|
+
'User-Agent': 'Mozilla/5.0 (compatible; Deef/1.0)',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const $ = cheerio.load(data);
|
|
19
|
+
const div = $('div.result-container').first();
|
|
20
|
+
return div.text() || text;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.error('Deef translate error:', e.message);
|
|
23
|
+
throw new Error(`Translation failed: ${e.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async shortUrl(longUrl = null) {
|
|
28
|
+
try {
|
|
29
|
+
if (!longUrl) {
|
|
30
|
+
throw new Error('URL parameter is required');
|
|
31
|
+
}
|
|
32
|
+
const { data } = await axios.get(`https://clck.ru/--?url=${encodeURIComponent(longUrl)}`, {
|
|
33
|
+
timeout: 5000,
|
|
34
|
+
headers: {
|
|
35
|
+
'User-Agent': 'Mozilla/5.0 (compatible; Deef/1.0)',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return (data || '').toString().trim();
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error('Deef shortUrl error:', e.message);
|
|
41
|
+
throw new Error(`URL shortening failed: ${e.message}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
runInBg(func, ...args) {
|
|
46
|
+
(async() => {
|
|
47
|
+
try {
|
|
48
|
+
await func(...args);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.log(`Error[${func}]:`, e.message);
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async encodeBase64(path = null) {
|
|
56
|
+
try {
|
|
57
|
+
if (!path) {
|
|
58
|
+
throw new Error('Path parameter is required');
|
|
59
|
+
}
|
|
60
|
+
const buf = await fs.promises.readFile(path);
|
|
61
|
+
return buf.toString('base64');
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error('Deef encodeBase64 error:', e.message);
|
|
64
|
+
throw new Error(`File encoding failed: ${e.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async genAiResponse(model = 'Qwen3 235B', messages = null) {
|
|
69
|
+
try {
|
|
70
|
+
if (!messages) {
|
|
71
|
+
throw new Error('Messages parameter is required');
|
|
72
|
+
}
|
|
73
|
+
const modelToCluster = { 'Qwen3 235B': 'hybrid', 'GPT OSS 120B': 'nvidia' };
|
|
74
|
+
const clusterMode = modelToCluster[model];
|
|
75
|
+
if (!clusterMode) {
|
|
76
|
+
throw new Error(`Unknown model: ${model}. Available models: ${Object.keys(modelToCluster).join(', ')}`);
|
|
77
|
+
}
|
|
78
|
+
const payload = {
|
|
79
|
+
model,
|
|
80
|
+
clusterMode,
|
|
81
|
+
messages,
|
|
82
|
+
enableThinking: true,
|
|
83
|
+
};
|
|
84
|
+
const response = await axios.post('https://chat.gradient.network/api/generate', payload, {
|
|
85
|
+
responseType: 'stream',
|
|
86
|
+
timeout: 30000,
|
|
87
|
+
headers: {
|
|
88
|
+
'User-Agent': 'Mozilla/5.0 (compatible; Deef/1.0)',
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const result = { reasoning: '', answer: '', status: 'unknown', cluster_info: null };
|
|
93
|
+
|
|
94
|
+
// Handle streaming response properly
|
|
95
|
+
if (response.data && typeof response.data.pipe === 'function') {
|
|
96
|
+
// It's a stream
|
|
97
|
+
const chunks = [];
|
|
98
|
+
for await (const chunk of response.data) {
|
|
99
|
+
chunks.push(chunk);
|
|
100
|
+
}
|
|
101
|
+
const fullData = Buffer.concat(chunks).toString('utf8');
|
|
102
|
+
const lines = fullData.split('\n').filter(Boolean);
|
|
103
|
+
|
|
104
|
+
for (const line of lines) {
|
|
105
|
+
try {
|
|
106
|
+
const jsonObj = JSON.parse(line);
|
|
107
|
+
const type = jsonObj.type;
|
|
108
|
+
if (type === 'reply') {
|
|
109
|
+
const dc = jsonObj.data || {};
|
|
110
|
+
if (dc.reasoningContent) {
|
|
111
|
+
result.reasoning += dc.reasoningContent;
|
|
112
|
+
}
|
|
113
|
+
if (dc.content) {
|
|
114
|
+
result.answer += dc.content;
|
|
115
|
+
}
|
|
116
|
+
} else if (type === 'jobInfo') {
|
|
117
|
+
const status = jsonObj.data?.status;
|
|
118
|
+
result.status = status;
|
|
119
|
+
if (status === 'completed') {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
} else if (type === 'clusterInfo') {
|
|
123
|
+
result.cluster_info = jsonObj.data || null;
|
|
124
|
+
}
|
|
125
|
+
} catch (_parseError) {
|
|
126
|
+
// Skip invalid JSON lines
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
// Handle non-streaming response
|
|
132
|
+
throw new Error('Expected streaming response');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return result;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
console.error('Deef(genAiResponse):', e.message);
|
|
138
|
+
throw new Error(`AI response generation failed: ${e.message}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async genGpt(messages = null) {
|
|
143
|
+
try {
|
|
144
|
+
if (!messages) {
|
|
145
|
+
throw new Error('Messages parameter is required');
|
|
146
|
+
}
|
|
147
|
+
const { data, status } = await axios.post(
|
|
148
|
+
'https://italygpt.it/api/chat',
|
|
149
|
+
{ messages, stream: true },
|
|
150
|
+
{
|
|
151
|
+
timeout: 30000,
|
|
152
|
+
headers: {
|
|
153
|
+
'User-Agent':
|
|
154
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
|
|
155
|
+
'Accept': 'text/event-stream',
|
|
156
|
+
'Content-Type': 'application/json',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
if (status === 200) {
|
|
161
|
+
return data.toString();
|
|
162
|
+
}
|
|
163
|
+
throw new Error(`API returned status ${status}`);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
console.error('Deef(genGpt):', e.message);
|
|
166
|
+
throw new Error(`GPT generation failed: ${e.message}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
package/src/ai/OnlySQ.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
export class OnlySQ {
|
|
5
|
+
async getModels({
|
|
6
|
+
modality = null,
|
|
7
|
+
can_tools = null,
|
|
8
|
+
can_stream = null,
|
|
9
|
+
status = null,
|
|
10
|
+
max_cost = null,
|
|
11
|
+
return_names = false,
|
|
12
|
+
} = {}) {
|
|
13
|
+
try {
|
|
14
|
+
const { data } = await axios.get('https://api.onlysq.ru/ai/models', {
|
|
15
|
+
timeout: 10000,
|
|
16
|
+
headers: {
|
|
17
|
+
'User-Agent': 'Mozilla/5.0 (compatible; OnlySQ/1.0)',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const models = data?.models || {};
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const [key, model] of Object.entries(models)) {
|
|
23
|
+
let ok = true;
|
|
24
|
+
if (modality !== null) {
|
|
25
|
+
const mods = Array.isArray(modality) ? modality : [modality];
|
|
26
|
+
if (!mods.includes(model.modality)) {
|
|
27
|
+
ok = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (ok && can_tools !== null) {
|
|
31
|
+
const val = model['can-tools'] ?? false;
|
|
32
|
+
if (val !== can_tools) {
|
|
33
|
+
ok = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (ok && can_stream !== null) {
|
|
37
|
+
const val = model['can-stream'] ?? false;
|
|
38
|
+
if (val !== can_stream) {
|
|
39
|
+
ok = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (ok && status !== null) {
|
|
43
|
+
if ((model.status ?? '') !== status) {
|
|
44
|
+
ok = false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (ok && max_cost !== null) {
|
|
48
|
+
const cost = parseFloat(model.cost ?? Number.POSITIVE_INFINITY);
|
|
49
|
+
if (cost > max_cost) {
|
|
50
|
+
ok = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (ok) {
|
|
54
|
+
out.push(return_names ? model.name : key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error('OnlySQ(getModels):', e.message);
|
|
60
|
+
throw new Error(`Failed to get models: ${e.message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async generateAnswer(model = 'gpt-5.2-chat', messages = null) {
|
|
65
|
+
try {
|
|
66
|
+
if (!messages) {
|
|
67
|
+
throw new Error('Messages parameter is required');
|
|
68
|
+
}
|
|
69
|
+
const payload = { model, request: { messages } };
|
|
70
|
+
const { data } = await axios.post('https://api.onlysq.ru/ai/v2', payload, {
|
|
71
|
+
timeout: 30000,
|
|
72
|
+
headers: {
|
|
73
|
+
'Authorization': 'Bearer openai',
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
'User-Agent': 'Mozilla/5.0 (compatible; OnlySQ/1.0)',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (!data?.choices?.[0]?.message?.content) {
|
|
80
|
+
throw new Error('Invalid API response format');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return data.choices[0].message.content;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error('OnlySQ(generateAnswer):', e.message);
|
|
86
|
+
throw new Error(`Answer generation failed: ${e.message}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async generateImage(model = 'flux', prompt = null, ratio = '16:9', filename = 'image.png') {
|
|
91
|
+
try {
|
|
92
|
+
if (!prompt) {
|
|
93
|
+
throw new Error('Prompt parameter is required');
|
|
94
|
+
}
|
|
95
|
+
if (!filename) {
|
|
96
|
+
throw new Error('Filename parameter is required');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const payload = { model, prompt, ratio };
|
|
100
|
+
const { data, status } = await axios.post(
|
|
101
|
+
'https://api.onlysq.ru/ai/imagen',
|
|
102
|
+
payload,
|
|
103
|
+
{
|
|
104
|
+
timeout: 60000, // Image generation can take longer
|
|
105
|
+
headers: {
|
|
106
|
+
'Authorization': 'Bearer openai',
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
'User-Agent': 'Mozilla/5.0 (compatible; OnlySQ/1.0)',
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (status === 200 && data?.files?.[0]) {
|
|
114
|
+
const buf = Buffer.from(data.files[0], 'base64');
|
|
115
|
+
await fs.promises.writeFile(filename, buf);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
throw new Error('Invalid API response or no image generated');
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.error('OnlySQ(generateImage):', e.message);
|
|
122
|
+
throw new Error(`Image generation failed: ${e.message}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|