groqAudioChatchat.ts9 matches
12console.log(`🔵 Last user message: "${messages.find(m => m.role === 'user')?.content?.substring(0, 50)}..."`);
13
14const GROQ_API_KEY = Deno.env.get("GROQ_API_KEY");
15if (!GROQ_API_KEY) {
16console.error("❌ Missing GROQ_API_KEY environment variable");
17return c.json({ error: "GROQ_API_KEY environment variable is not set" }, 500);
18}
1920console.log("🔵 Sending request to Groq API");
21const start = Date.now();
22const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
23method: "POST",
24headers: {
25"Content-Type": "application/json",
26"Authorization": `Bearer ${GROQ_API_KEY}`
27},
28body: JSON.stringify({
33});
34const elapsed = Date.now() - start;
35console.log(`🔵 Groq API response received in ${elapsed}ms, status: ${response.status}`);
3637if (!response.ok) {
38const errorData = await response.json();
39console.error("❌ Chat API error:", errorData);
40return c.json({ error: "Failed to get chat completion", details: errorData }, response.status);
41}
groqAudioChataudio.ts16 matches
1import { Context } from "https://deno.land/x/hono@v3.11.7/mod.ts";
23// Function to handle audio transcription using Groq's Whisper API
4export const audioTranscriptionHandler = async (c: Context) => {
5console.log("🎤 Audio transcription request received");
15}
1617// Get API key from environment variable
18const apiKey = Deno.env.get("GROQ_API_KEY");
19if (!apiKey) {
20console.error("❌ Transcription error: Missing API key");
21return c.json({ error: "API key not configured" }, 500);
22}
2333
34// If the file doesn't have a proper name or type, add one
35// This ensures the file has the right extension for the API
36if (!audioFile.name || !audioFile.type.startsWith('audio/')) {
37const newFile = new File(
45}
4647// Prepare the form data for Groq API
48const groqFormData = new FormData();
49
60groqFormData.append("timestamp_granularities[]", "word");
6162// Call Groq API
63console.log("🎤 Sending request to Groq Whisper API");
64const start = Date.now();
65const response = await fetch("https://api.groq.com/openai/v1/audio/transcriptions", {
66method: "POST",
67headers: {
68"Authorization": `Bearer ${apiKey}`
69},
70body: groqFormData
71});
72const elapsed = Date.now() - start;
73console.log(`🎤 Groq Whisper API response received in ${elapsed}ms, status: ${response.status}`);
7475// Get response content type
94errorMessage = `Server error: ${response.status} ${response.statusText}`;
95// Log the full response for debugging
96console.error("❌ Transcription API error response:", {
97status: response.status,
98statusText: response.statusText,
103}
104} catch (parseError) {
105console.error("❌ Error parsing Groq API response:", parseError);
106errorMessage = "Failed to parse error response from server";
107}
108109return c.json({
110error: `Groq API error: ${errorMessage}`,
111status: response.status
112}, response.status);
groqAudioChatalpine.ts10 matches
261// Now immediately send this message to get AI response
262try {
263// Prepare messages for the API
264const apiMessages = this.messages.map(({ role, content }) => ({ role, content }));
265
266// Ensure first message is always the correct system message for current mode
267if (apiMessages.length > 0 && apiMessages[0].role === 'system') {
268const systemMessage = this.chatMode === 'concise'
269? 'You are a helpful assistant powered by the Llama-3.3-70b-versatile model. Keep your responses short, concise and conversational. Aim for 1-3 sentences when possible.'
270: 'You are a helpful assistant powered by the Llama-3.3-70b-versatile model. Respond conversationally and accurately to the user.';
271
272apiMessages[0].content = systemMessage;
273}
274
276method: 'POST',
277headers: { 'Content-Type': 'application/json' },
278body: JSON.stringify({ messages: apiMessages })
279});
280
339this.statusMessage = 'Thinking...';
340
341// Prepare messages for the API (excluding UI-only properties)
342const apiMessages = this.messages.map(({ role, content }) => ({ role, content }));
343
344// Ensure first message is always the correct system message for current mode
345if (apiMessages.length > 0 && apiMessages[0].role === 'system') {
346const systemMessage = this.chatMode === 'concise'
347? 'You are a helpful assistant powered by the Llama-3.3-70b-versatile model. Keep your responses short, concise and conversational. Aim for 1-3 sentences when possible.'
348: 'You are a helpful assistant powered by the Llama-3.3-70b-versatile model. Respond conversationally and accurately to the user.';
349
350apiMessages[0].content = systemMessage;
351}
352
355method: 'POST',
356headers: { 'Content-Type': 'application/json' },
357body: JSON.stringify({ messages: apiMessages })
358});
359
2Greatest of all time for your email!
34### Google API Configuration
51. Create a new Google Cloud Project
62. Configure OAuth Conscent Screen
8#### Scopes Needed
9**Read Metadata**
10- https://www.googleapis.com/auth/gmail.metadata
11- This allows you to read email metadata (subjects, headers, labels) but not the email content itself
12- Perfect for creating an email management system without needing to access sensitive message content
1314**Labels**
15- https://www.googleapis.com/auth/gmail.labels
16- This is the scope for seeing and editing email labels
17- Allows you to create, delete, and modify labels
1920### Todo
21- [ ] Google API Configuration
22- [ ] OAuth Implementation with Basic UI to trigger OAuth
23- [ ] Fetch Emails
react-hono-with-react-routerindex.ts2 matches
12app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
1314// Add your API routes here
15// app.get("/api/data", c => c.json({ hello: "world" }));
1617// Unwrap and rethrow Hono errors as the original error
111}, [gameState?.currentPlayerIndex, gameState?.currentCard?.id]);
112113// Fetch players from the API
114const fetchPlayers = async () => {
115try {
116setLoading(true);
117const response = await fetch("/api/players");
118if (!response.ok) {
119throw new Error("Failed to fetch players");
138const deletePlayer = async (id: string) => {
139try {
140const response = await fetch(`/api/players/${id}`, {
141method: "DELETE",
142});
183try {
184// Fetch a card from the selected card set
185const response = await fetch(`/api/card-sets/${cardSet.id}/cards`);
186if (!response.ok) {
187throw new Error("Failed to fetch cards");
111}, [gameState?.currentPlayerIndex, gameState?.currentCard?.id]);
112113// Fetch players from the API
114const fetchPlayers = async () => {
115try {
116setLoading(true);
117const response = await fetch("/api/players");
118if (!response.ok) {
119throw new Error("Failed to fetch players");
138const deletePlayer = async (id: string) => {
139try {
140const response = await fetch(`/api/players/${id}`, {
141method: "DELETE",
142});
183try {
184// Fetch a card from the selected card set
185const response = await fetch(`/api/card-sets/${cardSet.id}/cards`);
186if (!response.ok) {
187throw new Error("Failed to fetch cards");
241initDb();
242243// API routes for games
244app.get("/api/games", async (c) => {
245const result = await sqlite.execute(`SELECT data FROM ${GAMES_TABLE}`);
246const games = result.rows.map(row => JSON.parse(row.data as string)) as Game[];
248});
249250app.get("/api/games/:id", async (c) => {
251const id = c.req.param("id");
252const result = await sqlite.execute(
263});
264265app.post("/api/games", async (c) => {
266const formData = await c.req.json() as GameFormData;
267const game = formDataToGame(formData);
275});
276277app.delete("/api/games/:id", async (c) => {
278const id = c.req.param("id");
279293});
294295// API routes for game players
296app.get("/api/games/:gameId/players", async (c) => {
297const gameId = c.req.param("gameId");
298320});
321322app.post("/api/games/:gameId/players", async (c) => {
323const gameId = c.req.param("gameId");
324const formData = await c.req.json() as PlayerFormData;
341});
342343app.delete("/api/games/:gameId/players/:playerId", async (c) => {
344const gameId = c.req.param("gameId");
345const playerId = c.req.param("playerId");
354});
355356// API routes for all players (not game-specific)
357app.get("/api/players", async (c) => {
358const result = await sqlite.execute(`SELECT data FROM ${PLAYERS_TABLE}`);
359const players = result.rows.map(row => JSON.parse(row.data as string)) as Player[];
361});
362363app.post("/api/players", async (c) => {
364const formData = await c.req.json() as PlayerFormData;
365const player = formDataToPlayer(formData);
373});
374375app.delete("/api/players/:id", async (c) => {
376const id = c.req.param("id");
377391});
392393// API routes for card sets
394app.get("/api/card-sets", (c) => {
395return c.json(CARD_SETS);
396});
397398// API route to get cards from a specific set
399app.get("/api/card-sets/:setId/cards", (c) => {
400const setId = c.req.param("setId");
401const cards = SAMPLE_CARDS[setId] || [];
407});
408409// API route to get a specific card
410app.get("/api/cards/:id", (c) => {
411const cardId = c.req.param("id");
412
timelinePlayerForm.tsx1 match
3738try {
39const response = await fetch("/api/players", {
40method: "POST",
41headers: {
timelineNewGameForm.tsx1 match
2930try {
31const response = await fetch("/api/games", {
32method: "POST",
33headers: {