-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWEBPOST_OPENROUTER_DEMO.js
More file actions
130 lines (106 loc) Β· 4.2 KB
/
Copy pathWEBPOST_OPENROUTER_DEMO.js
File metadata and controls
130 lines (106 loc) Β· 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* DEMO: webpost-openrouter command
*
* This shows the exact output format you'll see in Telegram
*/
// Mock implementation (for demo purposes)
class WebPostOpenRouterDemo {
async run(query) {
const articles = [
{
title: `${query} - Latest Developments`,
description: `Recent updates and innovations in ${query}`,
url: `https://example.com/${query.replace(/\s+/g, '-')}`,
snippet: '2 hours ago',
},
{
title: `Market Analysis: ${query} Trends 2026`,
description: `Deep dive into current trends affecting ${query}`,
url: `https://example.com/analysis`,
snippet: '4 hours ago',
},
{
title: `${query}: What's Next?`,
description: `Expert predictions on future direction`,
url: `https://example.com/predictions`,
snippet: '6 hours ago',
},
];
// Mock post content
const postContent = `π The ${query} space is heating up!
Key insights:
β’ Innovation is accelerating at an unprecedented pace
β’ Early adopters are already seeing significant returns
β’ Infrastructure improvements are removing barriers to entry
The question isn't whether this mattersβit's when you'll jump in.
What's your take? π`;
return {
query,
search: articles,
post: {
content: postContent,
tokensUsed: 215,
model: 'meta-llama/llama-2-70b-chat',
elapsed: 4230,
},
video: {
taskId: 'runway_123abc',
status: 'queued',
},
tokens: {
post: 215,
total: 215,
},
elapsed: 4500,
success: true,
};
}
formatForTelegram(result) {
if (!result.success) {
return `β Error: ${result.error}`;
}
let text = `π± *WebPost: ${result.query}*\n\n`;
// Post content
text += `βοΈ *Post:*\n${result.post.content}\n\n`;
// Sources
text += `π *Sources:*\n`;
result.search.slice(0, 2).forEach((article, i) => {
text += `${i + 1}. [${article.title}](${article.url})\n`;
});
// Token info
text += `\nπ *Token Usage:*\n`;
text += `OpenRouter: ${result.post.tokensUsed} tokens\n`;
text += `β±οΈ Generated in ${(result.elapsed / 1000).toFixed(1)}s\n`;
if (result.video) {
text += `\n㪠Video: Generating (ID: ${result.video.taskId})\n`;
}
return text;
}
}
// ============================================
// DEMO: Run examples
// ============================================
const demo = new WebPostOpenRouterDemo();
(async () => {
console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n');
// Example 1: Tech news
console.log('π± EXAMPLE 1: Tech News\n');
console.log('Command: /webpost Chile tech startups\n');
const result1 = await demo.run('Chile tech startups');
const formatted1 = demo.formatForTelegram(result1);
console.log(formatted1);
console.log('\nβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n');
// Example 2: Market analysis
console.log('π± EXAMPLE 2: Market Analysis\n');
console.log('Command: /webpost AI regulation trends\n');
const result2 = await demo.run('AI regulation trends');
const formatted2 = demo.formatForTelegram(result2);
console.log(formatted2);
console.log('\nβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n');
// Show raw result structure
console.log('π RAW RESULT STRUCTURE\n');
console.log(JSON.stringify(result1, null, 2));
console.log('\nβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n');
console.log('β
Demo complete!\n');
console.log('This is exactly what you\'ll see in Telegram when using /webpost\n');
})();