1 line
8.0 KiB
JSON
1 line
8.0 KiB
JSON
{"repo": "abhijeet0703/cvinsight", "files": {"lib/llm.js": {"e26ab3b9a3cd6808e3d3fdf3509e575c4a4703e3": {"t": 1785746704.8667243, "n": 3806, "h": "c0ec96ba694a0453", "c": "import { GoogleGenerativeAI } from '@google/generative-ai';\n\n// Single switch for the chat LLM. Keep this in sync with the env file.\n// Supported: \"gemini\" | \"deepseek\" | \"grok\" | \"ollama\".\nconst PROVIDER = (process.env.LLM_PROVIDER || 'gemini').toLowerCase();\n\nconst CONFIG = {\n gemini: {\n apiKey: process.env.GEMINI_API_KEY,\n model: process.env.GEMINI_MODEL || 'gemini-2.5-flash',\n },\n deepseek: {\n apiKey: process.env.DEEPSEEK_API_KEY,\n baseURL: process.env.DEEPSEEK_BASE_URL || 'https://api.deepseek.com/v1',\n model: process.env.DEEPSEEK_MODEL || 'deepseek-chat',\n },\n grok: {\n apiKey: process.env.GROK_API_KEY,\n baseURL: process.env.GROK_BASE_URL || 'https://api.x.ai/v1',\n model: process.env.GROK_MODEL || 'grok-2-latest',\n },\n ollama: {\n baseURL: process.env.OLLAMA_URL || 'http://127.0.0.1:11434',\n model: process.env.OLLAMA_CHAT_MODEL || 'llama3.1',\n },\n};\n\nlet geminiClient = null;\nfunction getGemini() {\n if (!geminiClient) {\n if (!CONFIG.gemini.apiKey) throw new Error('GEMINI_API_KEY not set');\n geminiClient = new GoogleGenerativeAI(CONFIG.gemini.apiKey);\n }\n return geminiClient;\n}\n\nasync function callGemini(prompt, { temperature, model }) {\n const g = getGemini().getGenerativeModel({\n model: model || CONFIG.gemini.model,\n generationConfig: { responseMimeType: 'application/json', temperature },\n });\n const res = await g.generateContent(prompt);\n return res.response.text();\n}\n\nasync function callOpenAICompat(cfg, prompt, { temperature, model }) {\n if (!cfg.apiKey) throw new Error(`API key missing for provider \"${PROVIDER}\"`);\n const res = await fetch(`${cfg.baseURL}/chat/completions`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${cfg.apiKey}`,\n },\n body: JSON.stringify({\n model: model || cfg.model,\n messages: [{ role: 'user', content: prompt }],\n temperature,\n response_format: { type: 'json_object' },\n }),\n });\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n const err = new Error(`${PROVIDER} call failed (${res.status}): ${body.slice(0, 300)}`);\n err.status = res.status;\n throw err;\n }\n const json = await res.json();\n return json.choices?.[0]?.message?.content || '';\n}\n\nasync function callOllama(prompt, { temperature, model }) {\n const res = await fetch(`${CONFIG.ollama.baseURL}/api/chat`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n model: model || CONFIG.ollama.model,\n messages: [{ role: 'user', content: prompt }],\n stream: false,\n format: 'json',\n options: { temperature },\n }),\n });\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n throw new Error(`Ollama chat failed (${res.status}): ${body.slice(0, 300)}`);\n }\n const json = await res.json();\n return json.message?.content || '';\n}\n\n// Returns parsed JSON. All callers prompt the model for strict JSON.\nexport async function generateJSON(prompt, { temperature = 0.1, model } = {}) {\n let raw;\n switch (PROVIDER) {\n case 'gemini':\n raw = await callGemini(prompt, { temperature, model });\n break;\n case 'deepseek':\n raw = await callOpenAICompat(CONFIG.deepseek, prompt, { temperature, model });\n break;\n case 'grok':\n raw = await callOpenAICompat(CONFIG.grok, prompt, { temperature, model });\n break;\n case 'ollama':\n raw = await callOllama(prompt, { temperature, model });\n break;\n default:\n throw new Error(`Unknown LLM_PROVIDER: ${PROVIDER}`);\n }\n const cleaned = String(raw).replace(/```json|```/g, '').trim();\n return JSON.parse(cleaned);\n}\n\nexport function getLLMProvider() {\n return { provider: PROVIDER, model: CONFIG[PROVIDER]?.model };\n}"}, "9c87e2dee1b02b7fdf2381f71965262bf563bd72": {"t": 1785767101.254015, "n": 3806, "h": "c0ec96ba694a0453", "c": "import { GoogleGenerativeAI } from '@google/generative-ai';\n\n// Single switch for the chat LLM. Keep this in sync with the env file.\n// Supported: \"gemini\" | \"deepseek\" | \"grok\" | \"ollama\".\nconst PROVIDER = (process.env.LLM_PROVIDER || 'gemini').toLowerCase();\n\nconst CONFIG = {\n gemini: {\n apiKey: process.env.GEMINI_API_KEY,\n model: process.env.GEMINI_MODEL || 'gemini-2.5-flash',\n },\n deepseek: {\n apiKey: process.env.DEEPSEEK_API_KEY,\n baseURL: process.env.DEEPSEEK_BASE_URL || 'https://api.deepseek.com/v1',\n model: process.env.DEEPSEEK_MODEL || 'deepseek-chat',\n },\n grok: {\n apiKey: process.env.GROK_API_KEY,\n baseURL: process.env.GROK_BASE_URL || 'https://api.x.ai/v1',\n model: process.env.GROK_MODEL || 'grok-2-latest',\n },\n ollama: {\n baseURL: process.env.OLLAMA_URL || 'http://127.0.0.1:11434',\n model: process.env.OLLAMA_CHAT_MODEL || 'llama3.1',\n },\n};\n\nlet geminiClient = null;\nfunction getGemini() {\n if (!geminiClient) {\n if (!CONFIG.gemini.apiKey) throw new Error('GEMINI_API_KEY not set');\n geminiClient = new GoogleGenerativeAI(CONFIG.gemini.apiKey);\n }\n return geminiClient;\n}\n\nasync function callGemini(prompt, { temperature, model }) {\n const g = getGemini().getGenerativeModel({\n model: model || CONFIG.gemini.model,\n generationConfig: { responseMimeType: 'application/json', temperature },\n });\n const res = await g.generateContent(prompt);\n return res.response.text();\n}\n\nasync function callOpenAICompat(cfg, prompt, { temperature, model }) {\n if (!cfg.apiKey) throw new Error(`API key missing for provider \"${PROVIDER}\"`);\n const res = await fetch(`${cfg.baseURL}/chat/completions`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${cfg.apiKey}`,\n },\n body: JSON.stringify({\n model: model || cfg.model,\n messages: [{ role: 'user', content: prompt }],\n temperature,\n response_format: { type: 'json_object' },\n }),\n });\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n const err = new Error(`${PROVIDER} call failed (${res.status}): ${body.slice(0, 300)}`);\n err.status = res.status;\n throw err;\n }\n const json = await res.json();\n return json.choices?.[0]?.message?.content || '';\n}\n\nasync function callOllama(prompt, { temperature, model }) {\n const res = await fetch(`${CONFIG.ollama.baseURL}/api/chat`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n model: model || CONFIG.ollama.model,\n messages: [{ role: 'user', content: prompt }],\n stream: false,\n format: 'json',\n options: { temperature },\n }),\n });\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n throw new Error(`Ollama chat failed (${res.status}): ${body.slice(0, 300)}`);\n }\n const json = await res.json();\n return json.message?.content || '';\n}\n\n// Returns parsed JSON. All callers prompt the model for strict JSON.\nexport async function generateJSON(prompt, { temperature = 0.1, model } = {}) {\n let raw;\n switch (PROVIDER) {\n case 'gemini':\n raw = await callGemini(prompt, { temperature, model });\n break;\n case 'deepseek':\n raw = await callOpenAICompat(CONFIG.deepseek, prompt, { temperature, model });\n break;\n case 'grok':\n raw = await callOpenAICompat(CONFIG.grok, prompt, { temperature, model });\n break;\n case 'ollama':\n raw = await callOllama(prompt, { temperature, model });\n break;\n default:\n throw new Error(`Unknown LLM_PROVIDER: ${PROVIDER}`);\n }\n const cleaned = String(raw).replace(/```json|```/g, '').trim();\n return JSON.parse(cleaned);\n}\n\nexport function getLLMProvider() {\n return { provider: PROVIDER, model: CONFIG[PROVIDER]?.model };\n}"}}}} |