refactor: optimize core engine and retrieval logic for v2.80.43

This commit is contained in:
2026-05-13 19:23:57 +09:00
parent c4260466b9
commit 089abf22db
17 changed files with 1311 additions and 88 deletions
+9 -9
View File
@@ -61,18 +61,18 @@ export function resolveEngine(baseUrl: string): EngineKind {
return 'ollama';
}
export function buildApiUrl(baseUrl: string, engine: EngineKind, endpoint: 'models' | 'chat'): string {
export function buildApiUrl(baseUrl: string, engine: EngineKind, endpoint: 'models' | 'chat' | 'embeddings'): string {
const normalized = normalizeBaseUrl(baseUrl);
if (engine === 'lmstudio') {
if (normalized.endsWith('/v1')) {
return endpoint === 'models' ? `${normalized}/models` : `${normalized}/chat/completions`;
}
return endpoint === 'models' ? `${normalized}/v1/models` : `${normalized}/v1/chat/completions`;
const root = normalized.endsWith('/v1') ? normalized : `${normalized}/v1`;
if (endpoint === 'models') return `${root}/models`;
if (endpoint === 'embeddings') return `${root}/embeddings`;
return `${root}/chat/completions`;
}
if (normalized.endsWith('/api')) {
return endpoint === 'models' ? `${normalized}/tags` : `${normalized}/chat`;
}
return endpoint === 'models' ? `${normalized}/api/tags` : `${normalized}/api/chat`;
const apiRoot = normalized.endsWith('/api') ? normalized : `${normalized}/api`;
if (endpoint === 'models') return `${apiRoot}/tags`;
if (endpoint === 'embeddings') return `${apiRoot}/embed`;
return `${apiRoot}/chat`;
}
export function summarizeText(text: string, maxLength: number = 400): string {