Skip to content

Commit cb6a118

Browse files
authored
[bugfix] no more proxy in "/v1/model" and "/v1/shields" path (#2324)
* fixed a bug where /v1/models was being proxied (adding userId) at the end. Signed-off-by: Lucas <lyoon@redhat.com> * skipping /models and /shields completely for history length and user id Signed-off-by: Lucas <lyoon@redhat.com> --------- Signed-off-by: Lucas <lyoon@redhat.com>
1 parent 2ec15ca commit cb6a118

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

  • workspaces/lightspeed/plugins/lightspeed-backend/src/service

workspaces/lightspeed/plugins/lightspeed-backend/src/service/router.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
} from './types';
3838
import { validateCompletionsRequest } from './validation';
3939

40+
const SKIP_USER_ID_ENDPOINTS = new Set(['/v1/models', '/v1/shields']);
41+
4042
/**
4143
* @public
4244
* The lightspeed backend router
@@ -105,19 +107,33 @@ export async function createRouter(
105107
target: `http://0.0.0.0:${port}`,
106108
changeOrigin: true,
107109
pathRewrite: (path, _) => {
108-
// Add user query parameter from the authenticated user
110+
const isSkippable = Array.from(SKIP_USER_ID_ENDPOINTS).some(endpoint =>
111+
path.startsWith(endpoint),
112+
);
113+
114+
if (isSkippable) {
115+
return path;
116+
}
117+
118+
let newPath = path;
119+
120+
// Add user_id
109121
const userQueryParam = `user_id=${encodeURIComponent(userEntity)}`;
110-
// Check if there are already query parameters
111-
let newPath = path.includes('?')
122+
newPath = path.includes('?')
112123
? `${path}&${userQueryParam}`
113124
: `${path}?${userQueryParam}`;
125+
126+
// Add history_length if needed
114127
if (
115128
!path.includes('history_length') &&
116129
path.includes('conversation_id')
117130
) {
118131
const historyLengthQuery = `history_length=${DEFAULT_HISTORY_LENGTH}`;
119-
newPath = `${newPath}&${historyLengthQuery}`;
132+
newPath = newPath.includes('?')
133+
? `${newPath}&${historyLengthQuery}`
134+
: `${newPath}?${historyLengthQuery}`;
120135
}
136+
121137
logger.info(`Rewriting path from ${path} to ${newPath}`);
122138
return newPath;
123139
},

0 commit comments

Comments
 (0)