text-transformer / src /config /tinyllama.js
OnyxMunk's picture
fix: replace TinyLlama with Qwen2.5-1.5B-Instruct (provider support)
0f21e51 verified
export const OLLAMA_BASE = 'http://localhost:11434';
export const HF_MODEL = 'Qwen/Qwen2.5-1.5B-Instruct';
export const HF_PROXY_PATH = '/api/hf-inference';
export const SYSTEM_PROMPT =
"You are a specialized assistant for the Text Transformer app. You speak in a helpful, slightly cyberpunk tone. You assist with text conversion and encoding tasks.";
function getEnv() {
const build = typeof import.meta !== 'undefined' && import.meta.env ? import.meta.env : {};
const runtime = typeof window !== 'undefined' && window.__HF_ENV && typeof window.__HF_ENV === 'object' ? window.__HF_ENV : {};
return { ...build, ...runtime };
}
function getProviderFromEnv() {
const env = getEnv();
const raw = env.VITE_TINYLLAMA_PROVIDER?.trim()?.toLowerCase();
if (raw === 'hf' || raw === 'huggingface' || raw === 'gpu') return 'hf';
if (raw === 'ollama' || raw === 'local' || raw === 'cpu') return 'ollama';
return 'auto';
}
function getHostBasedProvider() {
if (typeof window === 'undefined') return 'ollama';
const host = window.location.hostname;
if (host === 'localhost' || host === '127.0.0.1') return null;
if (host.includes('huggingface.co') || host.includes('hf.space')) return 'hf';
return 'ollama';
}
export function getTinyLlamaConfig(runtimeOverride = null) {
const env = getEnv();
const envProvider = getProviderFromEnv();
const hostProvider = getHostBasedProvider();
const effectiveProvider = runtimeOverride ?? (envProvider === 'auto' ? (hostProvider ?? 'hf') : envProvider);
if (effectiveProvider === 'hf') {
return {
provider: 'hf',
baseUrl: HF_PROXY_PATH,
model: HF_MODEL,
};
}
const customUrl = env.VITE_TINYLLAMA_API_URL?.trim();
const baseUrl = customUrl ? customUrl.replace(/\/$/, '') : OLLAMA_BASE;
if (env.VITE_TINYLLAMA_VERCEL_URL?.trim() && typeof window !== 'undefined' && window.location?.hostname?.includes('vercel.app')) {
return { provider: 'ollama', baseUrl: env.VITE_TINYLLAMA_VERCEL_URL.trim().replace(/\/$/, ''), model: 'tinyllama' };
}
return { provider: 'ollama', baseUrl, model: 'tinyllama' };
}
export function getDefaultProviderForUI() {
const envProvider = getProviderFromEnv();
const hostProvider = getHostBasedProvider();
if (envProvider !== 'auto') return envProvider;
return hostProvider ?? 'hf';
}