-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlyric.js
More file actions
173 lines (123 loc) · 5.18 KB
/
lyric.js
File metadata and controls
173 lines (123 loc) · 5.18 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { Ai } from './vendor/@cloudflare/ai.js';
import { escapeHtml } from './escape.js';
import template from './template.html';
export default {
// all right here we go, this might be stupid but...
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⢔⣒⠂⣀⣀⣤⣄⣀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⣴⣿⠋⢠⣟⡼⣷⠼⣆⣼⢇⣿⣄⠱⣄
//⠀⠀⠀⠀⠀⠀⠀⠹⣿⡀⣆⠙⠢⠐⠉⠉⣴⣾⣽⢟⡰⠃
//⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣦⠀⠤⢴⣿⠿⢋⣴⡏⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡙⠻⣿⣶⣦⣭⣉⠁⣿⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⠀⠈⠉⠉⠉⠉⠇⡟⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⣘⣦⣀⠀⠀⣀⡴⠊⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠈⠙⠛⠛⢻⣿⣿⣿⣿⠻⣧⡀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠫⣿⠉⠻⣇⠘⠓⠂⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⢶⣾⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣧⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠈⠙⠻⢿⣿⣿⠿⠛⣄⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡁⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣷⠂⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠇⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠋⠀⠀⠀⠀⠀⠀⠀⠀for Mother Medusa, Meteora, Minotaura
async fetch(request, env) {
//
const tasks = [];
const ai = new Ai(env.AI);
// prompt - simple completion style input
let simple = {
prompt: 'Tell me a joke about Cloudflare'
};
let response = await ai.run('@cf/meta/llama-2-7b-chat-int8', simple);
console.log(response)
console.log(`${response}`) // this causes the objObj issue
//return response;
//return Response.json(tasks);
//
const defaultData = { todos: [] };
const setCache = (key, data) => env.EXAMPLE_TODOS.put(key, data);
const getCache = key => env.EXAMPLE_TODOS.get(key);
//const ai = new Ai(env.AI);
async function rinseDream(dream){
//const tasks = [];
console.log(`ai call with %message: ${dream}`);
// prompt - simple completion style input
let simple = {
prompt: `Embellish this dream with some clever emoji: ${dream}`
};
let response = await ai.run('@cf/meta/llama-2-7b-chat-int8', simple);
console.log(`response: ${response}`);
//console.log(JSON.stringify(response));
return response;
//tasks.push({ inputs: simple, response });
// messages - chat style input
/*let chat = {
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Who won the world series in 2020?' }
]
};
response = await ai.run('@cf/meta/llama-2-7b-chat-int8', chat);
tasks.push({ inputs: chat, response });*/
//return Response.json(tasks);
}
async function getTodos(request) {
const ip = request.headers.get('CF-Connecting-IP');
const cacheKey = `data-${ip}`;
let data;
const cache = await getCache(cacheKey);
if (!cache) {
await setCache(cacheKey, JSON.stringify(defaultData));
data = defaultData;
} else {
data = JSON.parse(cache);
}
// Get all keys from Cloudflare KV
//const keys = await getAllKeys();
const body = template.replace(
'$TODOS',
JSON.stringify(
// refactor into standard message format later
data.todos?.map(todo => ({
id: escapeHtml(todo.id),
name: escapeHtml(todo.name),
completed: !!todo.completed
})) ?? []
)
);
return new Response(body, {
headers: { 'Content-Type': 'text/html' }
});
}
async function updateTodos(request) {
const body = await request.text();
// send to dreamLLM
const proc_body = await rinseDream(body);
const ip = request.headers.get('CF-Connecting-IP');
const urlToFetch = 'https://github.com/greydoubt'; // Replace with the desired URL
const webResponse = await fetch(urlToFetch);
const webData = await webResponse.text();
const cacheKey = `data-${ip}`;
try {
JSON.parse(proc_body);
//await setCache(cacheKey, body);
await setCache(cacheKey, proc_body);
return new Response(proc_body, { status: 200 });
} catch (err) {
return new Response(err, { status: 500 });
}
}
if (request.method === 'PUT') {
return updateTodos(request);
}
return getTodos(request);
}
};