@codebam/cf-workers-telegram-bot 12.6.15 → 12.6.17
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/dist/ai.js +1 -1
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +41 -7
- package/package.json +1 -1
package/dist/ai.js
CHANGED
|
@@ -79,7 +79,7 @@ input, config) {
|
|
|
79
79
|
return `- Name: ${t.name}\n Description: ${t.description}\n Parameters: ${JSON.stringify(t.parameters)}`;
|
|
80
80
|
})
|
|
81
81
|
.join('\n');
|
|
82
|
-
const promptInstruction = `\n\n[SYSTEM INSTRUCTION] You have access to the following tools:\n${toolInstructions}\n\nTo use a tool, you MUST output a tool call wrapped in XML format, like so:\n<tool_call>{"name": "search", "arguments": {"
|
|
82
|
+
const promptInstruction = `\n\n[SYSTEM INSTRUCTION] You have access to the following tools:\n${toolInstructions}\n\nTo use a tool, you MUST output a tool call wrapped in XML format, like so:\n<tool_call>{"name": "search", "arguments": {"query": "query" }}</tool_call>\nor\n<tool_call>{"name": "fetch", "arguments": {"url": "https://example.com" }}</tool_call>\n\nMake sure the tool call is outputted EXACTLY as shown. The system will intercept this call, execute the tool, and return the output to you. Do not write code or direct the user to run code; call the tools yourself.`;
|
|
83
83
|
systemMsg.content = systemMsg.content + promptInstruction;
|
|
84
84
|
}
|
|
85
85
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -132,7 +132,8 @@ export const searchTool = {
|
|
|
132
132
|
},
|
|
133
133
|
required: ['query'],
|
|
134
134
|
},
|
|
135
|
-
function: async (
|
|
135
|
+
function: async (args) => {
|
|
136
|
+
const query = args.query || args.q || '';
|
|
136
137
|
const instances = [
|
|
137
138
|
'https://searxng.site/',
|
|
138
139
|
'https://priv.au/',
|
|
@@ -164,7 +165,7 @@ export const searchTool = {
|
|
|
164
165
|
// Continue to next fallback
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
|
-
//
|
|
168
|
+
// Fallback to Wikipedia Search if all SearXNG instances fail/are rate-limited
|
|
168
169
|
try {
|
|
169
170
|
const wikiUrl = `https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(query)}&utf8=&format=json`;
|
|
170
171
|
const res = await fetch(wikiUrl, {
|
|
@@ -173,18 +174,51 @@ export const searchTool = {
|
|
|
173
174
|
if (res.status === 200) {
|
|
174
175
|
const data = (await res.json());
|
|
175
176
|
if (data && data.query && Array.isArray(data.query.search)) {
|
|
176
|
-
const
|
|
177
|
+
const wikiResults = data.query.search.map((item) => ({
|
|
177
178
|
title: item.title,
|
|
178
179
|
snippet: item.snippet.replace(/<\/?[^>]+(>|$)/g, ''), // strip HTML tags
|
|
179
180
|
url: `https://en.wikipedia.org/wiki/${encodeURIComponent(item.title)}`,
|
|
180
181
|
}));
|
|
181
|
-
|
|
182
|
+
if (wikiResults.length > 0) {
|
|
183
|
+
return JSON.stringify({ results: wikiResults });
|
|
184
|
+
}
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
|
-
catch
|
|
186
|
-
|
|
188
|
+
catch {
|
|
189
|
+
// Continue to next fallback
|
|
190
|
+
}
|
|
191
|
+
// Final fallback to Google News RSS search for recent general web/news results
|
|
192
|
+
try {
|
|
193
|
+
const googleNewsUrl = `https://news.google.com/rss/search?q=${encodeURIComponent(query)}&hl=en-US&gl=US&ceid=US:en`;
|
|
194
|
+
const res = await fetch(googleNewsUrl, {
|
|
195
|
+
headers: { 'User-Agent': userAgent },
|
|
196
|
+
});
|
|
197
|
+
if (res.status === 200) {
|
|
198
|
+
const xml = await res.text();
|
|
199
|
+
const items = [];
|
|
200
|
+
const itemRegex = /<item>([\s\S]*?)<\/item>/g;
|
|
201
|
+
let match;
|
|
202
|
+
while ((match = itemRegex.exec(xml)) !== null && items.length < 5) {
|
|
203
|
+
const content = match[1];
|
|
204
|
+
const titleMatch = /<title>([\s\S]*?)<\/title>/.exec(content);
|
|
205
|
+
const linkMatch = /<link>([\s\S]*?)<\/link>/.exec(content);
|
|
206
|
+
const descMatch = /<description>([\s\S]*?)<\/description>/.exec(content);
|
|
207
|
+
const title = titleMatch ? titleMatch[1].replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1') : '';
|
|
208
|
+
const link = linkMatch ? linkMatch[1] : '';
|
|
209
|
+
const desc = descMatch ? descMatch[1].replace(/<[^>]*>/g, '').replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1') : '';
|
|
210
|
+
if (title && link) {
|
|
211
|
+
items.push({ title, url: link, snippet: desc });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (items.length > 0) {
|
|
215
|
+
return JSON.stringify({ results: items });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
// Continue
|
|
187
221
|
}
|
|
188
|
-
return 'Error executing search: All public search instances and
|
|
222
|
+
return 'Error executing search: All public search instances, Wikipedia fallback, and Google News fallback returned no results.';
|
|
189
223
|
},
|
|
190
224
|
};
|