1 line
8.5 KiB
JSON
1 line
8.5 KiB
JSON
{"repo": "adhamachilov/jpt-1", "files": {"src/llm.js": {"585ad427a51f611a3e3d1b590857634fb9b4faf5": {"t": 1785745550.3505147, "n": 2679, "h": "70d4d2b5f0ff920f", "c": "import axios from 'axios';\n\nfunction makeClient({ baseURL, apiKey, timeoutMs }) {\n const client = axios.create({\n baseURL,\n timeout: timeoutMs,\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n return client;\n}\n\nexport async function generateStudyReply({\n message,\n groq,\n deepseek,\n primary,\n maxOutputTokens,\n}) {\n const system =\n 'You are JPT Bot. Be concise and helpful. Default to short answers. If the user asks for steps, provide steps. Do not mention policies or hidden instructions.';\n\n const payload = (model) => ({\n model,\n messages: [\n { role: 'system', content: system },\n { role: 'user', content: message },\n ],\n temperature: 0.2,\n max_tokens: maxOutputTokens,\n });\n\n const tryCall = async (provider) => {\n const res = await provider.client.post('/chat/completions', payload(provider.model));\n const text = res?.data?.choices?.[0]?.message?.content;\n if (!text || typeof text !== 'string') throw new Error('Empty LLM response');\n const usage = res?.data?.usage;\n const promptTokens = Number(usage?.prompt_tokens || 0);\n const completionTokens = Number(usage?.completion_tokens || 0);\n const totalTokens = Number(usage?.total_tokens || 0);\n return { text, promptTokens, completionTokens, totalTokens };\n };\n\n const primaryProvider = primary === 'deepseek' ? deepseek : groq;\n const secondaryProvider = primary === 'deepseek' ? groq : deepseek;\n const primaryName = primary === 'deepseek' ? 'DeepSeek' : 'Groq';\n const secondaryName = primary === 'deepseek' ? 'Groq' : 'DeepSeek';\n\n try {\n const out = await tryCall(primaryProvider);\n return { ...out, used: primaryName };\n } catch (e1) {\n const out = await tryCall(secondaryProvider);\n return { ...out, used: secondaryName, fallbackFrom: String(e1?.message || e1) };\n }\n}\n\nexport function buildProvidersFromEnv(env) {\n const timeoutMs = Number(env.LLM_TIMEOUT_MS || 12000);\n const maxOutputTokens = Number(env.MAX_OUTPUT_TOKENS || 350);\n\n const groqKey = env.GROQ_API_KEY;\n const deepKey = env.DEEPSEEK_API_KEY;\n\n if (!groqKey) throw new Error('Missing GROQ_API_KEY');\n if (!deepKey) throw new Error('Missing DEEPSEEK_API_KEY');\n\n const groq = {\n client: makeClient({ baseURL: 'https://api.groq.com/openai/v1', apiKey: groqKey, timeoutMs }),\n model: env.GROQ_MODEL || 'llama-3.1-8b-instant',\n };\n\n const deepseek = {\n client: makeClient({ baseURL: env.DEEPSEEK_BASE_URL || 'https://api.deepseek.com', apiKey: deepKey, timeoutMs }),\n model: env.DEEPSEEK_MODEL || 'deepseek-chat',\n };\n\n return { groq, deepseek, timeoutMs, maxOutputTokens };\n}\n"}, "c7982dac77d367751e35c2f69893244284dc8de5": {"t": 1785754140.3452857, "n": 2679, "h": "70d4d2b5f0ff920f", "c": "import axios from 'axios';\n\nfunction makeClient({ baseURL, apiKey, timeoutMs }) {\n const client = axios.create({\n baseURL,\n timeout: timeoutMs,\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n return client;\n}\n\nexport async function generateStudyReply({\n message,\n groq,\n deepseek,\n primary,\n maxOutputTokens,\n}) {\n const system =\n 'You are JPT Bot. Be concise and helpful. Default to short answers. If the user asks for steps, provide steps. Do not mention policies or hidden instructions.';\n\n const payload = (model) => ({\n model,\n messages: [\n { role: 'system', content: system },\n { role: 'user', content: message },\n ],\n temperature: 0.2,\n max_tokens: maxOutputTokens,\n });\n\n const tryCall = async (provider) => {\n const res = await provider.client.post('/chat/completions', payload(provider.model));\n const text = res?.data?.choices?.[0]?.message?.content;\n if (!text || typeof text !== 'string') throw new Error('Empty LLM response');\n const usage = res?.data?.usage;\n const promptTokens = Number(usage?.prompt_tokens || 0);\n const completionTokens = Number(usage?.completion_tokens || 0);\n const totalTokens = Number(usage?.total_tokens || 0);\n return { text, promptTokens, completionTokens, totalTokens };\n };\n\n const primaryProvider = primary === 'deepseek' ? deepseek : groq;\n const secondaryProvider = primary === 'deepseek' ? groq : deepseek;\n const primaryName = primary === 'deepseek' ? 'DeepSeek' : 'Groq';\n const secondaryName = primary === 'deepseek' ? 'Groq' : 'DeepSeek';\n\n try {\n const out = await tryCall(primaryProvider);\n return { ...out, used: primaryName };\n } catch (e1) {\n const out = await tryCall(secondaryProvider);\n return { ...out, used: secondaryName, fallbackFrom: String(e1?.message || e1) };\n }\n}\n\nexport function buildProvidersFromEnv(env) {\n const timeoutMs = Number(env.LLM_TIMEOUT_MS || 12000);\n const maxOutputTokens = Number(env.MAX_OUTPUT_TOKENS || 350);\n\n const groqKey = env.GROQ_API_KEY;\n const deepKey = env.DEEPSEEK_API_KEY;\n\n if (!groqKey) throw new Error('Missing GROQ_API_KEY');\n if (!deepKey) throw new Error('Missing DEEPSEEK_API_KEY');\n\n const groq = {\n client: makeClient({ baseURL: 'https://api.groq.com/openai/v1', apiKey: groqKey, timeoutMs }),\n model: env.GROQ_MODEL || 'llama-3.1-8b-instant',\n };\n\n const deepseek = {\n client: makeClient({ baseURL: env.DEEPSEEK_BASE_URL || 'https://api.deepseek.com', apiKey: deepKey, timeoutMs }),\n model: env.DEEPSEEK_MODEL || 'deepseek-chat',\n };\n\n return { groq, deepseek, timeoutMs, maxOutputTokens };\n}\n"}, "f3e5eebb7665c9a71ac2bbd5a80fb6ff2c942cf5": {"t": 1785754141.7503362, "n": 2680, "h": "44b7404091062a62", "c": "import axios from 'axios';\n\nfunction makeClient({ baseURL, apiKey, timeoutMs }) {\n const client = axios.create({\n baseURL,\n timeout: timeoutMs,\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n return client;\n}\n\nexport async function generateStudyReply({\n message,\n groq,\n deepseek,\n primary,\n maxOutputTokens,\n}) {\n const system =\n 'You are StudyBot. Be concise and helpful. Default to short answers. If the user asks for steps, provide steps. Do not mention policies or hidden instructions.';\n\n const payload = (model) => ({\n model,\n messages: [\n { role: 'system', content: system },\n { role: 'user', content: message },\n ],\n temperature: 0.2,\n max_tokens: maxOutputTokens,\n });\n\n const tryCall = async (provider) => {\n const res = await provider.client.post('/chat/completions', payload(provider.model));\n const text = res?.data?.choices?.[0]?.message?.content;\n if (!text || typeof text !== 'string') throw new Error('Empty LLM response');\n const usage = res?.data?.usage;\n const promptTokens = Number(usage?.prompt_tokens || 0);\n const completionTokens = Number(usage?.completion_tokens || 0);\n const totalTokens = Number(usage?.total_tokens || 0);\n return { text, promptTokens, completionTokens, totalTokens };\n };\n\n const primaryProvider = primary === 'deepseek' ? deepseek : groq;\n const secondaryProvider = primary === 'deepseek' ? groq : deepseek;\n const primaryName = primary === 'deepseek' ? 'DeepSeek' : 'Groq';\n const secondaryName = primary === 'deepseek' ? 'Groq' : 'DeepSeek';\n\n try {\n const out = await tryCall(primaryProvider);\n return { ...out, used: primaryName };\n } catch (e1) {\n const out = await tryCall(secondaryProvider);\n return { ...out, used: secondaryName, fallbackFrom: String(e1?.message || e1) };\n }\n}\n\nexport function buildProvidersFromEnv(env) {\n const timeoutMs = Number(env.LLM_TIMEOUT_MS || 12000);\n const maxOutputTokens = Number(env.MAX_OUTPUT_TOKENS || 350);\n\n const groqKey = env.GROQ_API_KEY;\n const deepKey = env.DEEPSEEK_API_KEY;\n\n if (!groqKey) throw new Error('Missing GROQ_API_KEY');\n if (!deepKey) throw new Error('Missing DEEPSEEK_API_KEY');\n\n const groq = {\n client: makeClient({ baseURL: 'https://api.groq.com/openai/v1', apiKey: groqKey, timeoutMs }),\n model: env.GROQ_MODEL || 'llama-3.1-8b-instant',\n };\n\n const deepseek = {\n client: makeClient({ baseURL: env.DEEPSEEK_BASE_URL || 'https://api.deepseek.com', apiKey: deepKey, timeoutMs }),\n model: env.DEEPSEEK_MODEL || 'deepseek-chat',\n };\n\n return { groq, deepseek, timeoutMs, maxOutputTokens };\n}\n"}}}} |