Update: [chat-completions.js] Update sendMakerSuiteRequest function Removed branching logic for differences in JSON request body between PaLM and Gemini, following the removal of PaLM from Google AI Studio.

43feffdfae4ecbf54e12d569cd88a35a9dea9170

M0cho <77959408+M0ch0@users.noreply.github.com>

1 files changed, +4 -40Showing whitespace changes
src/endpoints/backends/chat-completions.js+4 -40
@@ -262,9 +262,7 @@ async function sendMakerSuiteRequest(request, response) {
262262 }
263263
264264 const model = String(request.body.model);
265265 const isGeministream = model.includesBoolean('gemini'request.body.stream);
266- const isText = model.includes('text');
267- const stream = Boolean(request.body.stream) && isGemini;
268266
269267 const generationConfig = {
270268 stopSequences: request.body.stop,
@@ -301,39 +299,7 @@ async function sendMakerSuiteRequest(request, response) {
301299 return body;
302300 }
303301
304- function getBisonBody() {
302+ const body = getGeminiBody();
305- const prompt = isText
306- ? ({ text: convertTextCompletionPrompt(request.body.messages) })
307- : ({ messages: convertGooglePrompt(request.body.messages, model).contents });
308-
309- /** @type {any} Shut the lint up */
310- const bisonBody = {
311- ...generationConfig,
312- safetySettings: BISON_SAFETY,
313- candidate_count: 1, // lewgacy spelling
314- prompt: prompt,
315- };
316-
317- if (!isText) {
318- delete bisonBody.stopSequences;
319- delete bisonBody.maxOutputTokens;
320- delete bisonBody.safetySettings;
321-
322- if (Array.isArray(prompt.messages)) {
323- for (const msg of prompt.messages) {
324- msg.author = msg.role;
325- msg.content = msg.parts[0].text;
326- delete msg.parts;
327- delete msg.role;
328- }
329- }
330- }
331-
332- delete bisonBody.candidateCount;
333- return bisonBody;
334- }
335-
336- const body = isGemini ? getGeminiBody() : getBisonBody();
337303 console.log('Google AI Studio request:', body);
338304
339305 try {
@@ -343,10 +309,8 @@ async function sendMakerSuiteRequest(request, response) {
343309 controller.abort();
344310 });
345311
346312 const apiVersion = isGemini ? 'v1beta' : 'v1beta2';
347- const responseType = isGemini
313+ const responseType = (stream ? 'streamGenerateContent' : 'generateContent');
348- ? (stream ? 'streamGenerateContent' : 'generateContent')
349- : (isText ? 'generateText' : 'generateMessage');
350314
351315 const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, {
352316 body: JSON.stringify(body),