@codebam/cf-workers-telegram-bot 5.16.0 → 5.17.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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { preTagString, prettyJSON, addSearchParams, responseToJSON, } from "./libs";
|
|
2
2
|
import TelegramApi from "./telegram_api";
|
|
3
3
|
import { TelegramInlineQueryResultArticle, TelegramInlineQueryResultPhoto, } from "./types";
|
|
4
|
-
import { Ai } from "@cloudflare/ai";
|
|
5
4
|
export default class TelegramBot extends TelegramApi {
|
|
6
5
|
url;
|
|
7
6
|
kv;
|
|
@@ -28,7 +27,6 @@ export default class TelegramBot extends TelegramApi {
|
|
|
28
27
|
if (this.ai === undefined) {
|
|
29
28
|
return new Response("ok");
|
|
30
29
|
}
|
|
31
|
-
const ai = new Ai(this.ai);
|
|
32
30
|
let _prompt;
|
|
33
31
|
if (args[0][0] === "/") {
|
|
34
32
|
_prompt = args.slice(1).join(" ");
|
|
@@ -41,7 +39,7 @@ export default class TelegramBot extends TelegramApi {
|
|
|
41
39
|
}
|
|
42
40
|
const langs = ["french", "arabic", "german", "spanish", "russian"];
|
|
43
41
|
const inline_articles = await Promise.all(langs.map(async (lang) => {
|
|
44
|
-
const response = await ai.run("@cf/meta/m2m100-1.2b", {
|
|
42
|
+
const response = await this.ai.run("@cf/meta/m2m100-1.2b", {
|
|
45
43
|
text: _prompt,
|
|
46
44
|
source_lang: lang,
|
|
47
45
|
target_lang: "english",
|
|
@@ -71,7 +69,6 @@ export default class TelegramBot extends TelegramApi {
|
|
|
71
69
|
};
|
|
72
70
|
// bot command: /image
|
|
73
71
|
image = async (update, args) => {
|
|
74
|
-
const ai = new Ai(this.ai);
|
|
75
72
|
let _prompt;
|
|
76
73
|
if (args[0][0] === "/") {
|
|
77
74
|
_prompt = args.slice(1).join(" ");
|
|
@@ -84,7 +81,7 @@ export default class TelegramBot extends TelegramApi {
|
|
|
84
81
|
}
|
|
85
82
|
const inputs = { prompt: _prompt, num_steps: 20 };
|
|
86
83
|
await this.sendMessage(update.message?.chat.id ?? 0, "image is processing. please wait...");
|
|
87
|
-
const response = await ai.run("@cf/stabilityai/stable-diffusion-xl-base-1.0", inputs);
|
|
84
|
+
const response = await this.ai.run("@cf/stabilityai/stable-diffusion-xl-base-1.0", inputs);
|
|
88
85
|
const id = crypto.randomUUID();
|
|
89
86
|
await this.r2.put(id, response);
|
|
90
87
|
const url = "https://r2.seanbehan.ca/" + id;
|
|
@@ -95,7 +92,6 @@ export default class TelegramBot extends TelegramApi {
|
|
|
95
92
|
if (this.ai === undefined) {
|
|
96
93
|
return new Response("ok");
|
|
97
94
|
}
|
|
98
|
-
const ai = new Ai(this.ai);
|
|
99
95
|
let _prompt;
|
|
100
96
|
if (args[0][0] === "/") {
|
|
101
97
|
_prompt = args.slice(1).join(" ");
|
|
@@ -141,8 +137,7 @@ export default class TelegramBot extends TelegramApi {
|
|
|
141
137
|
"</s>";
|
|
142
138
|
const p = system_prompt + "[INST]" + _prompt + "[/INST]";
|
|
143
139
|
const prompt = p.slice(p.length - 4096, p.length);
|
|
144
|
-
const response = await ai
|
|
145
|
-
// @ts-expect-error ModelName doesn't need to be verified at build time
|
|
140
|
+
const response = await this.ai
|
|
146
141
|
.run(this.chat_model, {
|
|
147
142
|
prompt,
|
|
148
143
|
max_tokens: 596,
|
|
@@ -177,7 +172,6 @@ export default class TelegramBot extends TelegramApi {
|
|
|
177
172
|
if (this.ai === undefined) {
|
|
178
173
|
return new Response("ok");
|
|
179
174
|
}
|
|
180
|
-
const ai = new Ai(this.ai);
|
|
181
175
|
let _prompt;
|
|
182
176
|
if (args[0][0] === "/") {
|
|
183
177
|
_prompt = args.slice(1).join(" ");
|
|
@@ -226,8 +220,7 @@ export default class TelegramBot extends TelegramApi {
|
|
|
226
220
|
"</s>";
|
|
227
221
|
const p = system_prompt + "[INST]" + _prompt + "[/INST]";
|
|
228
222
|
const prompt = p.slice(p.length - 4096, p.length);
|
|
229
|
-
const response = await ai
|
|
230
|
-
// @ts-expect-error ModelName doesn't need to be verified at build time
|
|
223
|
+
const response = await this.ai
|
|
231
224
|
.run(this.chat_model, {
|
|
232
225
|
prompt,
|
|
233
226
|
max_tokens: 596,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebam/cf-workers-telegram-bot",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.17.0",
|
|
4
4
|
"description": "serverless telegram bot on cf workers",
|
|
5
5
|
"main": "./dist/main/src/main.js",
|
|
6
6
|
"module": "./dist/main/src/main.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@eslint/js": "^9.1.1",
|
|
34
34
|
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
|
35
35
|
"@typescript-eslint/parser": "^7.8.0",
|
|
36
|
-
"eslint": "^
|
|
36
|
+
"eslint": "^9.1.1",
|
|
37
37
|
"eslint-config-prettier": "^9.1.0",
|
|
38
38
|
"globals": "^15.1.0",
|
|
39
39
|
"lerna": "^8.1.2",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@cloudflare/ai": "1.0.53"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "efc0514c91ebd14c2d564b6917c79073ac07a56f"
|
|
48
48
|
}
|