mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add util for trim v1
This commit is contained in:
@ -5,7 +5,7 @@ const Readable = require('stream').Readable;
|
|||||||
|
|
||||||
const { jsonParser } = require('../../express-common');
|
const { jsonParser } = require('../../express-common');
|
||||||
const { TEXTGEN_TYPES, TOGETHERAI_KEYS, OLLAMA_KEYS } = require('../../constants');
|
const { TEXTGEN_TYPES, TOGETHERAI_KEYS, OLLAMA_KEYS } = require('../../constants');
|
||||||
const { forwardFetchResponse } = require('../../util');
|
const { forwardFetchResponse, trimV1 } = require('../../util');
|
||||||
const { setAdditionalHeaders } = require('../../additional-headers');
|
const { setAdditionalHeaders } = require('../../additional-headers');
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -67,9 +67,7 @@ router.post('/status', jsonParser, async function (request, response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Trying to connect to API:', request.body);
|
console.log('Trying to connect to API:', request.body);
|
||||||
|
const baseUrl = trimV1(request.body.api_server);
|
||||||
// Convert to string + remove trailing slash + /v1 suffix
|
|
||||||
const baseUrl = String(request.body.api_server).replace(/\/$/, '').replace(/\/v1$/, '');
|
|
||||||
|
|
||||||
const args = {
|
const args = {
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@ -199,8 +197,7 @@ router.post('/generate', jsonParser, async function (request, response) {
|
|||||||
controller.abort();
|
controller.abort();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Convert to string + remove trailing slash + /v1 suffix
|
let url = trimV1(baseUrl);
|
||||||
let url = String(baseUrl).replace(/\/$/, '').replace(/\/v1$/, '');
|
|
||||||
|
|
||||||
if (request.body.legacy_api) {
|
if (request.body.legacy_api) {
|
||||||
url += '/v1/generate';
|
url += '/v1/generate';
|
||||||
@ -337,8 +334,7 @@ ollama.post('/caption-image', jsonParser, async function (request, response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Ollama caption request:', request.body);
|
console.log('Ollama caption request:', request.body);
|
||||||
// Convert to string + remove trailing slash + /v1 suffix
|
const baseUrl = trimV1(request.body.server_url);
|
||||||
const baseUrl = String(request.body.server_url).replace(/\/$/, '').replace(/\/v1$/, '');
|
|
||||||
|
|
||||||
const fetchResponse = await fetch(`${baseUrl}/api/generate`, {
|
const fetchResponse = await fetch(`${baseUrl}/api/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -383,8 +379,7 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('LlamaCpp caption request:', request.body);
|
console.log('LlamaCpp caption request:', request.body);
|
||||||
// Convert to string + remove trailing slash + /v1 suffix
|
const baseUrl = trimV1(request.body.server_url);
|
||||||
const baseUrl = String(request.body.server_url).replace(/\/$/, '').replace(/\/v1$/, '');
|
|
||||||
|
|
||||||
const fetchResponse = await fetch(`${baseUrl}/completion`, {
|
const fetchResponse = await fetch(`${baseUrl}/completion`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
10
src/util.js
10
src/util.js
@ -458,6 +458,15 @@ function excludeKeysByYaml(obj, yamlString) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes trailing slash and /v1 from a string.
|
||||||
|
* @param {string} str Input string
|
||||||
|
* @returns {string} Trimmed string
|
||||||
|
*/
|
||||||
|
function trimV1(str) {
|
||||||
|
return String(str ?? '').replace(/\/$/, '').replace(/\/v1$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getConfig,
|
getConfig,
|
||||||
getConfigValue,
|
getConfigValue,
|
||||||
@ -481,4 +490,5 @@ module.exports = {
|
|||||||
getHexString,
|
getHexString,
|
||||||
mergeObjectWithYaml,
|
mergeObjectWithYaml,
|
||||||
excludeKeysByYaml,
|
excludeKeysByYaml,
|
||||||
|
trimV1,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user