Towniequeries.tsx5 matches
24user_id = ?
25AND timestamp > ?
26AND our_api_token = 1
27`,
28[userId, new Date().getTime() - 24 * 60 * 60 * 1000],
55finish_reason,
56num_images,
57our_api_token,
58}: {
59bearerToken: string;
67finish_reason: string;
68num_images: number;
69our_api_token: boolean;
70}) {
71const price = calculateCost({
91finish_reason,
92num_images,
93our_api_token
94) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
95`,
108finish_reason,
109num_images,
110our_api_token ? 1 : 0,
111],
112);
6const botToken = process.env.TELEGRAM_BOT_TOKEN;
78const response = await fetch(`https://api.telegram.org/bot${botToken}/getWebhookInfo`);
9const result = await response.json();
10return result;
blob_adminmain.tsx6 matches
1415// Public route without authentication
16app.get("/api/public/:id", async (c) => {
17const key = `__public/${c.req.param("id")}`;
18const { blob } = await import("https://esm.town/v/std/blob");
132};
133134app.get("/api/blobs", checkAuth, async (c) => {
135const prefix = c.req.query("prefix") || "";
136const limit = parseInt(c.req.query("limit") || "20", 10);
141});
142143app.get("/api/blob", checkAuth, async (c) => {
144const key = c.req.query("key");
145if (!key) return c.text("Missing key parameter", 400);
149});
150151app.put("/api/blob", checkAuth, async (c) => {
152const key = c.req.query("key");
153if (!key) return c.text("Missing key parameter", 400);
158});
159160app.delete("/api/blob", checkAuth, async (c) => {
161const key = c.req.query("key");
162if (!key) return c.text("Missing key parameter", 400);
166});
167168app.post("/api/blob", checkAuth, async (c) => {
169const { file, key } = await c.req.parseBody();
170if (!file || !key) return c.text("Missing file or key", 400);
blob_adminapp.tsx19 matches
70const menuRef = useRef(null);
71const isPublic = blob.key.startsWith("__public/");
72const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
7374useEffect(() => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
554onClick={() =>
555copyToClipboard(
556`${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
557)}
558className="text-blue-400 hover:text-blue-300 text-sm"
577>
578<img
579src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
580alt="Blob content"
581className="max-w-full h-auto"
untitled-2604new-file-9513.tsx24 matches
1// Creado por Alfonso Boldo
2// Sistema Completo de Prueba de APIs de LLMs para ValTown
3// Fecha: 05 de mayo de 2025
426}
2728// Para solicitudes POST, procesar la llamada a la API
29if (req.method === 'POST') {
30try {
57
58// Extraer parámetros
59const { provider, apiKey, prompt, model, temperature, maxTokens } = body || {};
60
61// Validar parámetros requeridos
62if (!provider || !apiKey || !prompt) {
63return new Response(
64JSON.stringify({
65error: 'Se requieren los parámetros: provider, apiKey y prompt'
66}),
67{ status: 400, headers }
74switch (provider.toLowerCase()) {
75case 'openai':
76result = await callOpenAI(apiKey, prompt, model || 'gpt-4o', temperature || 0.7, maxTokens || 1000);
77break;
78case 'anthropic':
79result = await callClaude(apiKey, prompt, model || 'claude-3-5-sonnet-20240521', temperature || 0.7, maxTokens || 1000);
80break;
81default:
111}
112113// Función para llamar a la API de OpenAI
114async function callOpenAI(apiKey, prompt, model, temperature, maxTokens) {
115const url = 'https://api.openai.com/v1/chat/completions';
116
117console.log(`Llamando a OpenAI con modelo: ${model}`);
122headers: {
123'Content-Type': 'application/json',
124'Authorization': `Bearer ${apiKey}`
125},
126body: JSON.stringify({
170}
171172// Función para llamar a la API de Claude (Anthropic)
173async function callClaude(apiKey, prompt, model, temperature, maxTokens) {
174const url = 'https://api.anthropic.com/v1/messages';
175
176console.log(`Llamando a Claude con modelo: ${model}`);
181headers: {
182'Content-Type': 'application/json',
183'x-api-key': apiKey,
184'anthropic-version': '2023-06-01'
185},
244<meta charset="UTF-8">
245<meta name="viewport" content="width=device-width, initial-scale=1.0">
246<title>Probador de APIs de LLMs</title>
247<style>
248body {
329</head>
330<body>
331<h1>Probador de APIs de LLMs</h1>
332<p>Esta herramienta te permite probar diferentes APIs de modelos de lenguaje como OpenAI (ChatGPT) y Claude (Anthropic).</p>
333
334<div class="container">
342
343<div class="form-group">
344<label for="apiKey">API Key:</label>
345<input type="password" id="apiKey" placeholder="Ingresa tu API key aquÃ">
346</div>
347
465submitBtn.addEventListener('click', async function() {
466const provider = document.getElementById('provider').value;
467const apiKey = document.getElementById('apiKey').value;
468const model = document.getElementById('model').value;
469const temperature = parseFloat(document.getElementById('temperature').value);
472
473// Validar campos
474if (!apiKey || !prompt) {
475alert('Por favor completa todos los campos requeridos.');
476return;
482rawResult.textContent = 'Cargando...';
483
484// Obtener la URL actual para la API
485// Como ahora todo está en un solo endpoint, simplemente usamos la misma URL
486const endpointUrl = window.location.href;
492const requestBody = {
493provider,
494apiKey,
495prompt,
496model,
morningmailmain.tsx1 match
19async function wikitext(): string {
20const randomArticle = await fetch(
21"https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro&explaintext&redirects=1&generator=random&formatversion=2&grnnamespace=0&grnlimit=3",
22);
23const articleJson = await randomArticle.json();
81async function getDiscussionPosts(discussionId: string): Promise<PostT[]> {
82// Used to get the list of post id's for the discussion.
83const discussionRes = await fetch(`${server}/api/discussions/${discussionId}`);
84const discussionResJson = await discussionRes.json();
859394await Promise.all(chunks.map(async (c: string[]) => {
95const postRes = await fetch(`${server}/api/posts?filter[id]=${c.join(",")}`);
96const postJson = await postRes.json();
97
TownieuseAuth.tsx11 matches
34const TOKEN_KEY = "bearer";
5const ANTHROPIC_KEY = "anthropic_api_key";
67export function useAuth() {
8const [token, setToken, removeToken] = useLocalStorage(TOKEN_KEY, "");
9const [anthropicApiKey, setAnthropicApiKey, removeAnthropicApiKey] = useLocalStorage(ANTHROPIC_KEY, "");
10const [error, setError] = useState(null);
1112const isAuthenticated = !!token;
1314const authenticate = async (valTownAPIKey: string, anthropicKey: string) => {
15// replace all this with oauth when it's ready
16try {
17const res = await fetch("/api/user", {
18headers: {
19"Authorization": "Bearer " + valTownAPIKey,
20},
21});
25setError(data.error);
26removeToken();
27removeAnthropicApiKey();
28return;
29}
30setError(null);
31setToken(valTownAPIKey);
32setAnthropicApiKey(anthropicKey);
33} catch (e) {
34console.error(e);
35setError(e.error);
36removeToken();
37removeAnthropicApiKey();
38}
39};
41const logOut = () => {
42removeToken();
43removeAnthropicApiKey();
44};
4550logOut,
51token,
52anthropicApiKey,
53};
54}
helloooooooindex.ts4 matches
87});
8889// API endpoint to get all posts
90app.get('/api/posts', async (c) => {
91const posts = await getAllPosts();
92return c.json(posts);
93});
9495// API endpoint to get a single post
96app.get('/api/posts/:slug', async (c) => {
97const slug = c.req.param('slug');
98const post = await getPost(slug);
helloooooooindex.html2 matches
116posts = window.INITIAL_DATA.posts;
117} else {
118const response = await fetch('/api/posts');
119posts = await response.json();
120}
156
157try {
158const response = await fetch(`/api/posts/${params.slug}`);
159
160if (!response.ok) {