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.
This commit is contained in:
M0cho
2024-12-15 13:06:48 +09:00
parent 9ea8fc92e4
commit 43feffdfae

View File

@ -262,9 +262,7 @@ async function sendMakerSuiteRequest(request, response) {
}
const model = String(request.body.model);
const isGemini = model.includes('gemini');
const isText = model.includes('text');
const stream = Boolean(request.body.stream) && isGemini;
const stream = Boolean(request.body.stream);
const generationConfig = {
stopSequences: request.body.stop,
@ -301,39 +299,7 @@ async function sendMakerSuiteRequest(request, response) {
return body;
}
function getBisonBody() {
const prompt = isText
? ({ text: convertTextCompletionPrompt(request.body.messages) })
: ({ messages: convertGooglePrompt(request.body.messages, model).contents });
/** @type {any} Shut the lint up */
const bisonBody = {
...generationConfig,
safetySettings: BISON_SAFETY,
candidate_count: 1, // lewgacy spelling
prompt: prompt,
};
if (!isText) {
delete bisonBody.stopSequences;
delete bisonBody.maxOutputTokens;
delete bisonBody.safetySettings;
if (Array.isArray(prompt.messages)) {
for (const msg of prompt.messages) {
msg.author = msg.role;
msg.content = msg.parts[0].text;
delete msg.parts;
delete msg.role;
}
}
}
delete bisonBody.candidateCount;
return bisonBody;
}
const body = isGemini ? getGeminiBody() : getBisonBody();
const body = getGeminiBody();
console.log('Google AI Studio request:', body);
try {
@ -343,10 +309,8 @@ async function sendMakerSuiteRequest(request, response) {
controller.abort();
});
const apiVersion = isGemini ? 'v1beta' : 'v1beta2';
const responseType = isGemini
? (stream ? 'streamGenerateContent' : 'generateContent')
: (isText ? 'generateText' : 'generateMessage');
const apiVersion = 'v1beta';
const responseType = (stream ? 'streamGenerateContent' : 'generateContent');
const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, {
body: JSON.stringify(body),