mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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:
@ -262,9 +262,7 @@ async function sendMakerSuiteRequest(request, response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const model = String(request.body.model);
|
const model = String(request.body.model);
|
||||||
const isGemini = model.includes('gemini');
|
const stream = Boolean(request.body.stream);
|
||||||
const isText = model.includes('text');
|
|
||||||
const stream = Boolean(request.body.stream) && isGemini;
|
|
||||||
|
|
||||||
const generationConfig = {
|
const generationConfig = {
|
||||||
stopSequences: request.body.stop,
|
stopSequences: request.body.stop,
|
||||||
@ -301,39 +299,7 @@ async function sendMakerSuiteRequest(request, response) {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBisonBody() {
|
const body = getGeminiBody();
|
||||||
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();
|
|
||||||
console.log('Google AI Studio request:', body);
|
console.log('Google AI Studio request:', body);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -343,10 +309,8 @@ async function sendMakerSuiteRequest(request, response) {
|
|||||||
controller.abort();
|
controller.abort();
|
||||||
});
|
});
|
||||||
|
|
||||||
const apiVersion = isGemini ? 'v1beta' : 'v1beta2';
|
const apiVersion = 'v1beta';
|
||||||
const responseType = isGemini
|
const responseType = (stream ? 'streamGenerateContent' : 'generateContent');
|
||||||
? (stream ? 'streamGenerateContent' : 'generateContent')
|
|
||||||
: (isText ? 'generateText' : 'generateMessage');
|
|
||||||
|
|
||||||
const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, {
|
const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, {
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
Reference in New Issue
Block a user