untitled-2604new-file-9513.tsx24 matches
1// Creado por Alfonso Boldo
2// Sistema de Prueba de APIs de LLMs para ValTown
3// Fecha: 05 de mayo de 2025
45// Este sistema permite probar distintas APIs de LLMs como ChatGPT (OpenAI) y Claude (Anthropic)
6// Puede implementarse en ValTown como un endpoint HTTP
726
27// Extraer parΓ‘metros
28const { provider, apiKey, prompt, model, temperature, maxTokens } = body;
29
30// Validar parΓ‘metros requeridos
31if (!provider || !apiKey || !prompt) {
32return new Response(
33JSON.stringify({
34error: 'Se requieren los parΓ‘metros: provider, apiKey y prompt'
35}),
36{ status: 400, headers }
43switch (provider.toLowerCase()) {
44case 'openai':
45result = await callOpenAI(apiKey, prompt, model || 'gpt-4o', temperature || 0.7, maxTokens || 1000);
46break;
47case 'anthropic':
48result = await callClaude(apiKey, prompt, model || 'claude-3-5-sonnet-20240521', temperature || 0.7, maxTokens || 1000);
49break;
50default:
73}
7475// FunciΓ³n para llamar a la API de OpenAI
76async function callOpenAI(apiKey, prompt, model, temperature, maxTokens) {
77const url = 'https://api.openai.com/v1/chat/completions';
78
79const response = await fetch(url, {
81headers: {
82'Content-Type': 'application/json',
83'Authorization': `Bearer ${apiKey}`
84},
85body: JSON.stringify({
108}
109110// FunciΓ³n para llamar a la API de Claude (Anthropic)
111async function callClaude(apiKey, prompt, model, temperature, maxTokens) {
112const url = 'https://api.anthropic.com/v1/messages';
113
114const response = await fetch(url, {
116headers: {
117'Content-Type': 'application/json',
118'x-api-key': apiKey,
119'anthropic-version': '2023-06-01'
120},
153<meta charset="UTF-8">
154<meta name="viewport" content="width=device-width, initial-scale=1.0">
155<title>Probador de APIs de LLMs</title>
156<style>
157body {
232</head>
233<body>
234<h1>Probador de APIs de LLMs</h1>
235<p>Esta herramienta te permite probar diferentes APIs de modelos de lenguaje como OpenAI (ChatGPT) y Claude (Anthropic).</p>
236
237<div class="container">
245
246<div class="form-group">
247<label for="apiKey">API Key:</label>
248<input type="password" id="apiKey" placeholder="Ingresa tu API key aquΓ">
249</div>
250
353submitBtn.addEventListener('click', async () => {
354const provider = document.getElementById('provider').value;
355const apiKey = document.getElementById('apiKey').value;
356const model = document.getElementById('model').value;
357const temperature = parseFloat(document.getElementById('temperature').value);
360
361// Validar campos
362if (!apiKey || !prompt) {
363alert('Por favor completa todos los campos requeridos.');
364return;
371
372// URL del endpoint (reemplaza con la URL real de tu Val en ValTown)
373const endpointUrl = 'https://api.val.town/v1/run/tu-usuario/llm-api-tester';
374
375// Enviar solicitud
381body: JSON.stringify({
382provider,
383apiKey,
384prompt,
385model,
morningmailmain.tsx1 match
11async function wikitext(): string {
12const randomArticle = await fetch(
13"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",
14);
15const 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
slack-prgithub-pr-inherit-labels.ts9 matches
198}
199
200const url = `https://api.github.com/repos/${repo}/issues/${issueNumber}`;
201console.log("π Fetching issue from:", url);
202
209});
210
211console.log("π GitHub API response status:", response.status);
212
213if (!response.ok) {
215try {
216const error = await response.json();
217console.error("β GitHub API error:", JSON.stringify(error));
218errorMessage = error.message || errorMessage;
219} catch (e) {
220const errorText = await response.text();
221console.error("β GitHub API error text:", errorText);
222}
223throw new Error(`Failed to fetch issue: ${errorMessage}`);
237
238try {
239const url = `https://api.github.com/repos/${repo}/issues/${prNumber}/labels`;
240console.log("π Sending labels update request to:", url);
241
253});
254
255console.log("π GitHub API response status:", response.status);
256
257if (response.ok) {
264try {
265const error = await response.json();
266console.error("β GitHub API error:", JSON.stringify(error));
267errorMessage = error.message || errorMessage;
268} catch (e) {
269const errorText = await response.text();
270console.error("β GitHub API error text:", errorText);
271}
272return { success: false, message: errorMessage };
273}
274} catch (error) {
275console.error("β Exception during API call:", error);
276return { success: false, message: error.message };
277}
38391. **Create a Slack App**:
40- Go to [Slack API Apps](https://api.slack.com/apps) β Create New App β From scratch
41- Name your app and select your workspace
42- Click "Create App"
774. If the merge button is clicked, the Val:
78- Receives the interaction from Slack
79- Uses the GitHub API to merge the PR
80- Sends a confirmation message back to Slack
81122- **Webhook not triggering**: Check the webhook delivery logs in GitHub repository settings
123- **Labels not copying**: Ensure the issue numbers are properly referenced in the PR description
124- **403 errors with GitHub API**: Your token doesn't have sufficient permissions. For most operations, you need:
125- Classic tokens: "repo" scope
126- Fine-grained tokens: "Read and Write" access to relevant resources (PRs, Issues, etc.)
slack-prgithub-pr-auto-assign.ts5 matches
155
156try {
157const url = `https://api.github.com/repos/${repo}/issues/${prNumber}/assignees`;
158console.log("π Sending assignee request to:", url);
159
171});
172
173console.log("π GitHub API response status:", response.status);
174
175if (response.ok) {
181try {
182const error = await response.json();
183console.error("β GitHub API error:", JSON.stringify(error));
184errorMessage = error.message || errorMessage;
185
194} catch (e) {
195const errorText = await response.text();
196console.error("β GitHub API error text:", errorText);
197}
198return { success: false, message: errorMessage };
199}
200} catch (error) {
201console.error("β Exception during API call:", error);
202return { success: false, message: error.message };
203}
slack-prgithub-pr-title-prefix.ts5 matches
162
163try {
164const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
165console.log("π Sending title update request to:", url);
166
178});
179
180console.log("π GitHub API response status:", response.status);
181
182if (response.ok) {
188try {
189const error = await response.json();
190console.error("β GitHub API error:", JSON.stringify(error));
191errorMessage = error.message || errorMessage;
192} catch (e) {
193const errorText = await response.text();
194console.error("β GitHub API error text:", errorText);
195}
196return { success: false, message: errorMessage };
197}
198} catch (error) {
199console.error("β Exception during API call:", error);
200return { success: false, message: error.message };
201}
slack-prgithub-slack-pr-approvals.ts16 matches
34};
3536// Types for Slack API
37type SlackMessage = {
38blocks: any[];
372
373// Get PR details
374const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
375console.log("π Fetching from GitHub API URL:", url);
376
377let response;
384}
385});
386console.log("π GitHub API response received");
387console.log("π Response status:", response.status);
388console.log("π Response status text:", response.statusText);
395
396if (!response.ok) {
397console.error(`β GitHub API error: ${response.status} ${response.statusText}`);
398
399let errorText;
400try {
401errorText = await response.text();
402console.error("β GitHub API error response:", errorText);
403
404try {
405// Try to parse as JSON for more details
406const errorJson = JSON.parse(errorText);
407console.error("β GitHub API error details:", JSON.stringify(errorJson));
408} catch (e) {
409// Not JSON, that's fine
419try {
420data = await response.json();
421console.log("π Successfully parsed GitHub API response");
422} catch (jsonError) {
423console.error("β Failed to parse GitHub API response:", jsonError);
424
425try {
430}
431
432throw new Error(`Failed to parse GitHub API response: ${jsonError.message}`);
433}
434
446}
447448// Merge a PR via GitHub API
449async function mergePR(repo: string, prNumber: number) {
450console.log(`π Starting mergePR for PR #${prNumber} in ${repo}`);
494
495// Proceed with merge
496const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}/merge`;
497console.log("π Sending merge request to:", url);
498
514body: mergeBody
515});
516console.log("π Merge API response received");
517console.log("π Response status:", response.status);
518console.log("π Response status text:", response.statusText);
683body: JSON.stringify(message)
684});
685console.log("π Slack API response received");
686console.log("π Response status:", response.status);
687console.log("π Response status text:", response.statusText);
694
695if (!response.ok) {
696console.error(`β Slack API error: ${response.status} ${response.statusText}`);
697
698let errorText;
699try {
700errorText = await response.text();
701console.error("β Slack API error response:", errorText);
702} catch (e) {
703console.error("β Could not read error response:", e);
Towniesend-message.ts3 matches
19}
2021const { messages, project, branchId, anthropicApiKey, selectedFiles, images } = await c.req.json();
22console.log("Original messages:", JSON.stringify(messages, null, 2));
23console.log("Images received:", JSON.stringify(images, null, 2));
2425// Still allow users to pass their own key, or use ours
26const apiKey = anthropicApiKey || Deno.env.get("ANTHROPIC_API_KEY");
27const anthropic = createAnthropic({
28apiKey,
29});
30
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}