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