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.
| @@ -262,9 +262,7 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | const model = String(request.body.model); |
| 265 | 265 | const isGeministream = model.includesBoolean('gemini'request.body.stream); |
| 266 | - const isText = model.includes('text'); | |
| 267 | - const stream = Boolean(request.body.stream) && isGemini; | |
| 268 | 266 | |
| 269 | 267 | const generationConfig = { |
| 270 | 268 | stopSequences: request.body.stop, |
| @@ -301,39 +299,7 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 301 | 299 | return body; |
| 302 | 300 | } |
| 303 | 301 | |
| 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(); | |
| 337 | 303 | console.log('Google AI Studio request:', body); |
| 338 | 304 | |
| 339 | 305 | try { |
| @@ -343,10 +309,8 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 343 | 309 | controller.abort(); |
| 344 | 310 | }); |
| 345 | 311 | |
| 346 | 312 | const apiVersion = isGemini ? 'v1beta' : 'v1beta2'; |
| 347 | - const responseType = isGemini | |
| 313 | + const responseType = (stream ? 'streamGenerateContent' : 'generateContent'); | |
| 348 | - ? (stream ? 'streamGenerateContent' : 'generateContent') | |
| 349 | - : (isText ? 'generateText' : 'generateMessage'); | |
| 350 | 314 | |
| 351 | 315 | const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, { |
| 352 | 316 | body: JSON.stringify(body), |