build llama.cpp embedding url path by appending instead of overwriting (#5178) * build llama.cpp embedding url path by appending instead of overwriting When using a llama-swap frontend, this allows choosing the embedding model by path; for instance, with the secondary embedding endpoint URL configured to http://127.0.0.1:5001/upstream/emb-model to pick the "emb-model" model. With this approach, the same llama-swap instance can be used to serve both the main LLM and the embedding model from local llama-server commands. * Trim trailing v1 from URL --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

ab8d7e518454ad9cc030d8f22c09614246f4695a

Wagner Bruna <wbruna@users.noreply.github.com>

Signed
1 files changed, +3 -2Ignore whitespace
src/vectors/llamacpp-vectors.js+3 -2
@@ -1,6 +1,8 @@
1import fetch from 'node-fetch';1import fetch from 'node-fetch';
2import urlJoin from 'url-join';
2import { setAdditionalHeadersByType } from '../additional-headers.js';3import { setAdditionalHeadersByType } from '../additional-headers.js';
3import { TEXTGEN_TYPES } from '../constants.js';4import { TEXTGEN_TYPES } from '../constants.js';
5import { trimV1 } from '../util.js';
46
5/**7/**
6 * Gets the vector for the given text from LlamaCpp8 * Gets the vector for the given text from LlamaCpp
@@ -10,8 +12,7 @@ import { TEXTGEN_TYPES } from '../constants.js';
10 * @returns {Promise<number[][]>} - The array of vectors for the texts12 * @returns {Promise<number[][]>} - The array of vectors for the texts
11 */13 */
12export async function getLlamaCppBatchVector(texts, apiUrl, directories) {14export async function getLlamaCppBatchVector(texts, apiUrl, directories) {
13 const url = new URL(apiUrl);15 const url = new URL(urlJoin(trimV1(apiUrl), '/v1/embeddings'));
14 url.pathname = '/v1/embeddings';
1516
16 const headers = {};17 const headers = {};
17 setAdditionalHeadersByType(headers, TEXTGEN_TYPES.LLAMACPP, apiUrl, directories);18 setAdditionalHeadersByType(headers, TEXTGEN_TYPES.LLAMACPP, apiUrl, directories);